Android Tutorial Android In-App Billing v3 Tutorial

Devv

Active Member
Licensed User
Longtime User
i'am always getting this error, any ideas ?



B4X:
Sub Activity_Create(FirstTime As Boolean)
     If FirstTime Then
         Activity.LoadLayout("main") 'draw the screen GUI
        manager.Initialize("manager", key)    'intialize the in-app billing library
        manager.DebugLogging = True  
     End If
End Sub


Sub Manager_BillingSupported (Supported As Boolean, Message As String)
   Log(Supported & ", " & Message)
   Log("Subscriptions supported: " & manager.SubscriptionsSupported)

    If Supported = True Then    'check your licence key if it support billing
        ToastMessageShow("Ready",False)
      
        ' add the menu items
        Activity.AddMenuItem("5$","five")
        Activity.OpenMenu
    Else
        ToastMessageShow("Billing is not supported !",True)
    End If
End Sub

Sub five_click
   manager.RequestPayment("testsword","inapp","test") 'buy the item (you can manage items from your devlopers account "In-app Products" page)
End Sub
 

Devv

Active Member
Licensed User
Longtime User
This message means that the user is not logged in to the Google account.
i was signed in with google account, that problem was solved when i published myapp

anyway now i'm getting another eror
"the item you requested is not available for puchase"

i have the same item id in the app and the developer console (very wired)
 

JonPM

Well-Known Member
Licensed User
Longtime User
I'm still confused as to the best way to use this library when needing to make purchases (or check what's been purchased) across multiple activities. Can someone shed some light on this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Put a single BillingManager in the StarterService.

The BillingSupported event will be raised in the service.

The other events will be raised in the activity that called the relevant method.

For example if you call BillingManager.GetOwnedProducts in the Main activity then the OwnedProducts will be raised on that activity.
 

tufanv

Expert
Licensed User
Longtime User
I am also getting "Authentication is required" message altough i am using a real device and i am already loggedin to google account and a draft uploaded to google play ( i have activated the product )

edit: Publishing the app in beta mode fixed the problem


This message means that the user is not logged in to the Google account.
 
Last edited:

JonPM

Well-Known Member
Licensed User
Longtime User
Is there a min API needed for this library? I'm getting a number of users reporting their purchased IAP content gets locked when the device is offline. I'm not having the issue on any of my devices.

Is it unsafe to store a boolean in a map file in DirInternal which saves the purchase state (ie unlocked content)?
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Hello:

I am just setting up a Subscriptions In-App billing.

Is there a way I can request what Subscriptions are available?
Not what ones have been purchased but what ones are available to purchase?

When I set these up in Google I had to give a Title, Description and amount for each Subscription how can I retrieve this list?

BobVal

I read somewhere that Google does not provide a complete list of what is available.

But this will get me all the information on a product if I know the productID

But I do not see in BillingManager any call to get this information

This is what I need to do:

The getSkuDetails() method
This method returns product details for a list of product IDs. In the response Bundle sent by Google Play, the query results are stored in a String ArrayList mapped to the DETAILS_LIST key. Each String in the details list contains product details for a single product in JSON format. The fields in the JSON string with the product details are summarized in table 2.

Table 2. Description of JSON fields with product item details returned from a getSkuDetails request.

Key Description
productId The product ID for the product.
type Value must be “inapp” for an in-app product or "subs" for subscriptions.
price Formatted price of the item, including its currency sign. The price does not include tax.
price_amount_micros Price in micro-units, where 1,000,000 micro-units equal one unit of the currency. For example, if price is "€7.99", price_amount_micros is "7990000".
price_currency_code ISO 4217 currency code for price. For example, if price is specified in British pounds sterling, price_currency_code is "GBP".
title Title of the product.
description Description of the product.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
I'm reading this thread but what's not clear is to me is if this library is writing data to the app folder or not.

what will happen if you disable wifi/mobile and then open the app?

will it read the purchases from 'disk' or pretend that nothing has been purchased since it can't connect to google play?

or do we need to write purchase info ourselfs when a payment succeeded and read it back in to disable ads for example.
 

Bill Kantz

Member
Licensed User
Longtime User
Billing manager does keep a local cache of purchase information. It does refresh the cache it if and when an internet connection is available.
 

sorex

Expert
Licensed User
Longtime User
so the filewrite in Ilan's example is not really needed?
 

sorex

Expert
Licensed User
Longtime User
you're right, Bill.

Even when disconnected from the mighty net it still pulls in the purshased item from the cache.
 

luke2012

Well-Known Member
Licensed User
Longtime User
TARGET: Implement in-app subscription within the Starter Service.

I did the following test:

1) I run the following code within the Main activity. RESULT = IT WORKS
2) I run the following code within the Starter Service*. RESULT = APP CRASH (see attached log)

*All the code was copied into the Starter Service (as it is). Code within "Sub Activity_Create" was copied within the "Sub Service_Create".

@Erel this is an expected behaviour ?
There is a way to run this code within the Starter Service ?

Thanks in advance for any help!

B4X:
Sub Process_Globals
    'in-app purchase (Annual Subscription)
    Public key_InApp_Billing As String = "XXX" 'The test was made using a valid key
    Public InAppManager As BillingManager3
    Public SubName As String
    Public SubPaid As Boolean
    Public SubSupported As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)

    'in-app billing (see in-app subscription "sb001")
    InAppManager.Initialize("InAppManager", key_InApp_Billing)
    InAppManager.DebugLogging = True
    SubName = "sb001" 'subscription ID

End Sub

Sub InAppManager_OwnedProducts (Success As Boolean, purchases As Map)

   If Success Then

      Log(purchases)

     SubPaid = False
      For Each p As Purchase In purchases.Values
         Log(p.ProductId & ", Purchased? " & (p.PurchaseState = p.STATE_PURCHASED))
    
        If p.ProductId = SubName Then
            SubPaid = True
        End If
    
      Next

     Log("SubPaid = " & SubPaid)
     ToastMessageShow("SubPaid = " & SubPaid, True)

     If SubPaid = False Then InAppManager.requestPayment (SubName,"subs","")

   End If

End Sub

Sub InAppManager_BillingSupported (Supported As Boolean, Message As String)

   ToastMessageShow("Subscriptions supported: " & InAppManager.SubscriptionsSupported, True)

   If InAppManager.SubscriptionsSupported Then

        InAppManager.GetOwnedProducts
        'SubSupported = True
  
    Else
  
        'SubSupported = False
        ToastMessageShow ("Subscriptions NOT supported!", True)
  
   End If

End Sub

Sub InAppManager_PurchaseCompleted (Success As Boolean, Product As Purchase)

  If Success Then

      Log("Pagamento riuscito")
    ToastMessageShow ("Pagamento OK", False)

    InAppManager.GetOwnedProducts

  Else
    Log("Pagamento fallito!")
    ToastMessageShow ("Pagamento FALLITO", False)

    SubPaid = False
  
  End If

End Sub
 

Attachments

  • log.PNG
    47.6 KB · Views: 498
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
I'm using In-App Billing for an Annual subscription item and it works fine.
The problem is that I'm forcing the user to use a Internet connection because I'm checking the subscription payment online using Google API.

Any idea to implement a offline (annual) subscription check ? Any support by Google to do this ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…