lawrencecchen / stripe-sync

Home Page:stripe-sync.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stripe Sync

Sync Stripe webhook events directly into your database.

  • ✅ Automatically verify webhook signatures
  • ✅ Webhook callbacks
  • ✅ Sync every Stripe webhook to database tables

Note: this is experimental. Stuff might be broken.

Setup

Detailed setup instructions can be found here:

https://stripe-sync.vercel.app/

Supabase

Synced Webhook events may contain sensitive information. Make sure to access this data using a service role Supabase client in a protected server environment.

Add stripe schema:

Grant service role permissions

grant usage on schema stripe to service_role;
grant all privileges on all tables in schema stripe to service_role;

Deploy

Make sure to pass the --no-verify-jwt flat, since we want Stripe to be able to give us POST reqeusts.

supabase functions deploy stripe --no-verify-jwt
supabase secrets set --env-file ./supabase/.env

Adapters

** Work in progress. Only Deno/Supabase Edge Functions are documented right now **

https://github.com/hattipjs/hattip

  • ✅ Supabase Edge Functions
  • ✅ Deno (including Deno Deploy)
  • ✅ Node.js
  • ✅ Cloudflare Workers
  • ✅ Express.js
  • ✅ Fastify
  • ✅ Vercel Serverless Functions
  • ✅ Vercel Edge Functions
  • ✅ Netlify Functions
  • ✅ Netlify Edge Functions
  • ✅ Bun

Limitations

Supabase-js cannot do cross schema joins. This may change, but in the meantime your options are:

  1. put all stripe tables in public (with a stripe_ prefix)
  2. use another database client (eg. Kysely)

Additionally, the Supabase Studio dashboard/table editor becomes very slow for large numbers of tables.

  • for now, stripe-sync only works on the 2022-08-01 api version.

Prior Work

This project is inspired by all of the projects listed below.

Todos

  • make ids primary keys
  • automatically register webhooks with stripe
  • stripe_ prefix ddl option
  • webhook callback functions on for custom logic
  • implement all stripe best practices
  • next.js adapter
  • fetch adapter (remix/cloudflare/deno/bun)
  • add tests
  • add resync
  • add relations
  • fix external accounts

Tests

Currently tested on every trigger supported by the Stripe CLI.

More robust tests coming soon.

License

MIT

Copyright (c) 2022-present, Lawrence Chen

About

stripe-sync.vercel.app

License:MIT License


Languages

Language:TypeScript 100.0%