Android Question Google billing

ilan

Expert
Licensed User
Longtime User
hi, i have a question to the new google billing method from here: https://www.b4x.com/android/forum/threads/googleplaybilling-in-app-purchases.109945/

so i have downloaded the example and i try to understand but it is unclear to me.

there is a removeAds button and a resetAds button

the resetAds event looks like this:

B4X:
Public Sub ResetAds
    'we want to get the ads product and consume it
    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)
        If Result.IsSuccess Then
            ConsumeAdsProduct(Purchases)
        End If
    End If
End Sub

Private Sub ConsumeAdsProduct(Purchases As List)
    For Each p As Purchase In Purchases
        If p.Sku = ADS_SDK_ID Then
            Wait For (billing.Consume(p.PurchaseToken, "")) Billing_ConsumeCompleted (Result As BillingResult)
            If Result.IsSuccess Then
                Log("consumed")
                AdsRemoved = False
                UpdateAdsState
            End If
        End If
    Next
End Sub

so it says we want to get the ads product and consume it so i understand the purchase is made here but why is AdsRemoved set to False?

if it is False than ADS will be shown, right (lblAd.Visible = Not(AdsRemoved)) ?

B4X:
Private Sub UpdateAdsState
    lblAd.Visible = Not(AdsRemoved)
    btnRemoveAds.Enabled = Not(AdsRemoved)
    btnReset.Enabled = AdsRemoved
End Sub

and if we make the purchase in the ResetAds button than what do we do in the btnRemoveAds event?

B4X:
Sub btnRemoveAds_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 Return
        End If
    End If
    ToastMessageShow("Error starting billing process", True)
End Sub

i am really confused :confused:
 

aeric

Expert
Licensed User
Longtime User
if it is False than ADS will be shown, right (lblAd.Visible = Not(AdsRemoved)) ?
It is for reseting the ads.

B4X:
Sub btnReset_Click
    ResetAds
End Sub

   |
   |
   V

Public Sub ResetAds
  ...
  ConsumeAdsProduct(Purchases)
  ...
End Sub

   |
   |
   V

Private Sub ConsumeAdsProduct(Purchases As List)
  ...
  Log("consumed")
  AdsRemoved = False
  UpdateAdsState
  ...
End Sub

   |
   |
   V

Private Sub UpdateAdsState
    lblAd.Visible = Not(AdsRemoved) ' <-- llblAd.Visible = True, Ads is reset and show
    btnRemoveAds.Enabled = Not(AdsRemoved)
    btnReset.Enabled = AdsRemoved
End Sub
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
if we make the purchase in the ResetAds button than what do we do in the btnRemoveAds event?
We make purchase to remove ads by clicking on btnRemoveAds.
Reset ads is to let us "purchase again" by clicking on btnReset.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I have a demo app
I can send you the project if you are interested.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
thanx @aeric
i didn't knew it is possible to remove the purchase from the customer with billing.Consume(p.PurchaseToken, "")
 
Upvote 0
Top