One-time
Learn how to setup and use one-time payments in your project.
This feature is only included for the following templates:
Important
One-time payments is not the same as e-commerce. It is a way to sell a specific product(s) for a one-time fee. e.g. TailwindCSS Plus.
Payment Structure
If you're using the CLI Monorepo template, the @workspace-apps/web app defines one-time payments out of the box for a single product.
Note that if you need to change the pricing structure (e.g. add another price), you will need to make revisions to the @workspace-apps/web app in the following locations:
/apps/web/src/server/router/payment/router.ts./apps/web/src/server/router/products/router.ts.
Setup
Create a new Stripe account and activate payments.
Business settings
Set up your business details so that you can start accepting payments.
- Go to the Settings of the Stripe dashboard
- Click on the Business section.
- Click on the Account details tab and fill out the form as needed.
- Click on the Business details tab and fill out the form as needed.
- You can do this later when you need to start accepting payments (i.e. are ready to switch off Stripe's test mode).
- Click on the Branding tab, and add your icon, logo, and colors.
- Click on the Customer emails tab and enable emails "Successful payments" and "Refunds".
Payment settings
Recommendations to avoid potential abuse and fraud.
- Go back to the Settings page.
- Click on the Payments section.
- Click on the Payment methods tab, and enable only the payment methods you want to offer.
- We recommend disabling "Cash App Pay" to mitigate abuse and fraud. Many customers using it tend to cancel transactions.
Billing settings
Recommendations for avoiding failed payments.
- Go back to the Settings page.
- Click on the Billing section.
- Click on the Subscriptions and emails tab.
- Enable the following Customer emails:
- Send emails when card payments fail
- Send emails when bank debit payments fail
- Within the "Payment method updates" section, select "Link to a Stripe-hosted page"
API keys
Connect your Stripe account to your project.
-
Go to the API keys page. You can find this by clicking on the "Developers" link at the bottom of the left sidebar.
-
Create a "Secret key", and copy values for
STRIPE_SECRET_KEYandSTRIPE_PUBLISHABLE_KEY. -
Add these values to your
.envfile in/apps/web/.env..env STRIPE_SECRET_KEY="sk_test_..." STRIPE_PUBLISHABLE_KEY="pk_test_..." -
Go to the Webhooks page. You can find this by clicking on the "Developers" link at the bottom of the left sidebar.
-
Click on "Add destination" and set the "Endpoint URL" to point to a URL that you want to receive webhooks from Stripe.
- Note that if you are running the project locally, you will need to tunnel your selected Endpoint URL to your local machine. This is because Stripe is unable to access localhost origins.
-
Enable the following events:
checkout.session.completedcheckout.session.expiredpayment_intent.createdpayment_intent.canceled
-
Click on "Create destination", and copy the "Signing secret" value.
-
Add this value to your
.envfile in/apps/web/.envasSTRIPE_WEBHOOK_SECRET..env STRIPE_WEBHOOK_SECRET="whsec_..."
Product and prices
Create your product and prices to offer to your customers.
-
Go to the Products catalog page.
-
Click on "Create product" and fill out the name, description and image.
-
In the pricing section of the product
- Ensure "One-off" is selected.
- Set the price to your desired price.
- Click "Add product" to finish creating the product.
-
Copy the "Product ID" and "Price ID" and add them to your
.envfile at/apps/web/.env/apps/web/.env STRIPE_PRICE_ID: "price_...", STRIPE_PRODUCT_ID: "prod_...",
Set Product metadata
We assume that you may want to potentially use the same Stripe business account for multiple products, each with different Stripe webhooks and settings. Unfortunately, Stripe does not allow partitioning webhooks by product, so we use Stripe metadata to differentiate between products.
- On your newly created product, click on the "Edit" button within the "Metadata" section.
- Create a key-value pair with the key
appIdand the value of yourappIdthat you have chosen for your project in/packages/configs/appConfig.jsunderstripe.appId.
- Create a key-value pair with the key
- Click on your flat-rate price, and add the same
appIdkey-value pair to the "Metadata" section.