Giter Club home page Giter Club logo

stripe-no-website-example's Introduction

Note

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.

Stripe + RevenueCat No Website Example

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.

Getting Started

The easiest way to use this project is by deploying to Heroku instantly with the button below.

Deploy

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.

Environment Variables

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 be true for production mode. Set to false 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.

Using the Sample

โš ๏ธ Please make sure you have connected your Stripe account to your RevenueCat account before making test purchases.

Creating a Product in Stripe

Follow the instructions in our docs to create subscription products in Stripe.

Setting Up Webhooks

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

Purchasing

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.

Limitations

Finding users from the dashboard

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.

Retry Logic

This example does not attempt to retry sending purchases to RevenueCat if the initial POST fails.

stripe-no-website-example's People

Contributors

codykerns avatar mitchellmonaghan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.