Stripe
The Stripe extension connects Billing to Stripe. Buyers pay on Stripe Checkout, Stripe's webhooks keep Billing's items current, and users manage cards and invoices in Stripe's Customer Portal.
With Managed Payments on (the default), Stripe sells as merchant of record: it collects and files sales tax and VAT and handles disputes. Turn it off to sell under your own Stripe account.
Install
Add it to your build next to Billing (Add Billing to your app):
set.Add(billing.New(billing.Config{}), stripe.New(stripe.Config{}))
The module is pocketone.dev/ext/stripe.
Keys
In the dashboard, open Billing → Settings. Stripe's section is below Billing's own.
| Setting | Where to find it |
|---|---|
| Secret key | Stripe's Developers → API keys. A test key (sk_test_) uses Stripe's sandbox. A restricted key (rk_) works when it can write Checkout Sessions, subscriptions and refunds and read prices, customers, invoices and payments. |
| Webhook signing secret | The whsec_ secret of the webhook endpoint below. |
| Managed Payments | Stripe is merchant of record for new checkouts. Subscriptions that started without it renew as they are. |
Press Test to check the key, then Save changes.
Webhooks
In Stripe, add a webhook endpoint (Developers → Webhooks) at the URL shown in Stripe's settings section:
<your app>/api/_c/billing/v1/webhook?provider=stripe. Send these events:
checkout.session.completed,checkout.session.async_payment_succeededcustomer.subscription.created,customer.subscription.updated,customer.subscription.deleted,customer.subscription.paused,customer.subscription.resumedinvoice.paid,invoice.payment_failedcharge.refunded,charge.dispute.created,charge.dispute.closed
Paste the endpoint's signing secret into the settings.
Try it on your machine
The Stripe CLI forwards a sandbox's webhooks to your local app:
stripe login
stripe listen --forward-to 'localhost:8090/api/_c/billing/v1/webhook?provider=stripe' \
--events checkout.session.completed,checkout.session.async_payment_succeeded,customer.subscription.created,customer.subscription.updated,customer.subscription.deleted,customer.subscription.paused,customer.subscription.resumed,invoice.paid,invoice.payment_failed,charge.refunded,charge.dispute.created,charge.dispute.closed
It prints a whsec_ signing secret to paste into the settings (stripe listen --print-secret shows it again). Use a
test key, start a checkout, and pay with card 4242 4242 4242 4242, any future date and any CVC.
Products
In Stripe, make a product with a price: recurring for a subscription product, one-time for an order. On Billing →
Products, set the product's prices to the price id: {"stripe": "price_..."}. Check prices confirms it.
What Billing's calls do at Stripe
| Billing | Stripe |
|---|---|
checkout |
A Checkout Session for the product's price and quantity. A returning buyer's Stripe customer is reused. |
portal |
A Customer Portal session. Set up the portal once under Settings → Billing → Customer portal in Stripe. |
cancel, resume |
Cancels at the period end or now; clears a scheduled cancel. |
quantity, plan |
Updates the subscription's item, prorated as asked. |
refund |
Refunds a one-time purchase, or a subscription's latest paid invoice, in full or in part. |
A one-time purchase is its PaymentIntent (pi_...). A subscription in Stripe's incomplete or unpaid state grants
nothing until it's paid.
The extension's reference is on its extension page.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.