B4A Library [B4A] GPBilling

This library wraps the GooglePlayBilling base library. It returns the results in structures as they are built in the Google accounting system.
The library does not display any messages; it only returns results: BillingResult, ProductResult, or PurchasedResult. It also generates the events described below.
When a ProductResult is returned, first read the ResponseCode value. If equal to CODE_OK, load the data from the list; otherwise, handle an error.
The principle of using the library is in the example application.

GPBilling_JE
Author: Jerryk
Version: 1.0

Add to the manifest editor:

CreateResourceFromFile(Macro GooglePlayBilling.GooglePlayBilling)​

Types:
to store in-app product
Type InAppProduct (
ProductId As String _​
ProductType As String _​
Title As String _​
Name As String _​
Description As String _​
PriceAmountMicros As String _​
PriceCurrencyCode As String _​
FormattedPrice As String )​

to store subscription product
Type SubsProduct (
ProductId As String _​
ProductType As String _​
Title As String _​
Name As String _​
Description As String _​
SubscriptionOfferDetails As List )​

to store SubscriptionOfferDetails
Type SubsOffer (
BasePlanId As String _​
OfferId As String _​
OfferToken As String _​
OfferTags As List _​
PricingPhaseList As List )​

to store PricingPhases
Type PricingPhase (
BillingCycleCount As String _​
BillingPeriod As String _​
FormattedPrice As String _​
PriceAmountMicros As String _​
PriceCurrencyCode As String _​
RecurrenceMode As String )​

to store returned result
Type ProductResult (
ResponseCode As Int _​
ProductsList As List)​

to store purchased items
Type PurchasedResult (
ItemPurchased As Boolean _​
ProductPurchased As Purchase)​

Events:
  • PurchaseCompleted (p As Purchase)
The event will be raised when the PurchaseInAppProducts or PurchaseSubsProducts function is called with a result of IsSuccess = True for each SKU separately. The passed parameter is p As Purchase.​
  • PurchaseError (Result As BillingResult)
The event will be raised when the PurchaseInAppProducts or PurchaseSubsProducts function is called with a result of IsSuccess = False. The parameter passed is Result As BillingResult.​

Functions:
  • Initialize (Callback As Object, EventName As String, AppPublicKey As String)
AppPublicKey = Licensing Public Key from Google Play Console​
  • GetInAppProducts (lSKUs As List) As ResumableSub
return ProductResult​
getss all available INAPP products (including disabled!!!!)
  • GetSubscriptions (lSKUs As List) As ResumableSub
return ProductResult​
getss all available SUBS products
  • PurchaseInAppProducts (lSKUs As List) As ResumableSub
return BillingResult​
purchase INAPP product
  • PurchaseSubsProducts (lSKUs As List, offertoken As String) As ResumableSub
return BillingResult​
purchase SUBS product
  • IsPurchased (skuType As String, sku As String) As ResumableSub
return PurchasedResult​
if PurchasedResult.ItemPurchased is True Sku is purchased
  • GetPurchasedProducts As ResumableSub
return ProductResult​
gets list of all purchased products
  • ConsumeProducts (skuType As String, sku As String) As ResumableSub
return BillingResult​
consume product
  • AcknowledgeProducts (p As Purchase) As ResumableSub
return BillingResult​
acknowledge product VerifyPurchase is called before acknowledging
  • ReturnResponseMessage (Result As Int) As String
return error string responded to error code defined in BillingResult​
Added two codes:​
CODE_NO_INAPP - return if no in-app SKU in Google Play Console​
CODE_NO_SUBSCRIPTION - return if no subs SKU in Google Play Console​

Properties:
  • message_xxxx (Message As String)
It is possible to localize a text message for each error.​
How to test the example on your Google Play Console?
  • Change in >Build Configurations>Package to match your application.
  • In the example, enter your ID for LICENSE_KEY and SKUs
B4X:
    LICENSE_KEY = "MIIBIjAN......................"
    lSKU_INAPP.Add("pro.gpbtest2")
    lSKU_INAPP.Add("pro.gpbtest3")
    lSKU_SUBS.Add("silver.gpbtest")
    lSKU_SUBS.Add("gold.gpbtest")

    gpb.Initialize(Me, "gpb", LICENSE_KEY)
 

Attachments

  • GPBilling_JE.zip
    26.8 KB · Views: 61
  • GPBlibExample.zip
    3.9 KB · Views: 63
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…