Payments
Choose between Stripe, or Lemon Squeezy (not implemented)
Configuration
This choice can be made using the GoFast CLI or by modifying the docker-compose.yml
file.
via CLI
Possible options are Stripe
, Lemon Squeezy
and Local (mock)
.
via Docker Compose
Possible options are stripe
, lemon
and local
.
Payments Configuration
Depending on the provider, you need to set the following environment variables in the docker-compose.yml
file:
- for
stripe
, setSTRIPE_API_KEY
andSTRIPE_PRICE_ID
. - for
lemon
, setLEMON_API_KEY
,LEMON_VARIANT_ID
andLEMON_STORE_ID
. - for
local
, no configuration is needed.
Implementation Details
The payments implementation can generate the client Checkout Session to process payments, the Customer Portal to check invoices, and includes a Webhook implementation to listen for changes. The flow is as follows:
- The user clicks the subscribe button, sending a request to the backend.
- The backend generates a Checkout URL.
- The user completes the order.
- A webhook on the backend listens for changes and updates the client’s status accordingly.
- After the client is created in the payment provider, they can visit their customer portal to check all invoices.
The local provider is a mock implementation that doesn’t require any configuration. It generates a random customer ID and subscription end date.
Webhook
Since the webhook needs to listen for changes, the gRPC configuration still includes an HTTP server.
The payments webhook has a separate file for HTTP routes: /http/route_webhook.go
.
Regardless of the provider, remember to set up the webhook URL in the provider’s dashboard, pointing to the /payments/webhook
route.
To test Stripe webhook locally, you can use the Stripe CLI, authenticate, and forward the events to the local server:
Lemon Squeezy doesn’t have a CLI, so you need to set up a tunnel to forward the events to the local server. One option is Cloudflare Tunnel.
Adding a New Provider
To add a new provider, follow these steps in the /payment/provider.go
file:
- Add the new provider to the
Provider
constant.
- Create a new provider struct.
- Return the new provider in the
NewProvider
function:
- Implement the required methods:
-
Add any new secrets in the
env.go
file. -
Fill in the
docker-compose.yml
file with the new provider configuration.
Getting Secrets
Stripe
To get the STRIPE_API_KEY
and STRIPE_PRICE_ID
, you need to create an account on the Stripe website and get the keys from the dashboard.
- Go to the Stripe Api Section.
- Copy the
Secret Key
and set it as theSTRIPE_API_KEY
. - Create a new product and price in the Products section.
- Go to the
Prices
tab and create a new price. - Go to the price details.
- Copy the
Price ID
and set it as theSTRIPE_PRICE_ID
.
Lemon Squeezy
To get the LEMON_API_KEY
, LEMON_VARIANT_ID
and LEMON_STORE_ID
, you need to create an account on the Lemon Squeezy website and get the keys from the dashboard.
- Go to the Lemon Squeezy Api Section.
- Create a new API key and set it as the
LEMON_API_KEY
. - Create a new product on the Products section.
- On the list, open the dropdown and click on
Copy variant ID
. Set it as theLEMON_VARIANT_ID
. - Go to the Stores section, where you can find the
Store ID
. Set it as theLEMON_STORE_ID
.
Need help?
Visit our discord server to ask any questions, make suggestions and give feedback :).