Coder Social home page Coder Social logo

saurabharch / stripe-sync-engine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supabase/stripe-sync-engine

0.0 1.0 0.0 1.54 MB

Sync your Stripe account to you Postgres database.

Home Page: https://supabase.com

License: Apache License 2.0

JavaScript 0.73% Dockerfile 0.36% TypeScript 94.94% PLpgSQL 3.97%

stripe-sync-engine's Introduction

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
  • 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
  • Point your Stripe webooks to your deployed app.

Backfill from Stripe

POST /sync
body: {
  "object": "product",
  "created": {
    "gte": 1643872333
  }
}
  • object all | customer | invoice | price | product | subscription
  • created is Stripe.RangeQueryParam. It supports gt, gte, lt, lte

Alternative routes to sync daily/weekly/monthly data

POST /sync/daily

---

POST /sync/daily
body: {
  "object": "product"
}

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 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

stripe-sync-engine's People

Contributors

kiwicopple avatar phamhieu avatar soedirgo avatar egor-romanov avatar darora avatar iamshankhadeep avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.