Android Question A problem with buying a two-level subscription in Google Billing

Jerryk

Member
Licensed User
Longtime User
Unlike Inapp purchases, Subscriptons have two levels:
  • Subscripton (what I want to buy) and
  • Base plan (for how long, from what frequency, for how much).

In my situation I have two subscripons: "demo" and "test".
"Test" has two active Base plans: "test2" - 1 month, prepaid and "test3" - weekly, auto-renewing.

1699110619603.png

1699113587698.png

When buying only with a parameter - Array ("test") returns the results. (test2 and test3 none). In this case, Google Billing offers me to buy Base plan "test3". I do not know why? How to buy specifically base plan "test2" or another?

How to choose a specific Base plan that I want to buy?

Function used:


B4X:
Private Sub Button2_Click
    Try
         Msgbox2Async("Confirm subscriptions?" & CRLF & CRLF & _
        "Note: For test, auto-renewal will take place max 6 times unless cancel", "CONFIRM?", "Yes", "Cancel", "", Null, False)
        Wait For Msgbox_Result (Confirm As Int)
        If Confirm = DialogResponse.POSITIVE Then
            Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
            If Result.IsSuccess Then
                'get the sku details
                Dim sf As Object = billing.QuerySkuDetails("subs", Array("test"))
                Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, SkuDetails As List)
                If Result.IsSuccess And SkuDetails.Size = 1 Then
                    Log( "SkuDetails:" & SkuDetails.Get(0))
                    Result = LaunchBillingFlow(billing, SkuDetails.Get(0), "")
                    If Result.IsSuccess Then
                        LogColor("Purchased subs", Colors.Red)
                        Return
                    End If
                End If
            End If
            ToastMessageShow("Error starting billing process", True)
        End If
    Catch
        LogColor("Error: " & LastException.Message, Colors.Red)
        MsgboxAsync("Subscription failed", "E R R O R")
    End Try
End Sub

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
 
Last edited:

Cristian Achim

Member
Licensed User
Longtime User
Unlike Inapp purchases, Subscriptons have two levels:
  • Subscripton (what I want to buy) and
  • Base plan (for how long, from what frequency, for how much).

In my situation I have two subscripons: "demo" and "test".
"Test" has two active Base plans: "test2" - 1 month, prepaid and "test3" - weekly, auto-renewing.

View attachment 147543
View attachment 147544
When buying only with a parameter - Array ("test") returns the results. (test2 and test3 none). In this case, Google Billing offers me to buy Base plan "test3". I do not know why? How to buy specifically base plan "test2" or another?

How to choose a specific Base plan that I want to buy?

Function used:


B4X:
Private Sub Button2_Click
    Try
         Msgbox2Async("Confirm subscriptions?" & CRLF & CRLF & _
        "Note: For test, auto-renewal will take place max 6 times unless cancel", "CONFIRM?", "Yes", "Cancel", "", Null, False)
        Wait For Msgbox_Result (Confirm As Int)
        If Confirm = DialogResponse.POSITIVE Then
            Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
            If Result.IsSuccess Then
                'get the sku details
                Dim sf As Object = billing.QuerySkuDetails("subs", Array("test"))
                Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, SkuDetails As List)
                If Result.IsSuccess And SkuDetails.Size = 1 Then
                    Log( "SkuDetails:" & SkuDetails.Get(0))
                    Result = LaunchBillingFlow(billing, SkuDetails.Get(0), "")
                    If Result.IsSuccess Then
                        LogColor("Purchased subs", Colors.Red)
                        Return
                    End If
                End If
            End If
            ToastMessageShow("Error starting billing process", True)
        End If
    Catch
        LogColor("Error: " & LastException.Message, Colors.Red)
        MsgboxAsync("Subscription failed", "E R R O R")
    End Try
End Sub

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
Hello! I have same problem. Did you solved it? Thank you!
 
Upvote 0

Cristian Achim

Member
Licensed User
Longtime User
Posting to old thread is a mistake.
You should always create a new thread for any issue you have.
I opened a new thread:
 
Upvote 0
Top