Dear All,
Please see my code modules placement in Starter vs Main modules to ensure correctness and completeness. Really apprec feedback
Starter
Main
And the In App Purchase is triggered by calling GetProductDetails
Please see my code modules placement in Starter vs Main modules to ensure correctness and completeness. Really apprec feedback
Starter
B4X:
Sub Process_Globals
Public billing As BillingClient
Public Const My_PublicKey As String = "xxxxxxxx"
Public Const product20 As String = "product20"
Public Const product50 As String = "product50"
End Sub
Sub Service_Create
billing.Initialize("billing")
End Sub
Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
If Result.IsSuccess Then
For Each p As Purchase In Purchases
If billing.VerifyPurchase(p, My_PublicKey) = True Then
If p.PurchaseState = p.STATE_PURCHASED Then
CallSubDelayed2(Main,"ConsumeProduct",p)
End If
End If
Next
End If
End Sub
Main
B4X:
Sub GetProductDetails
Dim skus As List
skus.Initialize
skus.Add(Starter.product20)
skus.Add(Starter.product50)
Wait For (Starter.billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
If Result.IsSuccess Then
Dim sf As Object = Starter.billing.QuerySkuDetails("inapp", skus)
Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, skus As List)
If Result.IsSuccess And skus.Size > 0 Then
Result = Starter.billing.LaunchBillingFlow(skus.Get(0))
End If
Else
ToastMessageShow("Error starting billing process", True)
End If
End Sub
Private Sub ConsumeProduct(p As Purchase)
If p.Sku =Starter.product20 Then
topup("20")
Else if p.Sku = Starter.product50 Then
topup("50")
End If
Wait For (Starter.billing.Consume(p.PurchaseToken, "")) Billing_ConsumeCompleted (Result As BillingResult)
End Sub
And the In App Purchase is triggered by calling GetProductDetails
Last edited: