Android Question Google Billing 5: OfferToken for single subscription offer

toby

Well-Known Member
Licensed User
Longtime User
I'm upgrading Google Billing to v5, which is required by Google, and after reading all the relate information, the purchase totken issue is still confusing me.

I got the code below from this post: Source: https://www.b4x.com/android/forum/t...-due-to-google-restriction.142524/post-903185
B4X:
Private Sub LaunchBillingFlow (Client As BillingClient, Sku As SkuDetails, OfferToken As String) As BillingResult
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim ProductDetailsParamsBuilder As JavaObject
    ProductDetailsParamsBuilder = ProductDetailsParamsBuilder.InitializeStatic("com.android.billingclient.api.BillingFlowParams.ProductDetailsParams").RunMethod("newBuilder", Null)
    ProductDetailsParamsBuilder.RunMethod("setProductDetails", Array(Sku))
    ProductDetailsParamsBuilder.RunMethod("setOfferToken", Array(OfferToken))
    Dim ProductDetails As List = Array(ProductDetailsParamsBuilder.RunMethod("build", Null))
    
    Dim BillingFlowParamsBuilder As JavaObject
    BillingFlowParamsBuilder = BillingFlowParamsBuilder.InitializeStatic("com.android.billingclient.api.BillingFlowParams").RunMethod("newBuilder", Null)
    BillingFlowParamsBuilder.RunMethod("setProductDetailsParamsList", Array(ProductDetails))
    
    Return Client.As(JavaObject).GetFieldJO("client").RunMethod("launchBillingFlow", Array(ctxt, BillingFlowParamsBuilder.RunMethod("build", Null)))
End Sub

In my app, there is only a single in-app product for purchase which is a subscription. Can I just pass an empty string as the OfferToken? If no, how to get it?

TIA
 
Solution
For reason unbeknownst to me, I had to pass an empty token (offerToken="") in order for it to work and to avoid the fatal error "There was some error on our end. Please try again" when executing the following line
B4X:
 Return Client.As(JavaObject).GetFieldJO("client").RunMethod("launchBillingFlow", Array(ctxt, BillingFlowParamsBuilder.RunMethod("build", Null)))

toby

Well-Known Member
Licensed User
Longtime User
For reason unbeknownst to me, I had to pass an empty token (offerToken="") in order for it to work and to avoid the fatal error "There was some error on our end. Please try again" when executing the following line
B4X:
 Return Client.As(JavaObject).GetFieldJO("client").RunMethod("launchBillingFlow", Array(ctxt, BillingFlowParamsBuilder.RunMethod("build", Null)))
 
Last edited:
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…