Android Question Howto GooglePlayBilling Subscription Up/Downgrade?

fredo

Well-Known Member
Licensed User
In Google billing, subscription products were created for month, quarter and year.
The playstore setup and the testapp run smoothly and as expected.

Now the user should be able to upgrade or downgrade as described here

2019-11-04_13-24-14.png

However, when upgrading or downgrading, you pass the product IDs for the current subscription and the future (upgraded or downgraded) subscription to the BillingFlowParams object using the setOldSku() method.


At this point it is unclear in which way the "setOldSku" can be achieved
 

Erel

Administrator
Staff member
Licensed User
You can use this code to start the billing flow and set the old SKU:

B4X:
'should be called from the activity
Sub LaunchBillingFlow(sku As SkuDetails, OldSku As String, PurchaseToken As String) As BillingResult
    Dim jo As JavaObject = Starter.billing
    Dim BillingClient As JavaObject = jo.GetField("client")
    Dim context As JavaObject
    context.InitializeContext
    Dim BillingFlowParams As JavaObject
    BillingFlowParams = BillingFlowParams.InitializeStatic("com.android.billingclient.api.BillingFlowParams") _
                .RunMethodJO("newBuilder", Null).RunMethodJO("setSkuDetails", Array(sku)) _
                .RunMethodJO("setOldSku", Array(OldSku, PurchaseToken)).RunMethod("build", Null)
    Return BillingClient.RunMethod("launchBillingFlow", Array(context, BillingFlowParams))
End Sub
 
Last edited:
Upvote 0
Top