Android Question VerifyPurchase

micheleBr

Member
Licensed User
Longtime User
Hi all,
I have a problem...
during the execution of this part of the code:

Code: Copy
    If pr.Sku.StartsWith("android.test") = False And billing.VerifyPurchase(pr, BILLING_KEY) = False Then
        Log("Invalid purchase")
        Return
    End If

the result "billing.VerifyPurchase" is always false even if I buy the in-app product, and after 3 days I get back the money from Google..
The "BILLING_KEY" is the same as another app that all works.
I follow this example, in one app all work, in another not...

What can be the problem?

Tnx in advance.
 
Are you putting your products/subscriptions name in pr.sku.startswith parameter?
1683888694645.png
 
Upvote 0
Hi,
not is a "one-time purchase", I just follow this:

Code: Copy
Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
    'This event will be raised when the status of one or more of the purchases has changed.
    'It will usually happen as a result of calling LaunchBillingFlow however it can be called in other cases as well.
 
    If Result.IsSuccess Then
     
        For Each pr As Purchase In Purchases
         
            If pr.Sku = ADS_SDK_ID Then
                HandleAdsPurchase(pr)
            Else
                Log("Unexpected product...")
            End If
         
        Next
     
    End If
 
End Sub

Private Sub HandleAdsPurchase (pr As Purchase)
 
    If pr.PurchaseState <> pr.STATE_PURCHASED Then Return
    'Verify the purchase signature.
    'This cannot be done with the test id.
 
    If pr.Sku.StartsWith("android.test") = False And billing.VerifyPurchase(pr, BILLING_KEY) = False Then
        Log("Invalid purchase")
        Return
    End If
 
    If pr.IsAcknowledged = False Then
        'we either acknowledge the product or consume it.
        Wait For (billing.AcknowledgePurchase(pr.PurchaseToken, "")) Billing_AcknowledgeCompleted (Result As BillingResult)
        Log("Acknowledged: " & Result.IsSuccess)
 
    End If
 
    Log("AdsRemoved")
    CheckDonation
 
End Sub

Private Sub btnDonazione_Click
 
    'make sure that the store service is connected
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then
        'get the sku details
        Dim sf As Object = billing.QuerySkuDetails("inapp", Array(ADS_SDK_ID))
        Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, SkuDetails As List)
        If Result.IsSuccess And SkuDetails.Size = 1 Then
            Result = billing.LaunchBillingFlow(SkuDetails.Get(0))
            If Result.IsSuccess Then
                CheckDonation
                Return
            End If
        End If
    End If
    ToastMessageShow("Error starting billing process", True)
 
End Sub

Private Sub CheckDonation
 
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then
        Wait For (billing.QueryPurchases("inapp")) Billing_PurchasesQueryCompleted (Result As BillingResult, Purchases As List)
        Log("Query completed: " & Result.IsSuccess)
        If Result.IsSuccess Then
            For Each pr As Purchase In Purchases
                If pr.Sku = ADS_SDK_ID Then HandleAdsPurchase(pr)
             
                If pr.PurchaseState= pr.STATE_PURCHASED Then
                    giaAcquistato =True
                Else
                    giaAcquistato =False
                End If
             
            Next
        End If
    End If
 
    If giaAcquistato =True Then
        btnDonazione.Visible =False
    Else
        btnDonazione.Visible =True
    End If
 
End Sub

In Sub HandleAdsPurchase, the code:
Code: Copy
billing.VerifyPurchase(pr, BILLING_KEY) = False
returns always false; but inside "pr" object, there are all values (after I bought it) like in another app that works...
 
Upvote 0
Back
Top