Coding Guidelines

Before using In-Apps API, the WP8InAppPurchasesManager should be initialised.

The code snippet shows how to start initialization and subscribe to the OnInitComplete action.

WP8InAppPurchasesManager.instance.init();
WP8InAppPurchasesManager.instance.OnInitComplete += OnInitComplete;

void OnInitComplete (WP8_InAppsInitResult res) {
	if(res.IsSucceeded) {
		Debug.Log("WP8InAppPurchasesManager initialized");
	} else  {
		Debug.Log("Initialization failed")
	}
}

original-c1fad9bb-556504c1df046.giforiginal-4ada3962-556504c1e88b6.gif

 

You can also check if WP8InAppPurchasesManager initialized using IsInitialized property:

if(WPN_BillingManagerExample.IsInited) {
	//some code
}

original-d76d1591-556504c1f1e1c.giforiginal-4c610baf-556504c207350.gif

 

As soon as WP8InAppPurchasesManager initialized we can use products property and retrieve its info.  

foreach(WP8ProductTemplate product in WP8InAppPurchasesManager.instance.products) {
	Debug.Log(product.Name);
	Debug.Log(product.Description);
	Debug.Log(product.ProductId);
	Debug.Log(product.Price);
	Debug.Log(product.ImgURL);
	Debug.Log(product.isPurchased);
}

original-57259b9d-556504c210cb6.giforiginal-0bc6eb5d-556504c21bf07.gif

 

The product info is represented as WP8ProductTemplate object.

public class WP8ProductTemplate {
	public string ImgURL { get;}
	public string Name { get; }
	public string ProductId { get; }
	public string Price { get; }
	public WP8PurchaseProductType Type { get; }
	public string Description { gt;  }
	public bool isPurchased { get; }
	private Texture2D texture;{ get;}
}

public enum WP8PurchaseProductType {
	Consumable,
	Durable
}

original-58ab79f8-556504c225ac5.giforiginal-3bfe1e9e-556504c28eb98.gif

 

The isPurchased property can be used to find out if Durable product was already purchased.

 

The following code snippet shows how to purchase the product if it, and find out purchase flow result.

WP8InAppPurchasesManager.instance.OnPurchaseFinished += OnPurchaseFinished;
WP8InAppPurchasesManager.instance.purchase("your_product_id_here");

private void OnPurchaseFinished(WP8PurchseResponce responce) {
	if(responce.IsSuccses) {
		//Unlock logic for product with id responce.productId should be here
		WP8Dialog.Create("Purchase Succse", "Product: " + responce.productId);
	} else {
		//Purchase fail logic for product with id responce.productId should be here
		WP8Dialog.Create("Purchase Failed", "Product: " + responce.productId);
	}
}

original-5d94a48d-556504c2cfdbc.giforiginal-44db2796-556504c2de2ea.gif

 

You can get more info about purchasing result by using WP8PurchseResponce properties.

public class WP8PurchseResponse {
	public bool IsSuccses {get;}
	public string receipt {get;}
	public string error  {get;}
}


public enum WP8PurchaseCodes  {
	SUCCSES = 0,
	CANCELED = 1,
	ERROR = 2,
	PURCHASED = 3
}

 

full example can be found at the In_AppPurchases example scene.