InAppBilling Extension
An Extension to enable service to sell digital product and contents in your android application.
This extension will help you to use Google Play's billing system in your application. It uses latest billing library 4.0.0.
Start Connection
First of all, you should establish a connection to Google Play. To connect to Google Play, you should use this method:
If billing client is ready and connection is established then it will trigger BillingClientReady
event.
Else if connection is failed / Billing Service is disconnected then it will trigger BillingServiceDisconnect
event. You can try to restart the connection by calling StartConnection
method again!
Launch Purchase Flow
To start a purchase request from your app, you should call LaunchPurchaseFlow
method. It needs productId
as params aswell as skuType can either be InApp
or Subs
.
If application fails to launch PurchaseFlow then it will trigger FailedToLaunchPurchaseFlow
with a response code.
If it is successfully purchased then it will trigger GotPurchase
event and you will get Purchase
object in the event block.
If the product or subscription is cancelled by the user then it will trigger PurchaseCancelled
Event.
If the purchase is failed then it will trigger PurchaseFailed
event.
Processing Purchase
Once a user completes the purchase, your app needs to process the purchases as It's possible that your app might not be aware of all the purchases a user has made. You can find more information & scenarios where your app could lose track or be unaware of purchases from here.
You can either process the purchase either handling purchase as consumable or non-consumable. You can find more about the consumable, and non-consumable purchases from here.
However you don't need to process the purchase manually if you enabled AutoAcknowledge
method as purchase is automatically handled as Non-Consumable ie acknowledged in this case.
To handle purchase as consumable,
To handle purchase as non-consumable,
Purchase
is same purchase you get from GetPurchase
block in LaunchProjectFlow .
If purchase was in pending state then it will trigger PurchaseStatePending
event,
If purchase was in unspecified state then it will trigger PurchaseStateUnspecified
event.
If the purchase is successfully handled then it will trigger PurchaseSuccess
Event,
If the handeling purchase is failed then it will again trigger PurchaseFailed
event.
Getting Purchase Details
You can get the details of a Purchase using this block :
Purchase
is same purchase you get from GetPurchase
block in LaunchProjectFlow .
If successful then it will trigger GotPurchaseDetails
with orderId
, isAcknowledged
, isAutoRenewing
, purchasedTime
and json
.
.
Getting Product/Subs Details
To get the details of either subscirption or product, you can use this block :
If success then it will trigger GotDetails
event with title
, description
, price
and originalJson
.
Getting Purchases History
You can get the history of purchase using this block :
After getting Purchase History successfully then it will trigger GotPurchaseHistory
event with list of original jsons.
Other blocks :
To check if purchase is acknowledged or not. It will return boolean.
To check if GooglePlay in your device supports subscription or not.
To check if billing client is ready or not.
It returns Subscription skuType
It returns InApp skuType
If Auto Acknowledge is enabled to true then purchase is automatically handled as Non-Consumable & so you doesn't need to handle it manually.
If Test is enabled then product Id everywhere is used as
android.test.purchased
. This product id can be used without publishing application to playstore.
Issue In Companion:
LaunchPurchaseFlow doesn't seem to work on companion and always trigger FailedToLaunchPurchaseFlow
event with response code of -1 which indicates service is disconnected, Refrence . Its because there is no required manifest in companion app. Service work after compiling as application.
Downloads :
Download Test Aia : InApp.aia (135.1 KB)
Download Latest Version From Github :
com.oseamiya.inappbilling
Always thankful to @Shreyash for Rush !!