Android Question In-app Purchases ( requires to buy the app again )

MarcoRome

Expert
Licensed User
Longtime User
Hi all, i have this code:

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 = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8Axxxxxxxx......"
    Dim Productid1 As String
    Dim Producttype As String
    Dim DeveloperPayload As String
    DeveloperPayload="Program" ' ---> Name of my App "
    Producttype="inapp" ' ---> this is an input
    Productid1 = "program_price" ' ---> this is an input I it is the product id i defined in the store **** SEE STEP 4

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    If FirstTime = True 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

'*** PER APP A PAGAMENTO
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))
            If p.ProductId = "program_price" And p.PurchaseState = p.STATE_PURCHASED Then
                Starter.comprato = "1"
            End If
        Next
      
        If Starter.comprato <> "1" Then
            Starter.comprato = "0"
                    'Messaggio acquista
                    Dim result As Int
                    result = Msgbox2("Questa è una versione di prova.", "Informazione" ,"Si Grazie", "", "Non Ancora", Null)
                    If result = DialogResponse.Positive Then
                        manager.RequestPayment(Productid1, Producttype, DeveloperPayload)
                    End If
            '..................
        End If
  
    End If
      
      

End Sub


Sub Manager_PurchaseCompleted(Success As Boolean, Product As Purchase)
    If Success Then
        manager.ConsumeProduct(Product) '******************THIS IS IMPORTANT FOR App-In consumable purchases
        If Product.Productid = "program_price" Then
            'Acquisto effettuato quindi vado avanti
            Starter.comprato = "1"
        End If
    End If
End Sub
'*** FINE APP A PAGAMENTO


Everything works, the problem that i have and once the app has been purchased and the transaction has been successful, if i go out and return, requires to buy the app again.

This is log after purchase ( when i go out app and return )
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (act_main2) Create, isFirst = true **
** Activity (act_main2) Resume **
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for com.devilapp.xxx
Subscriptions AVAILABLE.
true, Setup successful. (response: 0:OK)
Subscriptions supported: true
Starting async operation: refresh inventory
Querying owned items, item type: inapp
Package name: com.devilapp.xxx
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: com.devilapp.xxx
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
true
(MyMap) {}
** Activity (act_main2) Pause, UserClosed = false **
** Activity (act_main2) Resume **
** Activity (act_main2) Pause, UserClosed = false **

B4X:
Log(purchases)
        For Each p As Purchase In purchases.Values
            Log(p.ProductId & ", Purchased? " & (p.PurchaseState = p.STATE_PURCHASED))
            If p.ProductId = "program_price" And p.PurchaseState = p.STATE_PURCHASED Then
                Starter.comprato = "1"
            End If
        Next

The strain thing is that Log(Purchase) is NULL as you see in log file: (MyMap) {}

Any idea ?
Thank you
Marco
 
Last edited:
Top