# PurchaseClient

```
public abstract class BillingClient extends Object
```

```
java.lang.Object
    ↳ com.gaa.sdk.iap.PurchaseClient
```

\


It is a default interface for communication between library and user application codes.

All methods are processed as asynchronous ones and should be called up in the UI thread, and all callbacks are returned to the UI thread.

To set up connection after instantiating this class, call up the startConnection([PurchaseClientStateListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/PurchaseClientStateListener) method, and once the setup completes, you could receive notifications through listener.

\


| `class` `YourPurchaseManager implements` `PurchaseClientStateListener {     private` `PurchaseClient mPurchaseClient;` `public` `YourPurchaseManager() {         mPurchaseClient = PurchaseClient.newBuilder(activity)                     .setBase64PublicKey(/* your public key */)                     .setListener(this)                     .build();     } ... }` |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

In general, after the setup completes, call up the purchase history check and in-app product details. Refer to queryPurchasesAsync(String, [PurchasesListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/PurchasesListener)) and queryProductDetailsAsync([ProductDetailsParams](https://wiki.onestorecorp.com/display/IAPGOOGLE/ProductDetailsParams), [ProductDetailsListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/ProductDetailsListener)).

Never forget to call endConnection() when you exit the application after completing all tasks with this object. All the connections with billing modules must be disconnected and resources must be removed. The recommended location is Activity.onDestroy().

To check the detailed logs of library, input android.util.Log.VERBOSE in android.util.Log.VERBOSE and then call them up.

Logger.setLogLevel(int) MUST be removed before launching a release version of an application.

\


## Summary <a href="#purchaseclient-summary" id="purchaseclient-summary"></a>

***

| Nested classes |                                                                                                                                                                                                 |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| @interface     | [PurchaseClient.ResponseCode](https://dev.onestore.co.kr/wiki/en/doc/purchaseclient-responsecode-5833457.html)                                                                                  |
| @interface     | [PurchaseClient.ProductType](https://dev.onestore.co.kr/wiki/en/doc/purchaseclient-producttype-5833452.html)                                                                                    |
| @interface     | [PurchaseClient.RecurringAction](https://dev.onestore.co.kr/wiki/en/doc/purchaseclient-recurringaction-5833456.html)                                                                            |
| class          | <p><a href="https://dev.onestore.co.kr/wiki/en/doc/purchaseclient-builder-5833441.html">PurchaseClient.Builder</a></p><p>It is a builder for easy creation of the PurchaseClient instances.</p> |

## Public methods <a href="#purchaseclient-publicmethods" id="purchaseclient-publicmethods"></a>

***

### newBuilder <a href="#purchaseclient-newbuilder" id="purchaseclient-newbuilder"></a>

```
@UiThread
public static  newBuilder(Context context)
```

It generates a builder for creating the PurchaseClient instances.

| **Parameters:**                                                                                      |                                                                                 |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| context                                                                                              | It is used for the connection with billing modules by using applicationContext. |
| Returns:                                                                                             |                                                                                 |
| [PurchaseClient.Builder](https://dev.onestore.co.kr/wiki/en/doc/purchaseclient-builder-5833441.html) |                                                                                 |

### startConnection <a href="#purchaseclient-startconnection" id="purchaseclient-startconnection"></a>

```
@UiThread
public abstract void startConnection( listener)
```

It initiates the PurchaseClient setup process asynchronously.

It receives responses through [PurchaseClientStateListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/PurchaseClientStateListener) once completed.

| **Parameters:** |                                                                                                 |
| --------------- | ----------------------------------------------------------------------------------------------- |
| listener        | It receives a response when the PurchaseClient setup and payment module connection is complete. |

### endConnection <a href="#purchaseclient-endconnection" id="purchaseclient-endconnection"></a>

```
@UiThread
public abstract void endConnection()
```

It cuts the connection with billing modules and removes the resources retained by PurchaseClient.

### launchUpdateOrInstallFlow <a href="#purchaseclient-launchupdateorinstallflow" id="purchaseclient-launchupdateorinstallflow"></a>

```
@UiThread
public abstract void launchUpdateOrInstallFlow(Activity activity,  listener)
```

When PurchaseClient.ResponseCode.RESULT\_NEED\_UPDATE occurs, the value of IapResult.getResponseCode() should be called for the update or installation of billing modules.

| **Parameters:** |                                                                                            |
| --------------- | ------------------------------------------------------------------------------------------ |
| activity        | Activity: refer to the activity to understand the update and flow of billing modules.      |
| listener        | [IapResultListener](https://dev.onestore.co.kr/wiki/en/doc/iapresultlistener-5833434.html) |

### launchPurchaseFlow <a href="#purchaseclient-launchpurchaseflow" id="purchaseclient-launchpurchaseflow"></a>

```
@UiThread
public abstract  launchPurchaseFlow(Activity activity,  params)
```

It starts purchasing in-app products.

The purchase screen will be displayed, and the result will be received through PurchasesUpdatedListener, which has been specified when initializing PurchaseClient.

| **Parameters:**      |                                                                                              |
| -------------------- | -------------------------------------------------------------------------------------------- |
| activity             | Activity: refer to the activity to understand the billing flow.                              |
| params               | [PurchaseFlowParams](https://dev.onestore.co.kr/wiki/en/doc/purchaseflowparams-5833439.html) |
| **Returns:**         |                                                                                              |
| <p>IapResult<br></p> |                                                                                              |

### consumeAsync <a href="#purchaseclient-consumeasync" id="purchaseclient-consumeasync"></a>

```
@UiThread
public abstract void consumeAsync( params,  listener)
```

It consumes purchased in-app products.\


Consumption is available only for the in-app product you own, and if the in-app has already been consumed, it is required to be purchased again.

\


When it comes to API v6 and later, if ‘consume’ or ‘acknowledge’ is not made with 3 days after purchase, refund will be made.

| **Parameters:** |                                                                                    |
| --------------- | ---------------------------------------------------------------------------------- |
| params          | [ConsumeParams](https://dev.onestore.co.kr/wiki/en/doc/consumeparams-5833449.html) |
| listener        | It receives the result of the ConsumeListener consumption work.                    |

### acknowledgeAsync <a href="#purchaseclient-acknowledgeasync" id="purchaseclient-acknowledgeasync"></a>

```
@UiThread
public abstract void acknowledgeAsync( acknowledgeParams,  listener)
```

It checks purchased in-app products.

Consumption is available only for the in-app product you own, and if the in-app you checked is not consumed, it cannot be purchased again.

It can be applied to both Managed product and Monthly auto-renewal product. In particular, Managed product can be used as ‘Non-renewable’ in which the purchase is acknowledged and then the in-app is consumed after a certain time.

When it comes to API v6 and later, if ‘consume’ or ‘acknowledge’ is not made with 3 days after purchase, refund will be made.

| **Parameters:**   |                                                                                                                                      |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| acknowledgeParams | [AcknowledgeParams](https://dev.onestore.co.kr/wiki/en/doc/acknowledgeparams-5833443.html)                                           |
| listener          | It receives the result of the [AcknowledgeListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/AcknowledgeListener) check work. |

### queryPurchasesAsync <a href="#purchaseclient-querypurchasesasync" id="purchaseclient-querypurchasesasync"></a>

```
@UiThread
public abstract void queryPurchasesAsync(String productType,  listener)
```

It imports the purchase information of all in-app products purchased on apps.

| **Parameters:** |                                                                                                                                          |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| productType     | Specify the type of the [PurchaseClient.ProductType](https://wiki.onestorecorp.com/display/IAPGOOGLE/PurchaseClient.ProductType) in-app. |
| listener        | It receives the result of the [PurchasesListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/PurchasesListener) purchase history.   |

### queryProductDetailsAsync <a href="#purchaseclient-queryproductdetailsasync" id="purchaseclient-queryproductdetailsasync"></a>

```
@UiThread
public abstract void queryProductDetailsAsync( params,  listener)
```

It imports the details of in-app products registered on Developer Center.

| **Parameters:** |                                                                                                                                      |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| params          | [ProductDetailsParams](https://dev.onestore.co.kr/wiki/en/doc/productdetailsparams-5833438.html)                                     |
| listener        | It receives the result of the [PurchasesListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/PurchasesListener) in-app details. |

### manageRecurringProductAsync <a href="#purchaseclient-managerecurringproductasync" id="purchaseclient-managerecurringproductasync"></a>

```
@UiThread
public abstract void manageRecurringProductAsync( recurringProductParams,  listener)
```

It changes Monthly auto-renewal product status.

It performs the action either to cancel automatic payment every month or to resume the cancelled automatic payment.

| **Parameters:**        |                                                                                                                                                                               |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| recurringProductParams | [RecurringProductParams](https://dev.onestore.co.kr/wiki/en/doc/recurringproductparams-5833429.html)                                                                          |
| listener               | It imports the result of the [RecurringProductListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/RecurringProductListener) Monthly auto-renewal product status change. |

### launchLoginFlowAsync <a href="#purchaseclient-launchloginflowasync" id="purchaseclient-launchloginflowasync"></a>

```
@UiThread
public abstract void launchLoginFlowAsync(Activity activity,  listener)
```

When PurchaseClient.ResponseCode.RESULT\_NEED\_LOGIN occurs, the value of IapResult.getResponseCode() performs ONE store login.

| **Parameters:** |                                                                                            |
| --------------- | ------------------------------------------------------------------------------------------ |
| activity        | Activity: refer to the activity to understand ONE store login flow.                        |
| listener        | [IapResultListener](https://dev.onestore.co.kr/wiki/en/doc/iapresultlistener-5833434.html) |

### getStoreInfoAsync <a href="#purchaseclient-getstoreinfoasync" id="purchaseclient-getstoreinfoasync"></a>

```
@UiThread
public abstract void getStoreInfoAsync( listener)
```

It imports market identification codes.

This is the value required for using a server to server API.

| **Parameters:** |                                                                                                                                    |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| listener        | It receives the [StoreInfoListener](https://wiki.onestorecorp.com/display/IAPGOOGLE/StoreInfoListener) market identification code. |

\


\
