Menu

Stripe Integration

Stripe is currently the most stable and popular global payment processing platform that simplifies the payment process for global businesses, allowing SaaS products to easily accept various payment methods.

In this chapter, we'll introduce how to integrate Stripe into your project.

Registration and Basic Configuration

  1. Visit Stripe and register an account

  2. Go to the Dashboard page, start creating an account from the top left corner, then complete the prerequisite steps according to the page guidance.

Getting API Keys and Creating Webhooks

  1. After registration, you should enter Sandbox mode during development until all processes are debugged, then copy product information to Live mode.
stripe-sandbox
  1. Go to Developer - API Keys page and copy the Secret key and Publishable key to the environment variables STRIPE_SECRET_KEY and STRIPE_PUBLISHABLE_KEY.
stripe-api-keys
  1. Go to Developer - Webhooks page and create a Webhook endpoint.
stripe-webhook
  1. In Cursor or VSCode, set up a Forward Port and set it to Public, then copy the generated Forwarded Address.
stripe-webhook

Good to know:

  • Sometimes after not using it for a long time, the Forward Port may still appear open but has actually become invalid. Simply reopen it — this won't change the Forwarded Address.
  • If Cursor encounters failure when setting up Forward Port, please follow community-provided solutions: Windows Solution or Mac Solution, or switch to a familiar tunneling tool.
  1. Copy the Forwarded Address to the Webhook Endpoint URL, then click Select events to choose the required events.
stripe-webhook
  1. Select the following 7 events:
  • charge.refunded
  • checkout.session.completed
  • customer.subscription.created
  • customer.subscription.updated
  • customer.subscription.deleted
  • invoice.paid
  • invoice.payment_failed

These events are sufficient to complete a robust one-time payment and subscription payment flow, and all these events have corresponding handling logic in the Nexty.dev boilerplate.

stripe-webhook
  1. After the Webhook is created, get the Secret and copy it to the environment variable STRIPE_WEBHOOK_SECRET.
stripe-webhook

Creating Products

Now go to the Product Catalog page and create a product.

add-product

Here's the content filled in for the Nexty.dev product for reference.

product-preview
product-preview

After creation, click on the product to enter the details page.

product-details

You can see the Product ID and Price ID. In subsequent steps, we'll use the Price ID in the admin dashboard pricing plans.

product-id

You can follow the same steps to create additional subscription products.

Enable Radar

Stripe has a Radar feature that allows you to customize rules to identify and block high-risk payments to protect your account security.

block-rules

However, this is a paid feature that can be used for free in Sandbox.

If you've purchased Radar functionality in Live mode, you can add the following rules:

New users created within a week using more than 5 cards
:card_count_for_customer_weekly: > 5 and :hours_since_customer_was_created: <= 168
 
Same customer using more than 4 credit cards within a week
:card_count_for_customer_weekly: > 4 and :card_funding: = 'credit'
 
Weekly high-risk card attempts greater than 3
:card_count_for_customer_weekly: > 3 and :risk_score: > 50
 
Daily high-risk attempts from same IP address
:total_charges_per_ip_address_daily: > 10 and :risk_score: > 40

Limit User Concurrent Subscriptions

If your product has subscriptions and you want to limit users to only 1 subscription at a time, you can set this in the Payments module.

limit-customers-to-1-subscription
limit-customers-to-1-subscription
limit-customers-to-1-subscription

This setting can also prevent users from duplicate subscriptions, which could create disputed orders. Even if disputes are successfully appealed, there's still a $15 handling fee.

Manage Payment Methods

On the Settings - Payment Methods page, you can manage user payment methods. It's recommended to apply for Alipay and WeChat Pay, which allows more users to use your product, especially users in China.

payment-methods

When applying for Alipay and WeChat Pay, Stripe may request additional materials via email. Provide them according to the email instructions. These materials are required by Alipay and WeChat Pay, and Stripe will only officially enable them after approval from Alipay and WeChat Pay.

However, the permissions enabled here only support one-time payments, not subscription products. If you want your subscription products to also support Alipay and WeChat Pay, you need to contact Stripe customer service to apply separately.

Set Up User Portal

The User Portal is a page where users can view and modify their payment methods, subscription status, billing information, etc. Providing a Portal entry in your product can increase user trust.

user-portal

Live Mode

After completing payment flow debugging in Sandbox mode, you can directly copy the created products to Live mode with one click. Other steps need to be completed manually - you can use the steps introduced here as a checklist.

Conclusion

After completing the above configuration, you can follow the remaining steps in the Launch Source Repository documentation to update pricing plans and test the payment flow.