# In App Purchase - Android Integration

{% hint style="info" %}

<pre data-overflow="wrap"><code>You'll need to import the javascript file in your website before starting from this <a data-footnote-ref href="#user-content-fn-1">link</a>.
</code></pre>

{% endhint %}

If you have not done setup for In App Purchase in your Google Developer account [click here](https://docs.webtonative.com/plugin/in-app-purchase-android-setup) to know how to setup IAP in Android.

**To initiate In app purchase in your app call following method from javascript**

{% tabs %}
{% tab title="Plain JS" %}

```javascript
window.WTN.inAppPurchase({ 
    productId : ‘Product Id of IAP’,
    productType : ‘Product Type of IAP’,
    isConsumable : true or false,
    callback : function(data){
	var receiptData = data.receiptData;
	if(data.isSuccess){
	    		
	}
    }
})
```

{% endtab %}

{% tab title="ES 6+" %}

```
import { inAppPurchase } from "webtonative/InAppPurchase"

inAppPurchase({ 
    productId : ‘Product Id of IAP’,
    productType : ‘Product Type of IAP’,
    isConsumable : true or false,
    callback : function(data){
	var receiptData = data.receiptData;
	if(data.isSuccess){
    		
	}
    } 
}) 
```

{% endtab %}
{% endtabs %}

Use the productId, the one you have used while creating a product via play console.&#x20;

productType will be “INAPP” for one time purchases and “SUBS” for subscriptions.

If the product is consumable you’ll need to pass isConsumable ‘true’ else ‘false’.

For one-time consumable products,&#x20;

isConsumable would be ‘true’. By passing true you make sure that the user can purchase again and again.

For one-time non-consumable products, isConsumable would be ‘false’. By passing false you make sure that the user can purchase only once.

Subscription can be treated as a non-consumable product i.e. isConsumable would be ‘false’.

![](https://lh4.googleusercontent.com/Ul-ASvSZWAgQ1XtPNhkkpUOFbWUI4XE0RL7tNgdlsAWdYnGiL5r1ccAFcOVsZkuJdJ_kPI04a6XtufpkvhGsQWL7s0fGrId-sMfHdEvR4dJfraKj6qXVL1kSvHTZUMlmzjNFshPCLWlUHFNr_etDujKmj3BOt-LXJX-zCGdhSLGwir9TBjUDh2raGn9V-g)                             ![](https://lh4.googleusercontent.com/sWo4XvEMj1UDKeYRKf_9d_EgNDsnoluu7E25_YPOmfsklegCAlc-fa4cd5TIR723T7ujoLqLSf9P53dGSmWKNDN1ShwZGb45MXfVAzguKcabXDy2FiLkZfC_PFkRxw59HumS-UXw31ZDf_5EZ6UW3gUeYCTD6nS9yxPjNWzmXPKydSIiZF6e7Th7jD-d4g)

<br>

**To query purchases made by user call following method from javascript**

{% tabs %}
{% tab title="Plain JS" %}

```
window.WTN.getAllPurchases({ 
    callback : function(data){
	var receiptData = data.receiptData;
	if(data.isSuccess){
	    		
	}
    }
})
```

{% endtab %}

{% tab title="ES 6+" %}

```
import { getAllPurchases } from "webtonative/InAppPurchase"
getAllPurchases({ 
    callback : function(data){
	var purchaseData = data.purchaseData;
	//console.log(purchaseData)
    } 
}) 
```

{% endtab %}
{% endtabs %}

You can get all the purchases made by the user with active subscriptions and non-consumed one-time purchases.

[^1]: <https://docs.webtonative.com/javascript-apis/getting-started>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.webtonative.com/javascript-apis/in-app-purchase-android-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
