In-app purchase example not working.

86 views
Skip to first unread message

Fatih Elitas

unread,
Sep 16, 2025, 4:45:40 PMSep 16
to DroidScript
Hello;

The SPK file works in the purchase or subscription example, but when I convert it to AAB or APK, it doesn't trigger. It just sits there.
What could be the problem?


//Set to "IAP" or "SUBS"
var mode = "IAP"

//Change this list to your own product ids.
var products = "plugin_apkbuilder,plugin_spheroball,subs_premium1";
var productId = "plugin_spheroball";
   
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" )

//Create an info button.
btnInfo = app.CreateButton( "Get Store Info", 0.5, 0.1 )
btnInfo.SetOnTouch( btnInfo_OnTouch )
lay.AddChild( btnInfo )

//Create a purchases  button.
btnPurch = app.CreateButton( "Get Purchases", 0.5, 0.1 )
btnPurch.SetOnTouch( btnPurch_OnTouch )
lay.AddChild( btnPurch )

//Create a buy  button.
btnBuy = app.CreateButton( "Buy", 0.5, 0.1 )
btnBuy.SetOnTouch( btnBuy_OnTouch )
lay.AddChild( btnBuy )

//Create a text control to show results.
txt = app.CreateText( "", 0.9, 0.5, "Multiline,Left" )
txt.SetMargins( 0,0.1,0,0 )
txt.SetTextColor( "#ffffffff" )
txt.SetBackColor( "#ff222222" )
lay.AddChild( txt )

//Add layout to app.
app.AddLayout( lay )

//Create a playstore object.
playStore = app.CreatePlayStore()
}

//Called when user touches our Info button.
function btnInfo_OnTouch()
{
    //Get product info from Google Play.
    //(Only paid items will be listed)
    playStore.GetBillingInfo( products, OnStoreInfo, mode )
}

//Show Play Store prices.
function OnStoreInfo( items )
{
    txt.Log( "Prices:" )
    for( var i=0; i<items.length; i++ )
    {
        txt.Log( "ProductId = " + items[i].productId )
        txt.Log( "Price = " + items[i].price )
    }
}

//Called when user touches our Purchases button.
function btnPurch_OnTouch()
{
    playStore.GetPurchases( OnPurchases, mode )
}

//Show users purchases.
function OnPurchases( items )
{
    txt.Log( "\nPurchases:" )
    for( var i=0; i<items.length; i++ )
    {
        txt.Log( "ProductId = " + items[i].productId )
        txt.Log( "Purchased = " + (items[i].purchaseState==0) )
    }
}

//Buy an IAP item.
function btnBuy_OnTouch()
{
    playStore.Purchase( productId, "MyToken", OnPurchased, mode )
}

//Handle completed purchase.
function OnPurchased( prodId, orderId, purchToken, devToken, packageName )
{
    console.log( prodId +" "+ orderId +" "+ purchToken )
    app.Alert( "Item purchased!", "My App" )
}



Cemal

unread,
Sep 20, 2025, 3:39:37 AMSep 20
to DroidScript
Hello, I'm not sure, but if you haven't published it on the Play Store, it's normal for it not to work. You can publish it on the Play Store as a test app and try it out. The Play Store may prevent sales from being made on apps that are not published on the Play Store.

Dave

unread,
Sep 20, 2025, 8:58:58 AMSep 20
to DroidScript
Cemal is correct, you will need to get your own product id's and publish your AAB to the beta or test track to make it work.   Google Play does some check against your app when purchasing.

Also, you can setup your email address as a 'test account' in the developer console so that you don't get charged when you purchase things, which allows you to test the purchasing flow in your app.

Reply all
Reply to author
Forward
0 new messages