Hi Guys,
Sorry this is not documented properly yet, but here are some code snippets that might help those trying to use In App Purchasing:-
You will need to read the Google play IAP licensing info and setup IAP products in your dev console to use this.. although you can use Google's test ids to practice with at first.
Here is how to prepare for IAP:-
var playStore=null, purchases=[];
function OnStart()
{
DrawLayout();
:
//Create Google Play object.
playStore = app.CreatePlayStore();
:
}
Here is how to buy an item:-
//Purchase an IAP item.
function PurchaseItem()
{
//Start the purchase process.
var prodId = "myproductcode";
playStore.Purchase( prodId, "xbxrandomxbx", OnPurchased );
}
//Handle completed purchase.
function OnPurchased( prodId )
{
//Update purchase items array.
purchases[prodId] = true;
alert( "OnPurchased" + prodId );
}
Here is how to check for purchased items:-
//Check items are licensed.
function CheckLicenses()
{
//Check licenses after delay (allows app to finish starting up).
setTimeout( "playStore.GetPurchases(OnLicenses)", 1000 );
}
//Save licenses to an array.
function OnLicenses( items )
{
for( var i=0; i<items.length; i++ )
purchases[items[i].productId] = (items[i].purchaseState==0);
}
Here is how to get prices of items:-
//Get prices from Google Play.
//(Takes a comma separated list of prod ids)
function GetPrices( prodIDs )
{
//Get product info from Google Play.
//(Only paid items will be listed in OnStoreInfo)
playStore.GetBillingInfo( prodIDs, OnStoreInfo );
}
//Show Play Store prices.
function OnStoreInfo( items )
{
//Show prices.
for( var i=0; i<items.length; i++ )
{
var prodId = items[i].productId;
var price = items[i].price;
alert( prodId + " = " + price );
}
}