Stripe integration in your webapp
Pre-requisites
You need a Stripe account and API keys to integrate Stripe into your web application. You can sign up for a Stripe account at Stripe's website.
Enable Test Mode
Publishable Key and Secret Key
Webhooks keys
Why you need webhook keys? Webhooks are a way for Stripe to send real-time notifications to your web application about events that occur in your Stripe account, such as successful payments, failed charges, subscription updates, etc. To ensure the security of these notifications, Stripe uses webhook signing secrets to verify that incoming webhook events are genuinely from Stripe and have not been tampered with. To get the webhook keys, you can follow these steps:
- Log in to your Stripe dashboard.
- Navigate to the "Developers" section in the left-hand menu.
- Click on "Webhooks" in the submenu.
- Click on the "Add endpoint" button to create a new webhook endpoint.
- In the "Endpoint URL" field, enter the URL of your web application where you want to receive webhook events from Stripe.
- Select the events you want to listen for (e.g., "payment_intent.succeeded", "charge.failed", etc.).
- Click on the "Add endpoint" button to save the webhook endpoint.
- After creating the webhook endpoint, you will see a "Signing secret" section. Click on the "Reveal" button to view the webhook signing secret key. This key is used to verify that incoming webhook events are genuinely from Stripe.
All Stripe API keys and links in .env
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51TRFg......00gT7eFw25
STRIPE_SECRET_KEY=sk_test_51TRFglPO......8B5tXdaf
NEXT_PUBLIC_STRIPE_BILLING_LINK=https://billing.stripe.com/p/login/14A......kE00
STRIPE_WEBHOOK_SECRET=some-words-as-keys
Subscription cancellation and refund
Use Stripe-hosted customer portal link to allow your customers to manage their subscriptions, including cancellation and refunds. You can find the customer portal link in your Stripe dashboard under "Billing" > "Customer Portal".
https://dashboard.stripe.com/settings/billing/portal
Activate link
Copy link that looks link https://billing.stripe.com/p/login/14A......kE00