Android Question GooglePlayBilling V8.00+ - Need help fixing compilation/runtime setup

KevinSuzanne

Member
Licensed User
Hi everyone,

I am trying to implement the new GooglePlayBilling (Version 8.00+) engine in my app using B4A 13.40, but I am running into issues getting the subscription flow initialized and working properly.

Could someone kindly check my setup and tell me what I am missing?

My Setup Details:

  • B4A Version: 13.40
  • Java Version: 19
  • Library Checked: GooglePlayBilling (v8.00+)
  • Product Type: Subscription (subs)
  • Product ID: streets_wagerq_monthly
Manifest Editor:

Code snippet

CreateResourceFromFile(Macro, GooglePlayBilling.GooglePlayBilling)

Starter Service Code:

Code snippet

#Region Service Attributes
#StartAtBoot: False
#End Region

Sub Process_Globals
End Sub

Sub Process_Variables
#IgnoreWarnings: 9, 10
Public billing As BillingClient
Public Const SUBS_ID As String = "streets_wagerq_monthly"
Public IsPremiumUser As Boolean = False
End Sub

Sub Service_Create
billing.Initialize("billing")
Log("GooglePlayBilling v8.00+ engine initialized.")
End Sub

Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground
End Sub

Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
If Result.IsSuccess And Purchases.IsInitialized Then
Dim FoundActivePurchase As Boolean = False

For Each p As Purchase In Purchases
If p.ProductId = SUBS_ID Then
If p.PurchaseState = p.STATE_PURCHASED Then
FoundActivePurchase = True
If p.IsAcknowledged = False Then
Dim sf As Object = billing.AcknowledgePurchase(p.PurchaseToken, "")
Wait For (sf) billing_AcknowledgeCompleted (Res As BillingResult)
Log("V8 Token Acknowledgement Result: " & Res.IsSuccess)
End If
End If
End If
Next

If FoundActivePurchase Then
IsPremiumUser = True
If IsPaused(Main) = False Then
CallSub(Main, "RefreshPremiumUI")
End If
End If
End If
End Sub

Sub Service_Destroy
End Sub

Main Activity Code (Billing block):

Code snippet

Sub Activity_Resume
CheckSubscriptionStatus
End Sub

Private Sub CheckSubscriptionStatus
Wait For (Starter.billing.ConnectIfNeeded) billing_Connected (Result As BillingResult)
If Result.IsSuccess Then
Dim sf As Object = Starter.billing.QueryPurchases("subs")
Wait For (sf) billing_PurchasesReturned (Res As BillingResult, Purchases As List)
If Res.IsSuccess Then
CallSub3(Starter, "billing_PurchasesUpdated", Res, Purchases)
End If
Else
Log("Store connection failed or timed out.")
End If
End Sub

Public Sub RefreshPremiumUI
If Starter.IsPremiumUser Then
Log("UI Status: Premium Features Active")
Else
Log("UI Status: Standard Mode active")
End If
End Sub

Sub btnUpgrade_Click
Wait For (Starter.billing.ConnectIfNeeded) billing_Connected (Result As BillingResult)
If Result.IsSuccess Then
Dim sf As Object = Starter.billing.QuerySkuDetails("subs", Array As String(Starter.SUBS_ID))
Wait For (sf) billing_SkuDetailsReturned (Res As BillingResult, SkuDetailsList As List)

If Res.IsSuccess And SkuDetailsList.Size > 0 Then
Starter.billing.LaunchBillingFlow(SkuDetailsList.Get(0))
Else
Log("Product ID not found or mismatched: " & Res.DebugMessage)
End If
Else
Log("Cannot reach store connection.")
End If
End Sub

Any guidance on getting this standard V8.00+ template perfectly synchronized would be greatly appreciated. Thank you!
 

aeric

Expert
Licensed User
Longtime User
Read this:

and this:
 
Upvote 0
Top