Android Question In App Billing for B4A Default nor B4XPages

Markos

Well-Known Member
Licensed User
Longtime User
Hi All,

I am now ready to implements InApp Billing for Googleplay. I have the example provided by Erel and I want to confirm a few aspects as relates to Default B4A Not B4XPages

Steps to setup programatically

1) Add to the manifest
B4X:
CreateResourceFromFile(Macro, GooglePlayBilling.GooglePlayBilling)
2) Create a BillingClient object in the starter service and initialize it. or can it be in the Main sub
B4X:
billing.Initialize("billing")
3) The PurchasesUpdated is the only event that needs to be handled in its own sub and that sub must be in the same module where BillingClient was initialized does this mean in the Starter Service module
4) What does consume a purchase vs acknowledge and is consume necessary to accept the payment as valid?

A simple overview of what I want to implement
1) Customer Pays for an InApp product (in this case usage credit)
2) I verify the in App purchase was successful
3) I topup the customer usage credit

I would be most grateful to dummy it up for me to fast track my understanding.

Cheers

Mark
 

asales

Expert
Licensed User
Longtime User
Hi All,

I am now ready to implements InApp Billing for Googleplay. I have the example provided by Erel and I want to confirm a few aspects as relates to Default B4A Not B4XPages

Steps to setup programatically

1) Add to the manifest
B4X:
CreateResourceFromFile(Macro, GooglePlayBilling.GooglePlayBilling)
OK
2) Create a BillingClient object in the starter service and initialize it. or can it be in the Main sub
B4X:
billing.Initialize("billing")
In my previous apps that use Activity, I put the code in the Starter. I think this can also be used in the main module, but since all my apps today are B4xpages, I can't confirm. But you can test it in both modules.
3) The PurchasesUpdated is the only event that needs to be handled in its own sub and that sub must be in the same module where BillingClient was initialized does this mean in the Starter Service module
OK
4) What does consume a purchase vs acknowledge and is consume necessary to accept the payment as valid?

A simple overview of what I want to implement
1) Customer Pays for an InApp product (in this case usage credit)
2) I verify the in App purchase was successful
3) I topup the customer usage credit
Check this line in the library: "Consuming a purchase removes it from the 'purchased' products."
When you use the `consume` method, the user can buy the item again, so you need to change the code to handle this (control the credit of the customer).
 
Upvote 0

Markos

Well-Known Member
Licensed User
Longtime User
OK

In my previous apps that use Activity, I put the code in the Starter. I think this can also be used in the main module, but since all my apps today are B4xpages, I can't confirm. But you can test it in both modules.

OK

Check this line in the library: "Consuming a purchase removes it from the 'purchased' products."
When you use the `consume` method, the user can buy the item again, so you need to change the code to handle this (control the credit of the customer).
Many thanks. I started reading up more and I have a few more points for clarification

1. The goggleplay console monetisation settings the, Topic Name is required? I created it and set it under monetization menu option

2. Does this workflow look correct and complete when initiating with a call of GetProductDetails and to consume after processing a successful purchase or do we have to use QueryProductDetails instead of QuerySkuDetails and if so any examples how to use the new method with ProductDetailsParams

B4X:
Sub GetProductDetails
   Dim skus As List
   skus.Initialize
   skus.Add("product1")
   skus.Add("product2")
   skus.Add("product3")
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then

   Dim sf As Object = billing.QuerySkuDetails("inapp", skus)
Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, Skus As List)
   If Result.IsSuccess And Skus.Size > 0 Then
    Result = billing.LaunchBillingFlow(Skus.get(0))
   End If
else
ToastMessageShow("Error starting billing process", True)
End If
End Sub

Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
    If Result.IsSuccess Then
        For Each p As Purchase In Purchases
            ConsumeProduct(p)
        Next
    End If
End Sub

Private Sub ConsumeProduct(p as Purchase)
            If p.Sku = "product1" Then
                topup(10)
            Else if p.Sku = "product2" Then
                topup(20)
            Else if p.Sku = "product2" Then
                topup(50)
            End If
            Wait For (billing.Consume(p.PurchaseToken, "")) Billing_ConsumeCompleted (Result As BillingResult)
End Sub

sub topup
'do stuff to credit user account
end sub

4. Do I have any need for the RSA public key provided by google in the inapp one time purchase workflow
 
Last edited:
Upvote 0

asales

Expert
Licensed User
Longtime User
Many thanks. I started reading up more and I have a few more points for clarification

1. The goggleplay console monetisation settings the, Topic Name is required? I created it and set it under monetization menu option
You need the "Product ID". With this ID you can get the price, title, description of the product, etc.
2. Does this workflow look correct and complete when initiating with a call of GetProductDetails and to consume after processing a successful purchase or do we have to use QueryProductDetails instead of QuerySkuDetails and if so any examples how to use the new method with ProductDetailsParams

B4X:
Sub GetProductDetails
   Dim skus As List
   skus.Initialize
   skus.Add("product1")
   skus.Add("product2")
   skus.Add("product3")
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then

   Dim sf As Object = billing.QuerySkuDetails("inapp", skus)
Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, Skus As List)
   If Result.IsSuccess And Skus.Size > 0 Then
    Result = billing.LaunchBillingFlow(Skus.get(0))
   End If
else
ToastMessageShow("Error starting billing process", True)
End If
End Sub

Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
    If Result.IsSuccess Then
        For Each p As Purchase In Purchases
            ConsumeProduct(p)
        Next
    End If
End Sub

Private Sub ConsumeProduct(p as Purchase)
            If p.Sku = "product1" Then
                topup(10)
            Else if p.Sku = "product2" Then
                topup(20)
            Else if p.Sku = "product2" Then
                topup(50)
            End If
            Wait For (billing.Consume(p.PurchaseToken, "")) Billing_ConsumeCompleted (Result As BillingResult)
End Sub

sub topup
'do stuff to credit user account
end sub
I think so, but you need to test.
4. Do I have any need for the RSA public key provided by google in the inapp one time purchase workflow
Yes. Check the billing example:
Public const BILLING_KEY As String = "MIIBI..."
 
Upvote 0

Markos

Well-Known Member
Licensed User
Longtime User
You need the "Product ID". With this ID you can get the price, title, description of the product, etc.
Understood it was created but I don't see what code uses it so I assume it is just some push/pull mechanism to facilitate all the event triggers/subs
I think so, but you need to test.
Will do!
Yes. Check the billing example:
Public const BILLING_KEY As String = "MIIBI..."
Yep Implemented it, only thing that confused me at first glance is there is an AND in the example using the PublicRSAkey when it should be an OR. Funny thing is 50+ examples online and very rarely shows using the publickey to verify, they more use the purchase_state so I don't know if it is overkill, redundant or necessary
 
Upvote 0
Top