Android Question Billing not picking up latest subscription

tsteward

Well-Known Member
Licensed User
Longtime User
I have a client where p.OrderId picks up the original subscription in 2019 but I need the latest one in 2022
Attached is a screen shot from my app showing the productid.
No doubt I'm doing something wrong but how do I get the latest renewal not the original.

My Code
B4X:
public Sub RestorePurchases
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then
        Wait For (billing.QueryPurchases("subs")) Billing_PurchasesQueryCompleted (Result As BillingResult, Purchases As List)
        If Result.IsSuccess Then
            For Each p As Purchase In Purchases
                productID = p.OrderId
                purchaseTime = p.PurchaseTime
                SKU_Purchased = p.Sku
                token = p.PurchaseToken
                subsID = p.Sku
            Next
        End If
    End If
End Sub
 

Attachments

  • 325623520_1142202249989613_8536094297384413635_n.jpg
    325623520_1142202249989613_8536094297384413635_n.jpg
    32.1 KB · Views: 87
  • Screenshot 2023-01-15 120556.png
    Screenshot 2023-01-15 120556.png
    97.5 KB · Views: 68
Last edited:

aeric

Expert
Licensed User
Longtime User
Update to latest version of Google Play Billing v5
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Yes this is billing V5
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
I have tried getting p.OderID and p.PurchaseTime in both restore purchases and Handle Purchase
But I only ever get the original purchase not any subsequent re-subscriptions
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Here is handlepurchase
B4X:
public Sub HandleAdsPurchase (p As Purchase)
    If p.PurchaseState <> p.STATE_PURCHASED Then Return
    'Verify the purchase signature.
    'This cannot be done with the test id.
    If p.Sku.StartsWith("android.test") = False And billing.VerifyPurchase(p, BILLING_KEY) = False Then
        Log("Invalid purchase")
        Return
    End If
    If p.IsAcknowledged = False Then
        'we either acknowledge the product or consume it.
        Wait For (billing.AcknowledgePurchase(p.PurchaseToken, "")) Billing_AcknowledgeCompleted (Result As BillingResult)
        If Result.IsSuccess Then
            If p.Sku = ADS_SDK_Token Then
                Wait For (billing.QueryPurchases("inapp")) Billing_PurchasesQueryCompleted (Result As BillingResult, Purchases As List)
                myLog.Add($"(HandleAdsPurchase) Info received from PS Result - ${Result.ResponseCodeString}"$)
                If Result.IsSuccess Then
                    B4XPages.MainPage.Pages.PagePINCalc.sendPINRequest(Purchases,p.OrderId)
                End If
            End If
            
        End If
    Else
        If p.Sku = ADS_SDK_ID Or p.Sku = ADS_SDK_ID2 Or p.Sku = ADS_SDK_ID3 Then
            productID = p.OrderId
            purchaseTime = p.PurchaseTime
            SKU_Purchased = p.Sku
            token = p.PurchaseToken
            subsID = p.Sku
            Main.AppSubscriptionActive = True
            Main.OKToPost = True
        Else
            productID = ""
            Main.AppSubscriptionActive = False
            Main.OKToPost = False
        End If
    End If
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I share my version:

B4X:
Private Sub HandleSubscription (p As Purchase)
    If p.PurchaseState <> p.STATE_PURCHASED Then Return
    If billing.VerifyPurchase(p, BILLING_KEY) = False Then
        'Log("Invalid purchase")
        Return
    End If
    Dim PId As String = p.Sku
    If PId = "weekly_1" Then
        Log("Verified: " & PId)
    Else
        Log("Invalid Sku")
        Return
    End If
    If p.IsAcknowledged = False Then
        'we either acknowledge the product or consume it.
        Wait For (billing.AcknowledgePurchase(p.PurchaseToken, "")) Billing_AcknowledgeCompleted (Result As BillingResult)
        Log("Acknowledged: " & Result.IsSuccess)
    End If
    BlnWeekly = True
    UpdateSubscriptionState
End Sub

I have a subscription sku "weekly_1"
Is this is found, I will set the variable BlnWeekly to True. This state is update with UpdateSubscriptionState that will determine the UI such as enable a button or restricted function.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
One important point you may have missed.



You need to implement LaunchBillingFlow.
I do this when initially purchasing the subscription
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Did you add the new subs sku ? such as "weekly_2022".

B4X:
Dim sf As Object = billing.QuerySkuDetails("subs", Array("weekly_2019", "weekly_2022"))
Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, SkuDetails As List)
You might have something there. I'll look into it shortly
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
No I had all that setup correctly.

Still no idea why p.OrderId doesn't return the most recent subscription.

I'll find another way around my issue

Thank you
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
I'd really like to solve this and hoping someone sees this that didn't before.

When getting P.Orderid I only every get the original subscription not the current one.
How can I retrieve the current order?
 
Upvote 0
Top