Links

In App Purchase - Android Integration

You'll need to import the javascript file in your website before starting from this link.
If you have not done setup for In App Purchase in your Google Developer account click here to know how to setup IAP in Android.
To initiate In app purchase in your app call following method from javascript
Plain JS
ES 6+
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){
}
}
})
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){
}
}
})
Use the productId, the one you have used while creating a product via play console.
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,
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’.
To query purchases made by user call following method from javascript
Plain JS
ES 6+
window.WTN.getAllPurchases({
callback : function(data){
var receiptData = data.receiptData;
if(data.isSuccess){
}
}
})
import { getAllPurchases } from "webtonative/InAppPurchase"
getAllPurchases({
callback : function(data){
var purchaseData = data.purchaseData;
//console.log(purchaseData)
}
})
You can get all the purchases made by the user with active subscriptions and non-consumed one-time purchases.