Hi All, this is an little tutorial to implement "App-In consumable purchases"
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim manager As BillingManager3
Private key As String = "MIIBIjANBgkqXXXX......"
Dim Productid1, Productid2 As String
Dim Producttype As String
Dim DeveloperPayload As String
DeveloperPayload="Example In-App Consumable" ' ---> Name of my App "
Producttype="inapp" ' ---> this is an input
Productid1 = "price_300" ' ---> this is an input I it is the product id i defined in the store
Productid2 = "price_500" ' ---> this is an input I it is the product id i defined in the store
End Sub
Sub Globals
Private Button3 As Button
Private Label2 As Label
Private Button1 As Button
Private Label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime = True Then
manager.Initialize("manager", key)
End If
manager.DebugLogging = True
Activity.LoadLayout("Main")
End Sub
Sub Manager_BillingSupported (Supported As Boolean, Message As String)
Log(Supported & ", " & Message)
Log("Subscriptions supported: " & manager.SubscriptionsSupported)
If Supported Then
manager.GetOwnedProducts
End If
End Sub
Sub manager_OwnedProducts (Success As Boolean, purchases As Map)
Log(Success)
If Success Then
Log(purchases)
For Each p As Purchase In purchases.Values
Log(p.Productid & ", Purchased? " & (p.PurchaseState = p.STATE_PURCHASED))
Next
End If
End Sub
Sub button1_click
manager.RequestPayment(Productid1, Producttype, DeveloperPayload)
End Sub
Sub Button3_Click
manager.RequestPayment(Productid2, Producttype, DeveloperPayload)
End Sub
Sub Manager_PurchaseCompleted(Success As Boolean, Product As Purchase)
If Success Then
manager.ConsumeProduct(Product)
If Product.Productid = "price_300" Then
Msgbox("Hai acquistato price_300","Messaggio")
Label1.Text = "Acquisto Prima Opzione"
Label2.Text = "Hai 60 Secondi"
Else If Product.Productid = "price_500" Then
Msgbox("Hai acquistato price_500","Messaggio")
Label1.Text = "Acquisto Seconda Opzione"
Label2.Text = "Hai 100 Secondi"
End If
End If
End Sub