WebToNative
  • Getting started
  • Plugin Setup
    • OneSignal Set Up
    • Google AdMob Setup
    • In App Purchase - iOS Setup
    • In App Purchase - Android Setup
    • Firebase Notification Integration - iOS Setup
  • Social Login Integrations
    • Getting the SHA Key for Google Login
    • Create Google OAuth Client Id
    • Facebook Login Configuration
  • Javascript APIS
    • Getting Started
    • Status Bar
    • Pull To Refresh
    • Close App
    • Device Info
    • Clear App Cache
    • OneSignal Push Notification
    • Download Files
    • Printing Options
    • AdMob
    • Geo Location
    • Load In External Browser
    • Barcode Scan
    • In App Purchase - iOS Integration
    • In App Purchase - Android Integration
    • Social Login
    • Facebook App Events
    • Bottom Navigation
    • Clipboard
    • Screen Control
    • Background Location
    • Native Contacts
    • iOS App Tracking Transparency
    • Google Firebase Analytics
    • Haptic Feedback
    • Google Firebase Notification
    • Apps Flyer
    • App Review
    • Calender - iOS
    • Calendar - Android
    • Biometric Authentication
    • Media Player
    • Notification View
    • Offer Card
    • Cookie Update
    • App Launch Detection
    • Download Manager
    • Dynamic App Icon
    • File Sharing
  • Website Plugins
    • Wordpress
      • Push notification (WooCommerce)
      • In-App Purchase
        • In-App Purchase (IAP) Configuration Guide for iOS and Android
        • In-App Purchase (WooCommerce)
        • In-App Purchase
      • Offercard
      • Biometric Authentication
      • Social Login
      • Webtonative media player
        • WebToNative Radio Player
        • MediaPlayer Native Control
    • Bubble.io
      • Customize Status Bar
      • Device-Based Element Visibility
      • Pull to Refresh (Android)
      • OneSignal Push Notification
        • Set External ID
        • Send Push Notification
        • Set/Remove Email or SMS Phone
        • Set Tag
      • Close App
      • Get Device Info
      • Clear App Cache (Android)
      • Screen Control
      • Facebook Events
        • Regular
        • Purchase
      • AdMob
      • Offercard
      • In-App Purchase
        • In-App Purchase (Android/iOS)
        • Get IAP Canceled Subscription List (iOS)
      • Social Login
      • Biometric Authentication
  • Shopify
    • Social Login
    • In-App Purchase
      • In-app purchase
    • Push Notification
      • Abandoned Cart
    • Status Bar Customization
    • Native Device Visibilty
    • Set Onesignal Tags
    • Pull to Refresh
    • Account Deletion
    • Biometric Authentication
  • Upload Apps
    • Android App
    • Ios App
Powered by GitBook
On this page

Was this helpful?

  1. Javascript APIS

In App Purchase - Android Integration

PreviousIn App Purchase - iOS IntegrationNextSocial Login

Last updated 1 year ago

Was this helpful?

You'll need to import the javascript file in your website before starting from this .

If you have not done setup for In App Purchase in your Google Developer account to know how to setup IAP in Android.

To initiate In app purchase in your app call following method from 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){
	    		
	}
    }
})
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

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.

click here