This example assumes some previous knowledge about the RevenueCat platform.
If you're looking for official iOS, Android, Flutter, and other SDK's + sample apps for RevenueCat, head over to the RevenueCat GitHub page.
RevenueCat supports web payments through Stripe. This allows you to let users subscribe on your own website, and automatically unlock access to the same subscription content through the Purchases SDK.
If you don't have or don't want a full website, it can be unclear on how to proceed with integrating Stripe payments. This sample project demonstrates how to use Stripe Checkout and webhooks to send purchase data to RevenueCat.
The easiest way to use this project is by deploying to Heroku instantly with the button below.
You can run the project on any server that supports Node.JS 14.x with minimal effort.
Note: If you don't use Heroku, you'll need to swap out the herokuapp.com server URL's below with your own server.
The following environment variables should be set before starting the server.
-
RC_API_KEY
- Required. API key for your RevenueCat app. -
STRIPE_KEY
- Required. Production Stripe API key. -
STRIPE_KEY_TEST
- Required. Test Stripe API key. -
TEST_MODE
- Required. Should betrue
for production mode. Set tofalse
if you want use Stripe in test mode. -
SUCCESS_URL
- Required. The URL that Stripe will redirect the user to after a successful purchase. If you don't have a website, you could use a URL scheme to redirect back to your mobile app. -
CANCEL_URL
- Required. The URL that Stripe will redirect the user to after a user cancels a purchase without completing it. If you don't have a website, you could use a URL scheme to redirect back to your mobile app.
Follow the instructions in our docs to create subscription products in Stripe.
You'll need to create a new webhook in Stripe to forward purchase data to your instance and subsequently to RevenueCat.
Add a new webhook in Stripe for the event types:
checkout.session.completed
The URL for your webhook should be the following:
http://(herokuID).herokuapp.com/webhooks/stripe
To redirect your users to a checkout, you create a purchase
link, with the following format:
http://(herokuID).herokuapp.com/purchase/:appUserID/:stripePriceID
Parameters:
-
:appUserID
- The RevenueCat app user ID to which this purchase should be applied. -
:stripePriceID
- The Price ID for the purchase. When you create a subscription with Stripe, you create the 'Product' (for example, 'Pro Mode'), then a 'Price' (for example, $15/monthly). This parameter should be the price ID. Looks something like:price_1GyCuXCc12BVHqV1Qx5qhFXW
After the purchase is completed, Stripe will send a webhook to this server with the data from the purchase. The server will then forward it to RevenueCat and pair it with the user ID who made the purchase.
A limitation with this example is that each transaction will be logged as a separate customer with no apparent connection between purchases in the RevenueCat dashboard and customers in the Stripe dashboard.
To pair customers from the RevenueCat dashboard to the Stripe dashboard, this example sets a subscriber attribute for the RevenueCat subscriber called stripe_customer_id
that is searchable from Stripe's dashboard. Since each purchase is logged as a separate customer, this value is only the customer for the most recent purchase associated with that user ID.
This example does not attempt to retry sending purchases to RevenueCat if the initial POST
fails.