Android Question [Solved] In-App Purchase don't work

asales

Expert
Licensed User
Longtime User
I tried to create an app to use in-app to remove admob, but don't work.
I put the app in Google Play in beta test.

The RequestPayment is OK but OwnedProducts shows:
- SUCCESS: true
- PURCHASES: (MyMap) {} -> map is empty. Don't show the product purchased.

How I can fix it ?

Thanks in advance for any tip.

This is my code:
B4X:
Sub Process_Globals
    Dim manager As BillingManager3

    Dim Const key As String = "MIIBIjANBgkqhkiG9w0BAQEFAA..."
    Dim DeveloperPayload As String = "My App"   
End Sub

Sub Globals
    Private Button1 As Button
    Private pnlAdMob As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
   
      If FirstTime Then
      manager.Initialize("manager", key)     
    End If

    manager.DebugLogging = True  
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

'* * * IN-APP BILLING

Sub manager_BillingSupported (Supported As Boolean, Message As String)
   Log("SUPPORTED / MESSAGE: " & 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: " & Success)

    If Success Then
        Log("PURCHASES: " & purchases)
        For Each p As Purchase In purchases.Values
            If p.ProductId = "remove_ads" Then
                    If p.PurchaseState = p.STATE_PURCHASED Then
                        Log("STATE_PURCHASED")
                        pnlAdMob.Visible = False
                    Else If p.PurchaseState = p.STATE_CANCELED Or p.PurchaseState = p.STATE_REFUNDED Then
                        pnlAdMob.Visible = True
                    End If
                End If
            Next
        End If   
End Sub

Sub manager_PurchaseCompleted(Success As Boolean, Product As Purchase)
    If Success Then
        Log("You purchased " & Product.ProductId)
        manager.ConsumeProduct(Product)
        If Product.Productid = "remove_admob" Then
            Msgbox("Remove AdMob","In-App Purchase")
        End If
    End If
End Sub

Sub Button1_Click
    manager.RequestPayment("remove_admob", "inapp", DeveloperPayload)   
End Sub

the Logs shows:
B4X:
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for b4a.example.inapp
Subscriptions AVAILABLE.
SUPPORTED / MESSAGE: true, Setup successful. (response: 0:OK)
Subscriptions supported: true
Supported!!!
Starting async operation: refresh inventory
Querying owned items, item type: inapp
Package name: b4a.example.inapp
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Querying owned items, item type: subs
Package name: b4a.example.inapp
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Ending async operation: refresh inventory
SUCCESS: true
PURCHASES: (MyMap) {}
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Service (widgetservice) Start **
 

JonPM

Well-Known Member
Licensed User
Longtime User
Because of this line:
manager.ConsumeProduct(Product)

Why are you consuming the purchase? Once you consume it it resets the purchase state. This is used for when users buy things like coins, gold, etc, that can be purchased multiple times.
 
Upvote 0
Top