Payments with Stripe

ScaffoldHub uses Stripe to accept payments for the workspaces plans.

For this tutorial, we will use the Test Mode. You will need to repeat this process for Live Mode.

Create a Stripe account

Go to stripe.com and create a new account.

Save the API keys

  1. Go to the Get your test API keys tab.

  2. Copy the Publishable key to the .env.

  3. Save it on NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY.

  4. Copy the Secret key to the .env.

  5. Save it on STRIPE_SECRET_KEY.

Create the plans

By default, ScaffoldHub uses Growth and Enterprise as the plan names. Feel free to change those names, add or remove a plan. This will require changing the code. See Architecture > Payments for more details.

Go to Products > Add Product.

Fill in the Product's information.

  • Name

  • Price

  • Recurring

  • Billing Period

Copy the Price Codes and save on the backend environment variables.

NEXT_PUBLIC_SUBSCRIPTION_PRICES_BASIC = "price_..."
NEXT_PUBLIC_SUBSCRIPTION_PRICES_ENTERPRISE = "price_..."

Enable the Customer Portal

Go to Settings > Billing > Customer Portal.

Enable the functionalities you want on the customer portal.

Read more about the customer portal here: https://stripe.com/docs/billing/subscriptions/customer-portal

Create a Webhook

The webhook is responsible for notifying the application when the plans' subscriptions have changed.

Go to Developers > Webhooks > Add Endpoint.

The backend URL must have this format: https://your_backend_url/api/subscription/webhook

Events you need to capture are:

  • checkout.session.completed

  • customer.subscription.updated

  • customer.subscription.deleted

Now, update the STRIPE_WEBHOOK_SECRET environment variable with the Signing Secret.

Testing the webhooks on localhost

To test the webhooks on localhost, please follow this tutorial:

Done! You can now use payments on your application.

Last updated