Stripe
Stripe is an API driven online payment processing utility. supabase/wrappers
exposes below endpoints.
Warning
Restoring a logical backup of a database with a materialized view using a foreign table can fail. For this reason, either do not use foreign tables in materialized views or use them in databases with physical backups enabled.
Preparation
Before you can query Stripe, you need to enable the Wrappers extension and store your credentials in Postgres.
Enable Wrappers
Make sure the wrappers
extension is installed on your database:
1 |
|
Enable the Stripe Wrapper
Enable the stripe_wrapper
FDW:
1 2 3 |
|
Store your credentials
We need to provide Postgres with the credentials to connect to Stripe, and any additional options. We can do this using the create server
command:
1 2 3 4 5 6 7 |
|
By default, Postgres stores FDW credentials inside pg_catalog.pg_foreign_server
in plain text. Anyone with access to this table will be able to view these credentials.
Wrappers is designed to work with Vault, which provides an additional level of security for storing credentials. We recommend using Vault to store your credentials.
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 |
|
Create a schema
We recommend creating a schema to hold all the foreign tables:
1 |
|
Creating Foreign Tables
The Stripe Wrapper supports data read and modify from Stripe API.
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Accounts | ✅ | ❌ | ❌ | ❌ | ❌ |
Balance | ✅ | ❌ | ❌ | ❌ | ❌ |
Balance Transactions | ✅ | ❌ | ❌ | ❌ | ❌ |
Charges | ✅ | ❌ | ❌ | ❌ | ❌ |
Checkout Sessions | ✅ | ❌ | ❌ | ❌ | ❌ |
Customers | ✅ | ✅ | ✅ | ✅ | ❌ |
Disputes | ✅ | ❌ | ❌ | ❌ | ❌ |
Events | ✅ | ❌ | ❌ | ❌ | ❌ |
Files | ✅ | ❌ | ❌ | ❌ | ❌ |
File Links | ✅ | ❌ | ❌ | ❌ | ❌ |
Invoices | ✅ | ❌ | ❌ | ❌ | ❌ |
Mandates | ✅ | ❌ | ❌ | ❌ | ❌ |
PaymentIntents | ✅ | ❌ | ❌ | ❌ | ❌ |
Payouts | ✅ | ❌ | ❌ | ❌ | ❌ |
Prices | ✅ | ❌ | ❌ | ❌ | ❌ |
Products | ✅ | ✅ | ✅ | ✅ | ❌ |
Refunds | ✅ | ❌ | ❌ | ❌ | ❌ |
SetupAttempts | ✅ | ❌ | ❌ | ❌ | ❌ |
SetupIntents | ✅ | ❌ | ❌ | ❌ | ❌ |
Subscriptions | ✅ | ✅ | ✅ | ✅ | ❌ |
Tokens | ✅ | ❌ | ❌ | ❌ | ❌ |
Topups | ✅ | ❌ | ❌ | ❌ | ❌ |
Transfers | ✅ | ❌ | ❌ | ❌ | ❌ |
The Stripe foreign tables mirror Stripe's API.
We can then create the foreign table, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
attrs
is a special column which stores all the object attributes in JSON format, you can extract any attributes needed or its associated sub objects from it. See more examples below.
Accounts
This is an object representing a Stripe account.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Accounts | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Notes
- While any column is allowed in a where clause, it is most efficient to filter by
id
.
Balance
read only
Shows the balance currently on your Stripe account.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 |
|
Balance Transactions
read only
Balance transactions represent funds moving through your Stripe account. They're created for every type of transaction that comes into or flows out of your Stripe account balance.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- type
Charges
read only
To charge a credit or a debit card, you create a Charge object. You can retrieve and refund individual charges as well as list all charges. Charges are identified by a unique, random ID.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
Checkout Sessions
read only
A Checkout Session represents your customer's session as they pay for one-time purchases or subscriptions through Checkout or Payment Links. We recommend creating a new Session each time your customer attempts to pay.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- payment_intent
- subscription
Customers
read and modify
Contains customers known to Stripe.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
Disputes
read only
A dispute occurs when a customer questions your charge with their card issuer.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- charge
- payment_intent
Events
read only
Events are our way of letting you know when something interesting happens in your account.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- type
Files
read only
This is an object representing a file hosted on Stripe's servers.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- purpose
File Links
read only
To share the contents of a File
object with non-Stripe users, you can create a FileLink
.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Invoices
read only
Invoices are statements of amounts owed by a customer, and are either generated one-off, or generated periodically from a subscription.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- status
- subscription
Mandates
read only
A Mandate is a record of the permission a customer has given you to debit their payment method.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
Payment Intents
read only
A payment intent guides you through the process of collecting a payment from your customer.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
Payouts
read only
A Payout
object is created when you receive funds from Stripe, or when you initiate a payout to either a bank account or debit card of a connected Stripe account.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- status
Prices
read only
A Price
object is needed for all of your products to facilitate multiple currencies and pricing options.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- active
Products
read and modify
All products available in Stripe.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- active
Refunds
read only
Refund
objects allow you to refund a charge that has previously been created but not yet refunded.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- charge
- payment_intent
SetupAttempts
read only
A SetupAttempt
describes one attempted confirmation of a SetupIntent, whether that confirmation was successful or unsuccessful.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- setup_intent
SetupIntents
read only
A SetupIntent
guides you through the process of setting up and saving a customer's payment credentials for future payments.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- payment_method
Subscriptions
read and modify
Customer recurring payment schedules.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- price
- status
Tokens
read only
Tokenization is the process Stripe uses to collect sensitive card or bank account details, or personally identifiable information (PII), directly from your customers in a secure manner.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Top-ups
read only
To top up your Stripe balance, you create a top-up object.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- status
Transfers
read only
A Transfer object is created when you move funds between Stripe accounts as part of Connect.
Ref: Stripe docs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
While any column is allowed in a where clause, it is most efficient to filter by:
- id
- destination
Query Pushdown Support
This FDW supports where
clause pushdown. You can specify a filter in where
clause and it will be passed to Stripe API call.
For example, this query
1 |
|
will be translated Stripe API call: https://api.stripe.com/v1/customers/cus_xxx
.
For supported filter columns for each object, please check out foreign table documents above.
Examples
Some examples on how to use Stripe foreign tables.
Basic example
1 2 3 4 |
|
Query JSON attributes
1 2 3 4 5 6 7 8 9 10 11 |
|
Data modify
1 2 3 4 |
|
To insert into an object with sub-fields, we need to create the foreign table with column name exactly same as the API required. For example, to insert a subscription
object we can define the foreign table following the Stripe API docs:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
And then we can insert a subscription like below:
1 2 |
|
Note this foreign table is only for data insertion, it cannot be used in select
statement.