Resources
π° Test the live demo here!
- Test card number:
4242 4242 4242 4242
! - Choose a valid and random MM/YY (e.g. 09/23), as well as a random CVC (e.g. 123).
π§ The full code base can be found here.
A Paid Membership Site
If youβre looking for a way to finally charge people for your hard-earned digital work, look no further! In this tutorial, youβll learn how to create a paid membership app where users can pay for a lifetime access pass to your Premium Content πΈ.
We'll be using Stripe as our payment processor, Magic as our auth solution, React as our front end framework, Express as our server framework for Node.js, and Heroku to deploy our app!
Prerequisites
- If youβre unfamiliar with building a membership app with React, Express, and Magic, take a look at Build Magic auth into your React + Express app. We'll be reusing a lot of the code from this guide π.
- Also, feel free to check out Stripeβs guide on the Custom payment flow. We followed the steps listed in this guide to help implement our Stripe payment page π.
File Structure
The root directory will contain the server-side files. The client folder will have all of the frontend files.
βββ README.md
βββ client
β βββ .env
β βββ package.json
β βββ public
β β βββ (static files, such as images)
β βββ src
β β βββ App.js
β β βββ components
β β β βββ header.js
β β β βββ home.js
β β β βββ layout.js
β β β βββ loading.js
β β β βββ login-form.js
β β β βββ login.js
β β β βββ payment-form.js
β β β βββ payment.js
β β β βββ premium-content.js
β β β βββ profile.js
β β β βββ signup-form.js
β β β βββ signup.js
β β βββ index.js
β β βββ lib
β β β βββ LifetimeAccessRequestStatusContext.js
β β β βββ LifetimeContext.js
β β β βββ UserContext.js
β β β βββ magic.js
β βββ yarn.lock
βββ .env
βββ package.json
βββ server.js
βββ yarn.lock
Quick Start Instructions
Magic Setup
Create a Magic account and then grab your REACT_APP_MAGIC_PUBLISHABLE_KEY
and MAGIC_SECRET_KEY
from your Magic Dashboard.
Stripe Setup
Create a Stripe account and then grab your REACT_APP_STRIPE_PK_KEY
and STRIPE_SECRET_KEY
from your Stripe Dashboard.
Start your Express Server
git clone https://github.com/magiclabs/magic-stripe.git
cd magic-stripe
mv .env.example .env
- Replace
MAGIC_SECRET_KEY
andSTRIPE_SECRET_KEY
with the appropriate values you just copied. Your.env
file should look something like this:
MAGIC_SECRET_KEY=sk_test_XXX
CLIENT_URL=http://localhost:3000
STRIPE_SECRET_KEY=sk_test_XXX
yarn
node server.js
Note: Running yarn
helped us pull the dependencies we need for our server, including the Stripe Node library.
Start your React Client
(in a new terminal session)
cd client
mv .env.example .env
- Replace
REACT_APP_MAGIC_PUBLISHABLE_KEY
andREACT_APP_STRIPE_PK_KEY
with the appropriate values you just copied. Your.env
file should look something like this:
REACT_APP_MAGIC_PUBLISHABLE_KEY=pk_test_XXX
REACT_APP_SERVER_URL=http://localhost:8080
REACT_APP_STRIPE_PK_KEY=pk_test_XXX
yarn
yarn start
Note: Running yarn
helped us pull the dependencies we need for our client, including Stripe.js and the Stripe Elements UI library (both needed to stay PCI compliant; they ensure that card details go directly to Stripe and never reach your server.)
Magic React Storybook
This tutorial was built using Magic React Storybook π€©. If you wish to swap the Magic UI components out for your own custom CSS, delete @magiclabs/ui
and framer-motion
from your client/package.json
dependencies.
What's Next
Now that you've set everything up, let's get started with building the React client side! Click here to continue.
Top comments (0)