Android Question in-app billing v3. manager.ConsumeProduct doesn't launch and returns to main

CSesma

Member
Licensed User
Longtime User
[SOLUCIONADO]
Hi,

I have a problem testing in-app billing v3.

Everything works fine, I can buy a product, I even receive a paypal charge, but when the purchase ends, the google payments window closes and the app returns to activity main. It doesn't launch the PurchaseCompleted event.

The code I use is based on the forum example, I use an exclusive activity for purchases, and I do not use a class.

Although I have seen in the forum that someone had similar problems, I have not found a solution and I'm not able to solve it.

Can somebody help me?

Thank you very much.

This is the log since the start of the purchase.


B4X:
CStarting async operation: launchPurchaseFlow
Constructing buy intent for basic, item type: inapp
requestCode = 2
** Activity (compras) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Arrived: 2, 2
Ending async operation: launchPurchaseFlow
Successful resultcode from purchase activity.
Purchase data: {"orderId":"GPA.3307-0920-55555-55555","packageName":"com.demo.demo","productId":"basic","purchaseTime":1503774458931,"purchaseState":0,"developerPayload":"to buy a basic pack","purchaseToken":"ekbmfmjjkbchm……"}
Data signature: IULavJNRGqZvDMNn….., INAPP_PURCHASE_DATA={"orderId":"GPA.330……","packageName":"com.demo.demo","productId":"basic","purchaseTime":1503774458931,"purchaseState":0,"developerPayload":"to buy a basic pack","purchaseToken":"ekbmfmjjk……"}, com.google.android.finsky.analytics.LoggingContext.KEY_ACCOUNT=user@gmail.com, com.google.android.finsky.analytics.LoggingContext.KEY_USE_DEFAULT_LOGGER=false, INAPP_DATA_SIGNATURE=IULavJN…….}]
Expected item type: inapp
Purchase signature successfully verified.
compras$ResumeMessagerun (java line: 300)
java.lang.Exception: Sub manager_purchasecompleted signature does not match expected signature.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:181)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
    at anywheresoftware.b4a.inappbilling3.BillingManager3$3.onIabPurchaseFinished(BillingManager3.java:99)
    at anywheresoftware.b4a.objects.IbHelper.handleActivityResult(IbHelper.java:497)
    at anywheresoftware.b4a.objects.IbHelper$2.ResultArrived(IbHelper.java:382)
    at anywheresoftware.b4a.BA$4.run(BA.java:523)
    at anywheresoftware.b4a.BA.setActivityPaused(BA.java:408)
    at com.demo.demo.compras$ResumeMessage.run(compras.java:300)
    at android.os.Handler.handleCallback(Handler.java:761)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:6523)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
** Service (starter) Create **
** Service (starter) Start **
 
Last edited:

Computersmith64

Well-Known Member
Licensed User
Longtime User
Can you post your code? From the look of your log, there seems to be a problem with the purchasecompleted sub signature. I have an app that uses IAP with no problems, so if you post your code I can compare it to mine & see if I can spot the issue.

- Colin.
 
Upvote 0

CSesma

Member
Licensed User
Longtime User
Hi Colin,

This is the code:

B4X:
Sub Process_Globals
    'Purchases
    Dim manager As BillingManager3 
    Private key As String = "MIIBIjAN...."

End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("L_compras")
   
    'purchase
    If FirstTime Then
        manager.Initialize("manager", key)
        manager.DebugLogging = True
    End If
   
End Sub

Sub Manager_BillingSupported (Supported As Boolean, Message As String)
   
    manager.GetOwnedProducts
   
End Sub

Sub manager_OwnedProducts (Success As Boolean, mapPurchases As Map)
           
    If Success Then
        For Each p As Purchase In mapPurchases.Values
            If p.ProductId = "basic" And p.PurchaseState = p.STATE_PURCHASED Then
                manager.ConsumeProduct(mapPurchases.Get("basic"))
            End If
        Next
    End If
   
End Sub


Sub bt_compra1_click
   
    Dim ProdId As String
    ProdId = "basic"
    manager.requestpayment(ProdId, "inapp", "aaaa basic pack")
   
End Sub

Sub manager_PurchaseCompleted(success As Boolean, mapPurchases As Map)
    If success = True Then
        If mapPurchases.ContainsKey("basic") Then
            Aplica_compra("basic")
            manager.ConsumeProduct(mapPurchases.Get("basic"))
        End If
    End If

End Sub

Sub Aplica_compra(sProducto As String)
   
    If sProducto = "basic" Then
        Main.nCreditos = Main.nCreditos + 1000
        Main.mapINI.Put("Creditos", Main.nCreditos)
    End If
       
End Sub

Sub bt_volver6_click
    Activity.Finish
End Sub

Thank you,
Carmen
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
OK - there's your problem. The PurchaseCompleted sub has a signature of:
B4X:
Sub manager_PurchaseCompleted (Success As Boolean, Product As Purchase) ' not Map

So you would need to change your code to:

B4X:
Sub manager_PurchaseCompleted(Success As Boolean, Product As Purchase)
    If Success Then
        If Product.ProductId = "basic" Then
            Aplica_compra("basic")
            manager.ConsumeProduct(Product)
        EndIf
    EndIf
End Sub

Hint: If you're not sure what the sub signature should be you can have IDE to insert the sub signature in your code for you. Type "Sub" then hit space, then tab & select the object you're wanting the signature for (in this case you would find BillingManager3 in the list). Click on the object & a list of available events will come up for you to select from.

- Colin.
 
Last edited:
Upvote 0

CSesma

Member
Licensed User
Longtime User
Thank you Colin.

After all this time programming with B4A and had no idea that I could know the sub signature as well.
You have helped me a lot.
Thanks again.

Carmen
 
Upvote 0
Top