Index
Unity3D Asset
Quick Implementation
Step1
Step2
Step3
Implementation
Initialize
Purchasable Items
License Information
Purchase Product
Test the Windows Phone 8 InApp Purchases
Unity3D Asset
Download the Asset from the Unity Asset Store Windows Phone8 In App
Requirement Unity 3D 4.2 Basic or Pro
Quick Implementation
3 small steps for your first Windows Phone 8 inApp Purchase
Step 1
using WindowsPhone8_Store; //
Step 2
Use this for initialization and set the event
private WindowsPhone8_Store.InApp WP8inApp; void Start() { WP8inApp = new InApp(); WP8inApp.InitWindowsPhone8InApp(); WindowsPhone8_Store.InApp.onWP8inAppPurchased += onWP8inAppPurchased; WindowsPhone8_Store.InApp.onWP8inAppTransactionsRestored += onWP8inAppTransactionsRestored; WindowsPhone8_Store.InApp.onWP8inAppCancelled += onWP8inAppCancelled; WindowsPhone8_Store.InApp.onWP8inAppFailed += onWP8inAppFailed; }
Step3
void PurchaseProduct() { // Buy the product WP8inApp.PurchaseProduct("coin100"); } // // Events from WP8InAppPlugin // private void onWP8inAppTransactionsRestored(bool success) { Debug.Log("Transactions restored:" + success); } private void onWP8inAppPurchased(PurchasableProduct item) { Debug.Log("Purchased Done" + item.ProductId); if (item.ItemProductType == PurchasableProduct.ProductType.Consumable) { // A user can’t purchase the same product again until you have confirmed its. // This applies only to consumable products. // MyCoins += 100; WP8inApp.ReportProductFulfillment(item.ProductId); } } private void onWP8inAppCancelled(PurchasableProduct item) { Debug.Log("Purchase cancelled: " + item.ProductId); } private void onWP8inAppFailed(PurchasableProduct item) { Debug.Log("Purchase failed: " + item.ProductId); }
Implementation
Include the namespace for using the dll (WindowsPhone8_Store.dll)
using WindowsPhone8_Store;
Define global variable
private WindowsPhone8_Store.InApp WP8inApp;
You should initialize WP8InApp in the Start routine and Setup the Events
Initialize
void Start() { // Init the Windows Phone 8 InApp WP8inApp = new InApp(); WP8inApp.InitWindowsPhone8InApp(); // Setup the Events WindowsPhone8_Store.InApp.onWP8inAppPurchased += onWP8inAppPurchased; WindowsPhone8_Store.InApp.onWP8inAppTransactionsRestored += onWP8inAppTransactionsRestored; WindowsPhone8_Store.InApp.onWP8inAppCancelled += onWP8inAppCancelled; WindowsPhone8_Store.InApp.onWP8inAppFailed += onWP8inAppFailed; }
The most Calls to the Windows Phone 8 InApp Api calls are async and fire an event after there are finished.
//item was purchased successfully private void onWP8inAppPurchased(PurchasableProduct item) { } //success is True when the user own the item private void onWP8inAppTransactionsRestored(bool success) { } //item purchase process was cancelled from the user private void onWP8inAppCancelled(PurchasableProduct item) { } //item can not be purchased. Read the log file private void onWP8inAppFailed(PurchasableProduct item) { }
Purchasable Items
There are two functions to get all purchasables items. The first gives you a String Array with all Product IDs. The other
function Return an Array from type PurchasableProduct.
// Return String[] array with all purchasable id from the Windows Phone 8 Store WP8inApp.AllPurchasableItems() // Return PurchasableProduct[] array with all purchasable item infos WP8inApp.AllPurchasableItemIDs();
Purchasable Product Item
Property |
Access type |
Description |
---|---|---|
ProductId | Read-only | Gets the ID of an app’s in-app offer. |
Description | Read-only | Gets the description of the in-app product. |
FormattedPrice | Read-only | Gets the app’s purchase price formatted for the current market and currency. |
ImageUri | Read-only | Gets the URI of the image associated with this product. |
Name | Read-only | Gets the descriptive name of the product or feature. |
ItemProductType | Read-only | Gets the type of this in-app product. This can be either ProductType.Consumable or ProductType.Durable. |
License Information
Provides access to the current app’s license metadata.
WP8inApp.GetLicenseInformation("productid")
Property |
Access type |
Description |
---|---|---|
ExpirationDate | Read-only | Gets the expiration date and time of the license. |
IsActive | Read-only | Gets the value that indicates whether the feature’s license is active. |
ProductId | Read-only | Gets the ID of an app’s in-app offer. |
Purchase Product
To purchases the InApp product you only need the product ID which you can get from WP8inApp.AllPurchasableItemIDs();
void PurchaseProduct() { // Buy the Product WP8inApp.PurchaseProduct("coin100"); }
Test the Windows Phone 8 InApp Purchases
In Unity3D Editor you get some test items.
You can test in-app purchase in your Windows Phone app by following one of these techniques.
Creating a Dev Center beta app and adding beta in-app products
Testing your app’s in-app feature is to create a Dev Center beta app and add beta in-app products. In the Windows Phone Dev Center, you can upload your app to the Windows Phone Store as a beta app. Then, add your beta in-app products to the app. Test the in-app purchase process with the beta app.
Version 1.1 (2 Feb 2016)
Leave a reply