23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

As with the app purchase, any changes in product license status will trigger the licensechanged<br />

event; your handler for that event makes a great place to update your app status and initiate any<br />

downloads related to the purchase. The same event will be fired if a time-limited product license<br />

expires, which is your signal to make the purchase available again. It’s likely that you might also want to<br />

alert the user to that status, perhaps with a toast notification or with inline messages when the user tries<br />

to access that feature.<br />

Receipts<br />

Both the requestAppPurchaseAsync and requestProductPurchaseAsync methods of CurrentApp have an<br />

option, as we saw earlier, to provide a receipt string to the completed handler of the async operation. Its<br />

getAppReceiptAsync method also provides an all-up receipt (app and products) at any time. Generally<br />

speaking, receipts are most useful when a service needs to validate that an app is authorized to use<br />

certain functionality. The app acquires the receipt and sends it to the service, which can then do<br />

whatever validation it requires.<br />

In all cases, the receipt is an XML string that contains information such as the app or product id, the<br />

dates when the purchase was made and when the receipt was issued, and a digital signature. The details<br />

of the XML schema can be found on the reference page linked above.<br />

As an example, here’s the receipt string provided from requestProductPurchaseAsync when<br />

purchasing Product 2 in Scenario 2 of the sample:<br />

<br />

Here’s what Scenario 5 of the same sample receives from getAppReceiptAsync:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!