Stripe Payment Gateway Setup
In this section we will discuss step by step process for integrating Stripe payment gateway in Blink.
Collect Stripe Connection Keys
-
Create a Stripe account at https://dashboard.stripe.com/register
-
The it will redirect you to dashboard: https://dashboard.stripe.com/test/dashboard
-
From the dashboard copy
Publishable key
andSecret key
. Then save them in a secure place.
- Open the backend code in VS code and go to
.env
file, then place your secret key inSTRIPE_SECRET_KEY
variable and save it.
.env
# Stripe
STRIPE_SECRET_KEY="****************************************************************"
caution
By default Stripe comes with Test mode
. You can use test mode to locally test stripe payments. To accept real money payments, follow stripe business onboarding process.
Create Product on Stripe
- From dashboard go to Product catalog.
- Press on Create a product button.
info
We have 2 paid product for subscription. There names are
- Pro
- Premium
Monthly price for Pro subscription is $3.99 and yearly rate is $39.00.
Monthly price for Premium subscription is $7.99 and yearly rate is $79.00.
You can price as you want.
- For Pro product, provide name, description, amount, and select Recurring payment. Billing period should be
Monthly
, Unit quantity = 1. Save the product. - Then collect and save the
price id
of monthly subscription.
- Then go to the same product again and add another price, This time for
Yearly
subscription. Again collect and save theprice id
of yearly subscription. - For Premium product, repeat the same process again.
- Then open the backend code in VS code and go to
.env
file, then place yourPrice Ids
in their respected fields. - Save the
.env
file.
.env
# Stripe Price IDs
STRIPE_SUBSCRIPTION_PREMIUM_PLAN_YEARLY_PRICE_ID="************************************"
STRIPE_SUBSCRIPTION_PREMIUM_PLAN_MONTHLY_PRICE_ID="************************************"
STRIPE_SUBSCRIPTION_PRO_PLAN_YEARLY_PRICE_ID="************************************"
STRIPE_SUBSCRIPTION_PRO_PLAN_MONTHLY_PRICE_ID="************************************"
Create Stripe Webhook
- From Dashboard's bottom-left corner click on Developers
- Then click on Webhooks tab and then click on Create an event destination.
- Then Add an end point
- Your webhook Endpoint URL looks like
https://www.yourdomain.com/api/stripe/server-webhook
. Replacewww.yourdomain.com
with your domain name. - Then write description if you want and select Listen to Events on your account.
- Then select all events
- Copy
endpointSecret
code. - Click Add endpoint.
- Now open
.env
file from backend code, and add theendpointSecret
value toSTRIPE_WEBHOOK_SECRET
and save the file.
.env
# Stripe
STRIPE_SECRET_KEY="****************************************************************"
STRIPE_WEBHOOK_SECRET="************************************************"