In-App Purchases
Learn how to add in-app purchases to your app.
In-app purchases allow your app to charge users within it. For example, if you are building a game, you can charge users for extra lives, or if you are building a social media app, you can charge users to unlock premium features.
How it works
- You create a
Line Item
for your in-app purchase, this is scoped to a company - You open the checkout modal, passing in the
line_item_id
- The user enters their payment details and completes the purchase
- The company that has installed your app receives the payment
The company must have Whop Payments set up to accept payments. If they do not, the purchase will fail.
Getting started
In this example, we will be creating an app that allows users to buy T-shirts. Instead of making each T-shirt a separate product on Whop, we will be doing it under one app, and allowing them to purchase it through the app.
We are going to charge $29.99 per T-shirt.
Currently, this only works on the user_view
and the
admin_view
. If you call this function on any other view, it will
throw an error.
1. Prerequisites
- You must have initialized the Whop iFrame SDK. See Initialising the iFrame SDK
2. Create a Line Item
To offer in-app purchases, you first need to create a Line Item. These are purchasable entities that you can create / update / delete using the Whop API. It stores the price, name, and currency of your in-app purchase.
This means that you must ensure the line_item_id
you are using is scoped to the company you are trying to charge. E.g:
- Your app is installed on
biz_1
andbiz_2
- Your app must create 2 line items, one for
biz_1
and one forbiz_2
li_1
forbiz_1
li_2
forbiz_2
- Jordan is viewing a product purchased from
biz_1
- When creating the in-app purchase, you must use
li_1
as theline_item_id
, that way the charge is scoped tobiz_1
- If you pass in
li_2
as theline_item_id
, the charge will fail and throw an error
We are going to create a line item for our T-shirt using the Whop SDK
:
3. Opening the checkout modal
Now that we have created a line item for our T-shirt, we can create and open the checkout modal. This is where the user will enter their payment details and complete the purchase.
To do this, we are going to use the Whop SDK. This component will need to be client-side, as it has to access the browser.
4. Handling the result
When the user completes the purchase, the modal will close and return a result. This result will contain the session_id
and the receipt_id
.
The receipt_id
is a unique identifier for the purchase. You can use this to verify the purchase on your backend and fetch information about the purchase.
Your app will also receive a webhook when the purchase is complete. See Webhooks for more information.
If the payment is successful, the company will receive the payment. If the app wants to take a cut of the payment, you can do so by using Metered Billing.
Was this page helpful?