Skip to content

Go implementation for handling Stripe subscriptions in Appwrite

Notifications You must be signed in to change notification settings

alejndr0/go-subscriptions-with-stripe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔒 Go Stripe Subscriptions Function

Golang drop-in replacement for the official Node.js Stripe subscriptions template.

📋 Features

  • Create Stripe checkout sessions for subscription payments
  • Handle Stripe webhooks for subscription lifecycle events
  • Automatic user label management in Appwrite
  • Built-in error handling and logging
  • Secure endpoints with Appwrite authentication

🛠️ Setup

Prerequisites

  • Appwrite account and project
  • Stripe account with webhooks configured
  • Go 1.23 or later
  • Appwrite CLI (optional, for deployment)

Configuration Steps

  1. Create a new Appwrite function
  2. Set up the following environment variables:
APPWRITE_FUNCTION_API_ENDPOINT=<your-appwrite-endpoint>
APPWRITE_FUNCTION_PROJECT_ID=<your-project-id>
STRIPE_SECRET_KEY=<your-stripe-secret-key>
STRIPE_WEBHOOK_KEY=<your-stripe-webhook-signing-secret>
  1. Configure Stripe webhook endpoints to point to your function's /webhook endpoint
  2. Add the required webhook events in Stripe:
    • customer.subscription.created
    • customer.subscription.deleted

📚 API Documentation

POST /subscribe

Creates a new Stripe checkout session for monthly subscription payments.

Requirements:

  • User must be authenticated
  • Valid success and failure URLs must be provided

Request Body:

{
  "successUrl": "https://your-app.com/success",
  "failureUrl": "https://your-app.com/failure"
}

Success Response:

  • Redirects to Stripe checkout page (303)

Error Response:

  • Redirects to failure URL (303)

POST /webhook

Handles Stripe webhook events for subscription lifecycle management.

Supported Events:

  • customer.subscription.created: Adds "subscriber" label to user
  • customer.subscription.deleted: Removes "subscriber" label from user

Headers Required:

  • stripe-signature: Webhook signature from Stripe

🔒 Security Features

  • Authentication required for subscription creation
  • Webhook signature verification
  • Secure user ID handling
  • Environment variable configuration
  • Input validation

About

Go implementation for handling Stripe subscriptions in Appwrite

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages