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.
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
- 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.expired
π’ -
charge.failed
π’ -
charge.pending
π’ -
charge.refunded
π’ -
charge.succeeded
π’ -
charge.updated
π’ -
charge.dispute.closed
π’ -
charge.dispute.created
π’ -
charge.dispute.funds_reinstated
π’ -
charge.dispute.funds_withdrawn
π’ -
charge.dispute.updated
π’ -
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.paused
π’ -
customer.subscription.pending_update_applied
π’ -
customer.subscription.pending_update_expired
π’ -
customer.subscription.resumed
π’ -
customer.subscription.updated
π’ -
customer.updated
π’ -
invoice.created
π’ -
invoice.deleted
π’ -
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.partially_refunded
π’ -
payment_intent.payment_failed
π’ -
payment_intent.processing
π’ -
payment_intent.requires_action
π’ -
payment_intent.succeeded
π’ -
payment_method.attached
π’ -
payment_method.automatically_updated
π’ -
payment_method.detached
π’ -
payment_method.updated
π’ -
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.requires_action
π’ -
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
- Deploy the docker image to your favourite hosting service and expose port
8080
- eg:
docker run -e PORT=8080 --env-file .env supabase/stripe-sync-engine
- This will automatically run any migrations on your database
- eg:
- Point your Stripe webooks to your deployed app.
Backfill from Stripe
POST /sync
body: {
"object": "product",
"created": {
"gte": 1643872333
}
}
object
all | charge | customer | dispute | invoice | payment_method | payment_intent | plan | price | product | setup_intent | subscriptioncreated
is Stripe.RangeQueryParam. It supports gt, gte, lt, lte
daily/weekly/monthly
data
Alternative routes to sync POST /sync/daily
---
POST /sync/daily
body: {
"object": "product"
}
Syncing single entity
To backfill/update a single entity, you can use
POST /sync/single/cus_12345
The entity type is recognized automatically, based on the prefix.
Future ideas
- 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
Develop
npm run dev
to start the local servernpm 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.