Adding Stripe
DeploySolo includes a payment package that handles Stripe checkout and webhook processing. It automatically creates a paid boolean field on your users collection and updates it based on payment events.
Setup
Get Stripe credentials from your Stripe Dashboard:
- Secret Key (starts with
sk_) - Webhook Secret (starts with
whsec_) - Price ID (starts with
price_) from your product
- Secret Key (starts with
Add to
.env:STRIPE_SECRET_KEY=sk_test_... STRIPE_WEBHOOK_SECRET=whsec_... STRIPE_PRICE_ID=price_... DOMAIN_NAME=https://yourdomain.comRegister in
main.go:import ( "github.com/mannders00/deploysolo/pkg/payment" ) pb.OnServe().BindFunc(func(se *core.ServeEvent) error { payment.RegisterPayment(se, &payment.Config{ StripeSecretKey: os.Getenv("STRIPE_SECRET_KEY"), StripeWebhookSecret: os.Getenv("STRIPE_WEBHOOK_SECRET"), StripePriceID: os.Getenv("STRIPE_PRICE_ID"), DomainName: os.Getenv("DOMAIN_NAME"), LoginEndpoint: "/login", }) return se.Next() })
Usage
The package registers two routes:
- GET /checkout - Redirects logged-in users to Stripe checkout
- POST /webhook - Receives Stripe events and updates user paid status
Link to checkout from your templates:
<wa-button href="/checkout">
<wa-icon name="credit-card"></wa-icon>
Purchase Access
</wa-button>
Webhook Configuration
In your Stripe Dashboard, add a webhook endpoint pointing to https://yourdomain.com/webhook. Select events:
- checkout.session.completed
- invoice.payment_succeeded
- invoice.payment_failed
The webhook handler automatically updates the user’s paid field based on these events.
Protecting Routes
Check payment status in your handlers:
if !e.Auth.GetBool("paid") {
return e.Redirect(http.StatusSeeOther, "/checkout")
}
Or gate entire route groups using middleware. See the Creating Pages and htmx Routes section for middleware examples.