23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

You might have noticed that a ProductListing (from the app’s productListings collection) only<br />

contains a name and not a description. This really means that the name is the description and you should<br />

use it as such, rather than using it as another type of identifier, for which you already have productId. In<br />

other words, a product that provides 20 extra levels for a game should be named something like<br />

“Twenty extra levels with new challenges” rather than “extra_levels” because that name will appear in UI.<br />

As you dangle all your product options in front of the user, the user will (I’m being very affirmative<br />

here!) at some point want to purchase one or more of them. When the user taps the appropriate<br />

button, like the Buy Product buttons in the sample (see Figure 17-5 again), the app just needs to call<br />

requestProductPurchaseAsync with the product ID and a Boolean indicating whether the method<br />

should provide a receipt:<br />

currentApp.requestProductPurchaseAsync("product1", false).done(<br />

function () {<br />

if (licenseInformation.productLicenses.lookup("product1").isActive) {<br />

// Purchase was fulfilled; UI is not shown if the user already owns the product.<br />

} else {<br />

// Purchase UI was shown, but the user canceled.<br />

}<br />

},<br />

function () {<br />

// There was an error in the transaction; purchase did not occur<br />

});<br />

If the product already has an active license, requestProductPurchaseAsync will simply call your<br />

completed handler without showing any UI, as none is needed. Otherwise the user will see a series of<br />

prompts to confirm the purchase, including confirmation of their credentials. For the whole flow, see<br />

The in-app purchase user experience for a customer. A typical confirmation message is shown below:<br />

Note that the warning here, which exists to meet regulations in some countries, is not entirely true:<br />

you can also cancel entering your credentials in the next dialog.<br />

When using the CurrentAppSimulator, of course, you won’t see the Store prompts but only another<br />

simple dialog to control the result:<br />

779

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

Saved successfully!

Ooh no, something went wrong!