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 5.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!
You will not be able to use any other method till connection is established.
Query Product Details:
After you have established a connection to Google Play, you are ready to query for your available products and display them to your users.
Querying for product details is an important step before displaying your products to your users, as it returns localized product information. For subscriptions, ensure your product display follows all Play policies.
This method needs params productId
and skuType
.
If the product is successfully queried, then it will trigger following event. productDetails
is the most important argument and it is used to launch the purchase flow.
If the product is failed to query, then it will trigger following event with response code.
Launch The Project Flow:
To start a purchase request from your app, you should use LaunchPurchaseFlow
method which needs params like productDetails
, offerToken
, isOfferPersonalized
and skuType
.
productDetails
is same object you get from QueryProductDetails
block.
offerToken
is not compulsory. You can pass an empty string. However, for subscription, you can use GetOfferToken
to get offer token.
isOfferPersonalized
accepts true or false. If your app can be distributed to users in the European Union, this method to disclose to users that an item’s price was personalized using automated decision-making.
If the project flow is successfully launched, then it will trigger PurchaseFlowLaunched
event block.
If the project flow is failed to launch then it will trigger PurchaseFlowFailedToLaunch
block with a response code.
if the item is sucessfully purchased then an event GotPurchase
is triggered with purchase
object.
if the purchase is cancelled by user, then an event PurchaseCancelled
is triggered.
If the purchase is failed by any other reason, then an event PurchaseFailed
is triggered.
A successful purchase also generates a purchase token, which is a unique identifier that represents the user and the product ID for the in-app product they purchased. Your apps can store the purchase token locally, though Google recommend passing the token to your secure backend server where you can then verify the purchase and protect against fraud. You can get purchase token as well as other purchase details from GetPurchaseDetails
block.
On Successfull, it will trigger following event GotPurchaseDetails
.
Processing Purchase:
Once a user completes a purchase, your app then needs to process that purchase. your app is ready to grant entitlement to the user. The purchase can be handled as consumable or non-consumable. This acknowledgement communicates to Google Play that you have granted entitlement for the purchase.
NOTE: If you do not acknowledge a purchase within three days, the user automatically receives a refund, and Google Play revokes the purchase.
The process to grant entitlement and acknowledge the purchase depends on whether the purchase is a non-consumable, a consumable, or a subscription.
For consumables, the HandleConsumable
method fulfills the acknowledgement requirement and indicates that your app has granted entitlement to the user. This method also enables your app to make the one-time product available for purchase again.
To acknowledge non-consumable purchases, HandleNonConsumable
method can be used. Also, when you enable the AutoAcknowledge
block, it will automatically handle the purchase made as Non-Consumable
.
purchase
is same object that you get from GotPurchase
block.
On successfully handled the purchase, it will trigger PurchaseSuccess
event.
If purchase is failed to handle, then it will trigger PurchaseFailed
event with response code.
Query Purchases:
You can get all active subscriptions and non-consumed one-time purchases using QueryPurchases block.
If successfull then it will return list of Purchases on OnQueryPurchasesResponse
event.
If failed, then it will trigger OnQueryPurchasesFailed
event with response code.
Fetch Purchase History:
GetPurchasesHistory
block will returns the most recent purchase made by the user for each product, even if that purchase is expired, canceled, or consumed.
On successful, it will trigger GotPurchasesHistory
with list of purchases history.
If failed, then it will trigger FailedToGetPurchasesHistory
with an error message.
Response Code & Its Meaning:
SERVICE_TIMEOUT = -3;
FEATURE_NOT_SUPPORTED = -2;
SERVICE_DISCONNECTED = -1;
OK = 0;
USER_CANCELED = 1;
SERVICE_UNAVAILABLE = 2;
BILLING_UNAVAILABLE = 3;
ITEM_UNAVAILABLE = 4;
DEVELOPER_ERROR = 5;
ERROR = 6;
ITEM_ALREADY_OWNED = 7;
ITEM_NOT_OWNED = 8;
Download Latest Version From Github :
com.oseamiya.inappbilling
This extension is open sourced here: