Backend API for a pay-to-rank leaderboard in Go, using PostgreSQL and Stripe.
- Set PostgreSQL DSN in
DATABASE_URL. - Set
STRIPE_SECRET_KEY. - Run:
./start.shServer starts on http://localhost:8080.
DATABASE_URL=postgres://postgres:postgres@localhost:5432/paywall?sslmode=disable
STRIPE_SECRET_KEY=sk_test_xxxPORT=8080
FRONTEND_ORIGIN=http://localhost:3000
STRIPE_WEBHOOK_SECRET=whsec_xxx
DB_MAX_OPEN_CONNS=20
DB_MAX_IDLE_CONNS=5
DB_CONN_MAX_LIFETIME_MIN=30GET /healthGET /leaderboardPOST /pay(compat route; delegates to create payment intent)POST /create-payment-intentPOST /pay/confirmPOST /webhookGET /totalGET /ws
Request body:
{
"name": "Username",
"link": "https://twitter.com/user",
"email": "user@example.com",
"amount_cents": 5000
}Response:
{
"clientSecret": "pi_xxx_secret_xxx",
"paymentIntentId": "pi_xxx"
}- Configure Stripe webhook URL to
POST /webhook. - If
STRIPE_WEBHOOK_SECRETis set, signature validation is enforced. - Webhook events are idempotent via the
webhook_eventstable.
go run tools/run_migrations.gogo run tools/inspect_db.gogo run tools/insert_payment.gogo run tools/clear_payments.go