imomin / stripe-sync-engine

Sync your Stripe account to you Postgres database.

Home Page:https://supabase.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stripe Sync Engine (Experimental)

Continuously synchronizes a Stripe account to a Postgres database.

Note: this is experimental. There are no guarantees that it will be supported in the future.

Sync Stripe with Postgres

Motivation

Sometimes you want to analyze your billing data using SQL. Even more importantly, you want to join your billing data to your product/business data.

This server synchronizes your Stripe account to a Postgres database. It can be a new database, or an existing Postgres database.

How it works

How it works

  • Creates a new schema stripe in a Postgres database, with tables & columns matching Stripe.
  • Exposes a /webhooks endpoint that listens to any Stripe webhooks.
  • Inserts/updates/deletes changes into the tables whenever there is a change to Stripe.

Not implemented

  • This will not do an initial load of existing Stripe data. You should use CSV loads for this. We might implement this in the future.
  • We are progressively working through webhooks.

Webhook Progress

  • balance.available
  • charge.captured
  • charge.dispute.created
  • charge.failed
  • charge.refunded
  • charge.succeeded
  • checkout.session.async_payment_failed
  • checkout.session.async_payment_succeeded
  • checkout.session.completed
  • customer.created 🟒
  • customer.deleted
  • customer.source.created
  • customer.source.updated
  • customer.subscription.created 🟒
  • customer.subscription.deleted 🟒
  • customer.subscription.updated 🟒
  • customer.updated 🟒
  • invoice.created 🟒
  • invoice.finalized 🟒
  • invoice.paid 🟒
  • invoice.payment_failed 🟒
  • invoice.payment_succeeded 🟒
  • invoice.updated 🟒
  • issuing_authorization.request
  • issuing_card.created
  • issuing_cardholder.created
  • payment_intent.amount_capturable_updated
  • payment_intent.canceled
  • payment_intent.created
  • payment_intent.payment_failed
  • payment_intent.succeeded
  • payment_method.attached
  • plan.created
  • plan.deleted
  • plan.updated
  • price.created 🟒
  • price.deleted 🟒
  • price.updated 🟒
  • product.created 🟒
  • product.deleted 🟒
  • product.updated 🟒
  • setup_intent.canceled
  • setup_intent.created
  • setup_intent.setup_failed
  • setup_intent.succeeded
  • subscription_schedule.canceled
  • subscription_schedule.created
  • subscription_schedule.released
  • subscription_schedule.updated

Usage

  • Update your Stripe account with all valid webhooks and get the webhook secret
  • mv .env.sample .env and then rename all the variables
  • Make sure the database URL has search_path stripe. eg: DATABASE_URL=postgres://postgres:postgres@hostname:5432/postgres?sslmode=disable&search_path=stripe
  • Run dbmate up
  • Deploy the docker image to your favourite hosting service and expose port 8080
  • Point your Stripe webooks to your deployed app.

Future ideas

  • Expose a "sync" endpoint for each table which will manually fetch and sync from Stripe.
  • Expose an "initialize" endpoint that will fetch data from Stripe and do an initial load (or perhaps POST a CSV to an endpoint).

Development

Set up

  • Create a Postgres database on supabase.com (or another Postgres provider)
  • Update Stripe with all valid webhooks and get the webhook secret
  • mv .env.sample .env and then rename all the variables
  • run dbmate up to run all the database migrations

Develop

  • npm run dev to start the local server
  • npm run test to run tests

Building Docker

docker build -t stripe-sync-engine .
docker run -p 8080:8080 stripe-sync-engine

Release

Handled by GitHub actions whenever their is a commit to the main branch with fix or feat in the description.

License

Apache 2.0

Sponsors

Supabase is building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves.

New Sponsor

About

Sync your Stripe account to you Postgres database.

https://supabase.com

License:Apache License 2.0


Languages

Language:TypeScript 97.6%Language:JavaScript 1.6%Language:Dockerfile 0.8%