B4A Library GPBpurchases - Google Play Billing purchases library

This library makes shopping on the Play Store very easy. It wraps the entire billing functionality. Just a few settings and the user can shop items. All necessary data is downloaded from the Google Play Console. Therefore, it is very important to choose the correct name and description of the purchased item in GPC. In-app items appear first, then subscriptions. Subscriptions are displayed including phases. Behavior can be set in the Designer, including colors.
After a successful purchase, the PurchaseCompleted event is raised, where you can set the user's permissions.
The principle of using the library is in the sample application.

Screenshot.png


GPBpurchases_JE
Author: Jerryk
Version: 1.1

Add to the manifest editor:

CreateResourceFromFile(Macro GooglePlayBilling.GooglePlayBilling)

Dependences:
Google Play Billing library - GPBilling_JE . Download and add to Additional library folder.

Events:
  • PurchaseCompleted (p As Purchase)
The event will be triggered by pressing the Buy or Subscribe button and Return.IsSuccess = True. The passed parameter is p As Purchase.​
  • PurchaseError (Result As BillingResult)
The event will be triggered by pressing the Buy or Subscribe button and Return.IsSuccess = False. The parameter passed is Result As BillingResult.​
  • BillingError (Result As BillingResult)
The event will be triggered by pressing the Buy or Subscribe button and event PurchaseCompleted not be raised. The parameter passed is Error As Int.​

Functions:
  • Init (LICENSE_KEY As String)
Set the Licensing Public Key from Google Play Console.​
  • SetSku (stype As String, linapp As List, lsubs As List)
Sets the SKUs to be displayed by the ShowSku function​
stype: INAPP - show Inapp only, SUBS - show Subs only, ALL - show all SKUs​
linapp - list of INAPP id's, lsubs - list of SUBS id's​
  • ShowSku
show SKUs in CustomListView​
  • ErrorText (error As Int) As String
convert error to string based on strings.xml​
  • ConsumeProduct (stype As String, sku As String)
consume product: stype - INAPP, SUBS, sku - SKU id​

Properties:
  • HidePurchasedInapp As Boolean
Sets or gets whether a purchased Inapp item should be displayed.​
  • ShowTimeOfPurchase As Boolean
Sets or gets whether to display the purchase time.​
  • HideInappDescription As Boolean
Sets or gets whether to display Inapp description.​
  • ExpandedInappDescription As Boolean
Sets or gets whether the Inapp description should be displayed expanded or collapsed.​
  • HidePurchasedSubs As Boolean
Sets or gets whether a purchased Subs item should be displayed.​
  • ShowUnsubscribeButton As Boolean
Sets or gets whether to display the Unsubscribe Button.​
  • HideSubsDescription As Boolean
Sets or gets whether to display Subs description.​
  • ExpandedSubsDescription As Boolean
Sets or gets whether the Subs description should be displayed expanded or collapsed.​

Localization:
You can localize the library. Copy the strings.xml file from the value folder to the appropriate language-specific value-xx folder. Mark as writable, translate, mark as read-only.

How to test the example on your Google Play Console?
  • Change in >Build Configurations>Package to match your application.
  • In the example, enter your IDs for LICENSE_KEY and SKUs
  • catch the PurchaseCompleted event and set the user's permissions
  • enjoy !!!
B4X:
GPPurchases1.Init(LICENSE_KEY)
...

Private Sub B4XPage_Appear
    Select Case skutype
        Case "ALL"   'to show all skus to purchase
            lSKU_inapp.Clear
            lSKU_inapp.Add("pro.gpbtest2")   'add INAPP ID
            lSKU_inapp.Add("pro.gpbtest3")
            lSKU_subs.Clear
            lSKU_subs.Add("silver.gpbtest")    'add SUBS ID
            lSKU_subs.Add("gold.gpbtest")
        Case "INAPP"   'to show only one inapp sku to purchase
            lSKU_inapp.Clear
            lSKU_inapp.Add(sku)
        Case "SUBS"   'to show only one subs sku to purchase
            lSKU_subs.Clear
            lSKU_subs.Add(sku)
    End Select

    GPPurchases1.SetSku(skutype, lSKU_inapp, lSKU_subs)
    GPPurchases1.ShowSku
End Sub
Please donate something for the cafe, I spent a lot of time on this. :)
 

Attachments

  • GPBpurchases_JE.b4xlib
    13.6 KB · Views: 34
  • GPBpurchasesEx.zip
    15.8 KB · Views: 27
Last edited:
Top