Payments
This document explains how Stripe payment processing and subscription lifecycle works in ShipClojure.
Setup
- Create a new account on Stripe and activate payments (boring, I know.. see you in a bit!)
- In your Settings, Public Details, add your website URL
- In your Settings, Branding, add your logo & colors
- In your Settings, Customer Emails, turn on emails for successful payments & refunds
- In your Settings, Customer Portal, activate link to customer portal (in case you need later)
- In the search box, type 'rules' and click Fraud Prevention > Rules, make sure the first 3DS rule is enabled. I also turn on the second one (recommended). Make sure to block payments if CVC fails (check below)
- Create a test sandbox - this is useful to test all of the purchasing flows without spending money
- Create a new product and copy the price ID (
price_1ju5GD464564) in the Stripe configuration - In your Developers, copy your Secret key to
resources/.secrets.edn - :stripe > :api-key - To set up the webhook locally, follow the steps in Developers, Webhook, Test in local environment. After login to Stripe CLI (it's installed with mise), use this command to forward webhook events to our API:
stripe listen --forward-to localhost:8080/api/webhook/stripe
Copy the signing secret and add it to your secrets configuration (resources/.secrets.edn - :stripe > :webhook-signing-secret)
Going to production?
- If you have created products in the test sandbox, on the options for that product there is a option
Copy to Live Mode. Click that - Turn OFF Test Mode in your Stripe Dashboard
- In your Developers, copy your public & private keys and add them to your production environment variables
- In your Developers, Webhook, Add Endpoint. Set your domain +
/api/webhook/stripe. Select checkout.session.completed event (or more if needed). Copy the signing secret and add it to your production environment variables - Optional: In Balance, Manage Payouts, set a specific date of the month to receive your payouts (I use the 10th of each month)
- Optional: In Settings, Customer Emails, activate emails for successful payments & refunds
Create a checkout
From the front-end, use the checkout component to automatically create a checkout session (one-time payment or subscription).
Stripe webhooks & subscription handling
Our API listens to Stripe selected webhook events & updates the user accordingly. It turns boolean has-access to true/false based on whether the user should have access to a paid resource or not.
You can add your own business logic to the /api/webhook/stripe endpoint (add credits to a user, send email with a paid e-book etc.)