Android Question Check Subscription Status In App Billing V3

tucano2000

Active Member
Licensed User
In App Billing V3. How do I check the status of a subscription previously purchased every time I start an application ?
 

tucano2000

Active Member
Licensed User
You should call manager.GetOwnedProducts and handle the OwnedProducts event.
Erel I did this on a device with another account in playstore . Always returns Success = true but purchases size index = 0. No items . I need to know which item , date, etc.
 

tucano2000

Active Member
Licensed User
I got. The problem was that the test device had two accounts. I deleted one and only let the test account that worked. Purchases Size = 1 and also got the key related to the product name.

I'm trying to figure out the purchase of a subscription to validate the use of certain application functions.

In subscription the state is returning 0. But I made a refund of the amount and canceled. Should not return another value?

Returned logs:

manager_OwnedProducts Success = true
purchases size = 1
myapp_assinatura
Purchase(type:subs): myapp_assinatura, state = 0

The reason would be this:

When the user cancels a subscription, Google Play does not offer a refund for the current billing cycle. Instead, it allows the user to have access to the cancelled subscription until the end of the current billing cycle, at which time it terminates the subscription. For example, if a user purchases a monthly subscription and cancels it on the 15th day of the cycle, Google Play will consider the subscription valid until the end of the 30th day (or other day, depending on the month).
See my code:

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

Sub Globals


    Private Button1 As Button
    Private Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("teste")
  If FirstTime Then
      manager.Initialize("manager", key)
      manager.DebugLogging = False
  End If
End Sub

Sub Manager_BillingSupported (Supported As Boolean, Message As String)
  Log(Supported & ", " & Message)
  Log("Subscriptions supported: " & manager.SubscriptionsSupported)
  If Supported Then
          'manager.GetOwnedProducts 'requisita os produtos comprados e dispara o evento com o mesmo nome
  End If
End Sub
Sub Button1_Click
    manager.RequestPayment("myapp_assinatura", "subs", "MyApp assinatura_ok")
    'manager.RequestPayment("android.test.purchased", "inapp", "Infranote_assinatura_ok")
End Sub
Sub Activity_Click
   '1manager.RequestPayment("android.test.purchased", "subs", "extra data")
   'manager.GetOwnedProducts
   'Manager.RequestPayment(Activity, "android.test.purchased", "extra data")
End Sub

Public Sub manager_ProductConsumed (Success As Boolean, Product As Purchase)
        Log("teste")
        Log("===== LOG DO APLICATIVO ==================================================")
        Log("Product.DeveloperPayload = " & Product.DeveloperPayload)
        Log("Product.ItemType = " & Product.ItemType)
        Log("Product.ProductId = " & Product.ProductId)
        Log("Product.PurchaseState = " & Product.PurchaseState)
        Log("Product.PurchaseTime = " & Product.PurchaseTime)
        Log("Product.toString = " & Product.toString)
        Log("==========================================================================")
End Sub
Public Sub manager_PurchaseCompleted (Success As Boolean, Product As Purchase)

    'manager.ConsumeProduct(Product)
    'Return
      Log(Success)
    If Success = True Then
        'Select Product.Productid
            'Case "TestXX"
                'qui inserisco cosa fare nel caso la transazione si andata a buon fine
                ' Faccio andare nella routine esempio sub lancia dove elimino la pubblicità
        Log("===== LOG DO APLICATIVO ==================================================")
        Log("Product.DeveloperPayload = " & Product.DeveloperPayload)
        Log("Product.ItemType = " & Product.ItemType)
        Log("Product.ProductId = " & Product.ProductId)
        Log("Product.PurchaseState = " & Product.PurchaseState)
        Log("Product.PurchaseTime = " & Product.PurchaseTime)
        Log("Product.toString = " & Product.toString)
        Dim r As Reflector
        r.Target = Product
        Dim token As String = r.GetField("mToken")
        Log("Product.Token = " & token)
        Log("==========================================================================")
                ToastMessageShow("PLAY STORE OK Buy ;);)))))!!", False)
        'End Select
    Else

        ToastMessageShow("PLAY STORE Error Buy", False)
        'Product.PurchaseState
        'Log("===== LOG DO APLICATIVO ==================================================")
        'Log("Product.DeveloperPayload = " & Product.DeveloperPayload)
        'Log("Product.ItemType = " & Product.ItemType)
        'Log("Product.ProductId = " & Product.ProductId)
        'Log("Product.PurchaseState = " & Product.PurchaseState)
        'Log("Product.PurchaseTime = " & Product.PurchaseTime)
        'Log("Product.toString = " & Product.toString)
        Log("==========================================================================")
    End If
End Sub

Sub manager_OwnedProducts (Success As Boolean, purchases As Map)
    Log("manager_OwnedProducts Success = " & Success)
    Log("purchases size = " & purchases.Size)
If Success  Then
    For i=0 To purchases.Size-1  
          Log(purchases.GetKeyAt(i)) 'Get name of Product
        Log(purchases.GetValueAt(i)) 'Get State of signature
    Next
End If
End Sub


Sub Button2_Click
    manager.GetOwnedProducts 'requisita os produtos comprados e dispara o evento com o mesmo nome
End Sub
 
Last edited:
Top