> For the complete documentation index, see [llms.txt](https://docs.webtonative.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.webtonative.com/javascript-apis/in-app-purchase-android-integration-1.md).

# 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](/plugin/in-app-purchase-android-setup.md) 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="npm" %}

```
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="npm" %}

```
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>
