Updated on 22. June 2023 by Jan Bunk
You can follow these guides to create in app purchase products and subscriptions:
You might be asked to enter some additional information to enable payments in your developer account.
As you will need to create an in app purchase product in each platform, make sure you use the same product ID on both platforms, so triggering the in app purchase via Javascript will be easier (see below).
First, you'll most likely want to check whether the current user is using your app, because a regular browser user won't be able to make in app purchases.
You can use
getAppPlatform() != null
with the app helper script.
Then, if the user is using your app, you can use the below Javascript to trigger an in app purchase.
executeWhenAppReady()
function of
our app helper script. It ensures that your website doesn't try to interact with the app before it's ready or when your website is loaded using a regular browser (ReferenceError, function is not defined).
<script>
try {
// productId is the ID you specified for the in app purchase product in App Store Connect and the Google Play Console
// consumable is a boolean value that indicates whether the product can be purchased multiple times (consumable==true) or just once (consumable==false)
// subscriptions should use consumable==false
// userIdentifier can be any string that identifies the current user.
// The userIdentifier will be sent to your server's unlocking endpoint if the purchase is successful (so you can then unlock the product that was bought on your server)
await makeInAppPurchase(productId, consumable, userIdentifier);
} catch (e) {
// e.g. if the productId is invalid
}
</script>
executeWhenAppReady()
function of
our app helper script. It ensures that your website doesn't try to interact with the app before it's ready or when your website is loaded using a regular browser (ReferenceError, function is not defined).
You can also provide a "Restore Purchases" option to your users.
<script>
restorePurchases()
</script>
Usually restoring purchases is necessary when users uninstall the app and install it again on a new device. They can then restore their previous purchases. You store the user's information and purchases on your server already, which is independent of the user's device.
We are still providing you the opportunity to integrate a restore purchase functionality in the hopes that it may be useful under other circumstances, e.g. it could potentially help if something went wrong while verifying and unlocking a user's purchase.
After a user completes a purchase in the app, the purchase needs to be verified on a server and, if successfully verified, the purchased contents need to be unlocked on your server.
Please see your in app purchase settings for more information and guides.
Here's a list of related pages about in app purchases: