# PurchaseClient

```java
public abstract class BillingClient extends Object

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

\
The default interface for communication between the library and the user application code.\
Every method is processed asynchronously. It must be called from the UI thread and every call back is restored to the UI thread.\
When it calls the startConnection ([PurchaseClientStateListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/purchaseclientstatelistener)) method and the setting is complete, it can receive notifications through the listener to set the connection setting after instantiating this class.

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

\
In general, it calls the purchase history check and the details of in-app products. Please refer to queryPurchasesAsync(String, [QueryPurchasesListner](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/querypurchaseslistener)) and queryProductDetailsAsync([ProductDetailsParams](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/productdetailsparams), ProductDetailsListener). Please do not forget to call endConnection() when the work is done with this object and end the application. It needs to disconnect and remove resources from the billing module. The recommended location is Activity.onDestroy(). To check the detailed log of the library, enter android.util.Log.VEROSE in Logger.setLogLevel(int).\
Caution: Please remove Logger.setLogLevel(int) before releasing the release version of the application.

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

***

| **Nested classes** |                                                                                                                                                   |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| @interface         | [PurchaseClient.ConnectionState](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/purchaseclientstatelistener)     |
| @interface         | [PurchaseClient.ResponseCode](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/annptations/purchaseclient.responsecode)       |
| @interface         | [PurchaseClient.ProductType](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/annptations/purchaseclient.producttype)         |
| @interface         | [PurchaseClient.RecurringAction](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/annptations/purchaseclient.recurringaction) |
| @interface         | [PurchaseClient.FeatureType](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/annptations/purchaseclient.featuretype)         |
| class              | <p><a href="purchaseclient.builder">PurchaseClient.Builder<br></a>A builder that helps create a PurchaseClient instance easily.</p>               |

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

***

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

@AnyThreadpublic static [PurchaseClient.Builder](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/purchaseclient.builder) newBuilder(Context context)\
Generates the builder to create a PurchaseClient instance.

| **Parameters:**                                                                                                               |                                                                      |
| ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| context                                                                                                                       | Used to connect with the payment module by using applicationContext. |
| **Returns:**                                                                                                                  |                                                                      |
| [PurchaseClient.Builder](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/purchaseclient.builder) | <p><br></p>                                                          |

### isReady <a href="#id-en-purchaseclient-isready" id="id-en-purchaseclient-isready"></a>

@AnyThreadpublic abstract boolean isReady()\
Checks if the client is connected to the current service to check whether the request of other functions succeed.

| **Returns:** |
| ------------ |
| boolean      |

### getConnectionState <a href="#id-en-purchaseclient-getconnectionstate" id="id-en-purchaseclient-getconnectionstate"></a>

@AnyThreadpublic abstract int getConnectionState()\
Restores the connection state of the current PurchaseClient.

| **Returns:** |                                                                                                                                                                                        |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int          | The state value that corresponds to [PurchaseClient.ConnectionState.](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/annptations/purchaseclient.connectionstate) |

### &#x20;isFeatureSupported <a href="#id-en-purchaseclient-isfeaturesupported" id="id-en-purchaseclient-isfeaturesupported"></a>

@UiThread\
public abstract IapResult[ ](https://dev.onestore.co.kr/wiki/en/doc/en-iapresult-38077498.html)isFeatureSupported(String feature)\
Checks whether or not the specified feature is supported by the service.

| **Parameters:** |                                                                                                                                                                             |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| String          | One of [PurchaseClient.FeatureType ](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/annptations/purchaseclient.featuretype)constants.                 |
| **Returns:**    |                                                                                                                                                                             |
| IapResult       | <p>If the feature is supported, PurchaseClient.ResponseCode.RESULT\_OK.<br>If the feature is not supported, PurchaseClient.ResponseCode.ERROR\_FEATURE\_NOT\_SUPPORTED.</p> |

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

@AnyThreadpublic abstract void startConnection([PurchaseClientStateListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/old-version/v19/one-store-iap-reference/interfaces/purchaseclientstatelistener)[ ](https://dev.onestore.co.kr/wiki/en/doc/en-purchaseclientstatelistener-38077519.html)listener)\
Starts PurchaseClient setting process asynchronously. It receives responses through PurchaseClientStateListener.

| **Parameters:** |                                                                                              |
| --------------- | -------------------------------------------------------------------------------------------- |
| listener        | Receives responses when PurchaseClient setting and billing module connections are completed. |

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

@AnyThreadpublic abstract void endConnection()\
Disconnects from the billing module and removes retained resources of PurchaseClient.

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

@UiThreadpublic abstract void launchUpdateOrInstallFlow(Activity activity, IapResultListener[ ](https://dev.onestore.co.kr/wiki/en/doc/en-iapresultlistener-38077517.html)listener)\
Needs to call for an update or installation of the billing module when the value of IapResult.getResponseCode() occurs as PurchaseClient.ResponseCode.RESULT\_NEED\_UPDATE

| **Parameters:** |                                                                                                                        |
| --------------- | ---------------------------------------------------------------------------------------------------------------------- |
| activity        | Activity: Refers to the activity to know the flow of update or installation of the billing module.                     |
| listener        | [IapResultListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/iapresultlistener) |

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

@UiThread\
public abstract IapResult[ ](https://dev.onestore.co.kr/wiki/en/doc/en-iapresult-38077498.html)launchPurchaseFlow(Activity activity, PurchaseFlowParams[ ](https://dev.onestore.co.kr/wiki/en/doc/en-purchaseflowparams-38077506.html)params)\
Starts purchasing in-app products.\
The purchase page displays and it receives response results by [PurchasesUpdatedListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/purchasesupdatedlistener) that is specified when PurchaseClient was initialized.

| **Parameters:** |                                                                                                                                                              |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| activity        | Refers to activity to open the purchase page.                                                                                                                |
| params          | A parameter to open the [PurchaseFlowParams](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/purchaseflowparams) purchase page. |
| **Returns:**    |                                                                                                                                                              |
| IapResult       | <p><br></p>                                                                                                                                                  |

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

@AnyThreadpublic abstract void consumeAsync(ConsumeParams[ ](https://dev.onestore.co.kr/wiki/en/doc/en-consumeparams-38077496.html)params, ConsumeListener[ ](https://dev.onestore.co.kr/wiki/en/doc/en-consumelistener-38077516.html)listener)\
Consumes the purchased products.\
It can be processed for only owned products and it needs to be purchased again if the products are consumed already.\
Caution: It will be refunded if it is not consumed or acknowledged within 3 days of the purchase date from API v6.

| **Parameters:** |                                                                                                                                                           |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| params          | A parameter to consume [ConsumeParams.](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/consumeparams)                       |
| listener        | Receives the result of [ConsumeListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/consumelistener) consuming work. |

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

@AnyThread\
public abstract void acknowledgeAsync(AcknowledgeParams[ ](https://dev.onestore.co.kr/wiki/en/doc/en-acknowledgeparams-38077494.html)acknowledgeParams, AcknowledgeListener[ ](https://dev.onestore.co.kr/wiki/en/doc/en-acknowledgelistener-38077515.html)listener)\
Acknowledges purchased products.\
It can be processed for only owned products and it can't be purchased again if the acknowledged product is not consumed.\
It can be applied on all management-type products or monthly auto-renewal products.\
In particular, for management-type products, it is able to be used as subscription products that can be acknowledged and consumed after a certain time period.\
Caution: It will be refunded if it doesn't consume or acknowledge within 3 days of the purchase date from API v6.

| **Parameters:**   |                                                                                                                                                                                        |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| acknowledgeParams | The parameter to acknowledge the purchase of [AcknowledgeParams.](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/acknowledgeparams)                      |
| listener          | Receives the result of acknowledging the purchase works of [AcknowledgeListener.](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/acknowledgelistener) |

### &#x20;queryPurchasesAsync <a href="#id-en-purchaseclient-querypurchasesasync" id="id-en-purchaseclient-querypurchasesasync"></a>

@AnyThread\
public abstract void queryPurchasesAsync(String productType, [\[EN\]QueryPurchasesListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/querypurchaseslistener)[ ](https://dev.onestore.co.kr/wiki/en/doc/en-querypurchaseslistener-38077522.html)listener)\
Brings the purchase information of every purchased product from the app.

| **Parameters:** |                                                                                                                                                                           |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| productType     | Specifies [PurchaseClient.ProductType](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/querypurchaseslistener) type of products.          |
| listener        | Receives the result of [QueryPurchasesListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/querypurchaseslistener) purchase history. |

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

@AnyThread\
public abstract void queryProductDetailsAsync(ProductDetailsParams params, ProductDetailsListener[ ](https://dev.onestore.co.kr/wiki/en/doc/en-productdetailslistener-38077518.html)listener)\
Brings the detailed information of the registered in-app products in the developer center.

| **Parameters:** |                                                                                                                                                                                            |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| params          | It is the parameter to bring [ProductDetailsParams](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/productdetailsparams) product detailed information.       |
| listener        | It receives the result of [ProductDetailsListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/recurringproductlistener) product detailed information. |

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

@AnyThread\
public abstract void manageRecurringProductAsync(RecurringProductParams[ ](https://dev.onestore.co.kr/wiki/en/doc/en-recurringproductparams-38077508.html)recurringProductParams, RecurringProductListener[ ](https://dev.onestore.co.kr/wiki/en/doc/en-recurringproductlistener-38077523.html)listener)\
Changes the status of monthly auto-renewal products.\
It processes the action of canceling automatic payment for every month or resuming the canceled monthly auto-renewal product again.

| **Parameters:**        |                                                                                                                                                                                                 |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| recurringProductParams | A parameter to change the status of [RecurringProductParams](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/recurringproductparams) monthly auto-renewal status.  |
| listener               | Receives the result of [RecurringProductListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/recurringproductlistener) monthly auto-renewal status change. |

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

@UiThread\
public abstract void launchLoginFlowAsync(Activity activity, IapResultListener[ ](https://dev.onestore.co.kr/wiki/en/doc/en-iapresultlistener-38077517.html)listener)\
Processes store login when the value PurchaseClient.ResponseCode.RESULT\_NEED\_LOGIN is occured.

| **Parameters:** |                                                                                                                                                                   |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| activity        | Activity: Refers to the activity to know the flow of store login.                                                                                                 |
| listener        | Receives the result of [lapResultListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/purchaseclient) login success or failure. |

### launchManageSubscription <a href="#id-en-purchaseclient-launchmanagesubscription" id="id-en-purchaseclient-launchmanagesubscription"></a>

@UiThread\
public abstract void launchManageSubscription(Activity activity, SubscriptionParams[\[EN\]SubscriptionParams](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/subscriptionparams)subscriptionParams)\
Moves to the subscription products management menu.

| **Parameters:**    |                                                                                                                                                                                                                  |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| activity           | Refers to activity to move to the subscription products management menu.                                                                                                                                         |
| subscriptionParams | If [SubscriptionParams](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/classes/subscriptionparams) null, it moves to the detail page if there is PurchaseData on the management menu page. |

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

@AnyThread\
public abstract void getStoreInfoAsync([StoreInfoListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/storeinfolistener) listener)\
Brings the market identification code.\
This value is required when using server to server API.

| **Parameters:** |                                                                                                                                                                 |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| listener        | Receives the [StoreInfoListener](https://onestore-dev.gitbook.io/dev/eng/tools/billing/v21/references/interfaces/storeinfolistener) market identification code. |
