November 7, 2012

This post talks about new monetization feature in Windows Phone 8 – In-App-Purchases (IAP). According to multiple industry sources (link1, link2, link3) IAP can actually make more money that free/ad-supported application. Let’s see how to add this feature to application. In this post I will show how to build simplest “virtual” shop app. All IAP functionality process allocated in Windows.ApplicationModel.Store namespace.

First let’s understand the terminology associated with IAP process.

Product – something you are selling in application. Unlike Windows 8, in Windows Phone 8 we got two different product types: Durable and Consumable.

Durable – a Product that is purchased once and owned by the user/application.

Consumable – a Product that is purchased and used multiple times. This Product could be purchased again and again when user needs it.

Products are organized into Product List which managed through application’s settings on Dev Center Dashboard.

Purchase – the process of buying a Product.

License – a set of definitions describing the product type, whether it is active and its expiration date. Associated with each Product.

Receipt – a proof of purchase which used to verify that user Purchased the Product.

Fulfillment – the process of giving the user the Product he/she Purchased. Depends on application logic, but must me reported to marketplace. Available only for Consumables and plays key role in Product Purchase process – new Consumable cannot be Purchased again without reporting previous successful fulfillment.

Working with Catalog

Current application licensing info and associated product list is obtained using CurrentApp class. This app provides key functionality of searching catalog (by keyword or productId), purchasing the products and report fulfillments. The following code snippet searches all products by keywords:

In addition to search functionality, CurrentApp class also provides access to full product list which is accessible through CurrentApp.LicenseInformation.ProductLicenses class. Each item in ProductLicenses is an object from ProductLicense class. This class enables querying product state by providing ExpirationDate, IsActive and IsConsumable properties. The following code snippet loads not purchased durables from product catalog:

Working IAP is a server-based commerce. It relies on communication with Microsoft’s backend services to list products, enumerate licenses and process purchases. It may also rely on your servers to deliver purchased in-app products if needed. When purchasing the product (published application) marketplace will perform real transaction with client’s account. In development cycle it is not always possible to deploy application to marketplace (especially as public application). It is possible to deploy application as Beta on marketplace. Beta applications support full IAP mechanism through marketplace with only one difference – although the user experience shows prices as entered into Dev Center, all in-app purchases made from beta apps are free. This approach is strongly recommended once you application is in somewhat ready state. But what to do during initial development stages? Windows 8 provides CurrentAppSimulator class for this work. Unfortunately this functionality didn’t made it into Windows Phone 8. To overcome this, we want to use mock library which closely mimics Store APIs.

To work with this library it must be referenced on all pages which are using Store functionality as follows:

#if DEBUG

using MockIAPLib;

using Store = MockIAPLib;

#else

using Store = Windows.ApplicationModel.Store;

#endif

From now on, to test real marketplace functionality all you need is to compile your app as Release. While the library closely mimics store APIs it must be initiated with as it doesn’t uses server-based information from marketplace. It should be initiated from XML-based product catalog as follows:

Note: in real scenarios it is recommended to get product images from app’s server-side storage as the approach shown in this sample relays on having all possible product images in application package which is not recommended and prevents from extending product list after publishing the app.

2 comments

Steve,Great article. I reeembmr in a business class that I took a long time ago, the lesson that really stood out is spend less time worrying about what font to use on your business card and more time worrying about what makes your product or service better than the others, and how you’re going to get that message out to the public. Or as you say, there’s a lot you can worry about after you hit critical mass and are making money. Scott