AppcoinsBillingClient

The AppcoinsBillingClient is the main interface for handling in-app billing in your application. It provides a straightforward way to perform operations like querying purchases, retrieving product details, consuming purchases, managing billing flows and performing app related operations like app updates.

To use the AppcoinsBillingClient, create a single instance in your application. Start by initializing it with the startConnection method, passing a listener to track the connection status. Once the connection is established, you can safely call methods to handle in-app billing tasks.

Call endConnection to release resources and prevent memory leaks once your application is being terminated. For best practices, instantiate the client in your Application's onCreate method and ensure cleanup in onDestroy.

The AppcoinsBillingClient supports both synchronous and asynchronous operations, offering flexibility to execute tasks on the UI thread or background threads. Take special attention to the methods that require to be executed in the background threads to avoid ANRs.

Always check the readiness of the client using the isReady method before performing any operations related to the billing service to avoid inconsistent behaviors.

By following these guidelines, you can ensure a smooth and efficient in-app billing integration for your application.


Public Methods


consumeAsync

void consumeAsync(String token, ConsumeResponseListener consumeResponseListener)

Consumes a purchase, finalizing the transaction. Unconsumed purchases may lead to refunds.

Parameters

NameTypeDescription
tokenStringThe token identifying the purchase to be consumed.
consumeResponseListenerConsumeResponseListenerListener to receive the status of the consume operation.

endConnection

void endConnection()

Terminates the connection to the billing client.


getReferralDeeplink

ReferralDeeplink getReferralDeeplink()

Retrieves a deeplink to the correct store from which the application was installed.

This method must not be called on the Main/UI Thread.

Returns

A ReferralDeeplink with the details of the request result.


isAppUpdateAvailable

boolean isAppUpdateAvailable()

Checks whether an update is available for the application.

Returns

Boolean value which specifies if there is an update available or not.


isReady

boolean isReady()

Checks whether the billing client is ready to process requests.

Returns

Boolean value which specifies if the client is ready or not.


launchAppUpdateDialog

void launchAppUpdateDialog(Context context)

Displays a dialog prompting the user to update the application if there is an update available. If the user agrees, the store page from where the application was installed is launched.

Parameters

NameTypeDescription
contextContextThe application context.

launchAppUpdateStore

void launchAppUpdateStore(Context context)

Opens the store from where the application was installed, navigating to the application's page.

Parameters

NameTypeDescription
contextContextThe application context.

launchBillingFlow

int launchBillingFlow(Activity activity, BillingFlowParams billingFlowParams)

Launches the billing flow for a specified SKU.

This method must not be called on the Main/UI Thread.

Returns

An integer value of the ResponseCode.

Parameters
NameTypeDescription
activityActivityThe activity used to launch the billing flow.
billingFlowParamsBillingFlowParamsParameters for the billing flow.

onActivityResult (Deprecated)

boolean onActivityResult(int requestCode, int resultCode, Intent data)

This method is deprecated and no longer required in the billing integration.

Processes the result of a previously launched activity.

Returns

Boolean value which specifies if the result was processed successfully or not.

Parameters

NameTypeDescription
requestCodeIntThe request code from onActivityResult.
resultCodeIntThe result code from onActivityResult.
dataIntentThe intent data from onActivityResult.

queryPurchases

PurchasesResult queryPurchases(String skuType)

Retrieves the purchases associated with the user based on the specified SKU type.

Returns

A PurchasesResult containing the query results.

Parameters

NameTypeDescription
skuTypeStringThe type of purchase to query. Must be a valid SkuType .

querySkuDetailsAsync

void querySkuDetailsAsync( SkuDetailsParams skuDetailsParams, SkuDetailsResponseListener onSkuDetailsResponseListener )

Fetches details of SKUs available in the application asynchronously.

Parameters

NameTypeDescription
skuDetailsParamsSkuDetailsParamsParameters specifying the SKUs to query.
onSkuDetailsResponseListenerSkuDetailsResponseListenerListener for receiving the SKU details.

startConnection

void startConnection(AppCoinsBillingStateListener listener)

Initializes a connection to the billing client.

Parameters

NameTypeDescription
listenerAppCoinsBillingStateListenerA listener to monitor connection state changes.