Database

Stripe


Stripe is an API driven online payment processing utility.

The Stripe Wrapper allows you to read data from Stripe within your Postgres database.

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:


_10
create extension if not exists wrappers with schema extensions;

Enable the Stripe Wrapper

Enable the stripe_wrapper FDW:


_10
create foreign data wrapper stripe_wrapper
_10
handler stripe_fdw_handler
_10
validator stripe_fdw_validator;

Store your credentials (optional)

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.


_10
-- Save your Stripe API key in Vault and retrieve the `key_id`
_10
insert into vault.secrets (name, secret)
_10
values (
_10
'stripe',
_10
'<Stripe API key>'
_10
)
_10
returning key_id;

Connecting to Stripe

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:


_10
create server stripe_server
_10
foreign data wrapper stripe_wrapper
_10
options (
_10
api_key_id '<key_ID>', -- The Key ID from above, required if api_key_name is not specified.
_10
api_key_name '<key_Name>', -- The Key Name from above, required if api_key_id is not specified.
_10
api_url 'https://api.stripe.com/v1/', -- Stripe API base URL, optional. Default is 'https://api.stripe.com/v1/'
_10
api_version '2024-06-20' -- Stripe API version, optional. Default is your Stripe account’s default API version.
_10
);

Create a schema

We recommend creating a schema to hold all the foreign tables:


_10
create schema if not exists stripe;

Entities

The Stripe Wrapper supports data read and modify from Stripe API.

ObjectSelectInsertUpdateDeleteTruncate
Accounts
Balance
Balance Transactions
Charges
Checkout Sessions
Customers
Disputes
Events
Files
File Links
Invoices
Mandates
Meters
PaymentIntents
Payouts
Prices
Products
Refunds
SetupAttempts
SetupIntents
Subscriptions
Tokens
Topups
Transfers

Accounts

This is an object representing a Stripe account.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Accounts

Usage


_13
create foreign table stripe.accounts (
_13
id text,
_13
business_type text,
_13
country text,
_13
email text,
_13
type text,
_13
created timestamp,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'accounts'
_13
);

Notes

  • While any column is allowed in a where clause, it is most efficient to filter by id
  • Use the attrs jsonb column to access additional account details

Balance

This is an object representing your Stripe account's current balance.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Balance

Usage


_10
create foreign table stripe.balance (
_10
balance_type text,
_10
amount bigint,
_10
currency text,
_10
attrs jsonb
_10
)
_10
server stripe_server
_10
options (
_10
object 'balance'
_10
);

Notes

  • Balance is a read-only object that shows the current funds in your Stripe account
  • The balance is broken down by source types (e.g., card, bank account) and currencies
  • Use the attrs jsonb column to access additional balance details like pending amounts
  • While any column is allowed in a where clause, filtering options are limited as this is a singleton object

Balance Transactions

This is an object representing funds moving through your Stripe account. Balance transactions are created for every type of transaction that comes into or flows out of your Stripe account balance.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Balance Transactions

Usage


_16
create foreign table stripe.balance_transactions (
_16
id text,
_16
amount bigint,
_16
currency text,
_16
description text,
_16
fee bigint,
_16
net bigint,
_16
status text,
_16
type text,
_16
created timestamp,
_16
attrs jsonb
_16
)
_16
server stripe_server
_16
options (
_16
object 'balance_transactions'
_16
);

Notes

  • Balance transactions are read-only records of all funds movement in your Stripe account
  • Each transaction includes amount, currency, fees, and net amount information
  • Use the attrs jsonb column to access additional transaction details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • type

Charges

This is an object representing a charge on a credit or debit card. You can retrieve and refund individual charges as well as list all charges. Charges are identified by a unique, random ID.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Charges

Usage


_16
create foreign table stripe.charges (
_16
id text,
_16
amount bigint,
_16
currency text,
_16
customer text,
_16
description text,
_16
invoice text,
_16
payment_intent text,
_16
status text,
_16
created timestamp,
_16
attrs jsonb
_16
)
_16
server stripe_server
_16
options (
_16
object 'charges'
_16
);

Notes

  • Charges are read-only records of payment transactions in your Stripe account
  • Each charge includes amount, currency, customer, and payment status information
  • Use the attrs jsonb column to access additional charge details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • customer

Checkout Sessions

This is an object representing 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

Operations

ObjectSelectInsertUpdateDeleteTruncate
Checkout Sessions

Usage


_12
create foreign table stripe.checkout_sessions (
_12
id text,
_12
customer text,
_12
payment_intent text,
_12
subscription text,
_12
attrs jsonb
_12
)
_12
server stripe_server
_12
options (
_12
object 'checkout/sessions',
_12
rowid_column 'id'
_12
);

Notes

  • Checkout Sessions are read-only records of customer payment sessions in your Stripe account
  • Each session includes customer, payment intent, and subscription information
  • Use the attrs jsonb column to access additional session details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • customer
    • payment_intent
    • subscription

Customers

This is an object representing your Stripe customers. You can create, retrieve, update, and delete customers.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Customers

Usage


_13
create foreign table stripe.customers (
_13
id text,
_13
email text,
_13
name text,
_13
description text,
_13
created timestamp,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'customers',
_13
rowid_column 'id'
_13
);

Example operations:


_12
-- create a new customer
_12
insert into stripe.customers(email, name, description)
_12
values ('jane@example.com', 'Jane Smith', 'Premium customer');
_12
_12
-- update a customer
_12
update stripe.customers
_12
set name = 'Jane Doe'
_12
where email = 'jane@example.com';
_12
_12
-- delete a customer
_12
delete from stripe.customers
_12
where id = 'cus_xxx';

Notes

  • Customers can be created, retrieved, updated, and deleted through SQL operations
  • Each customer can have an email, name, and description
  • Use the attrs jsonb column to access additional customer details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • email

Disputes

This is an object representing a dispute that occurs when a customer questions your charge with their card issuer.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Disputes

Usage


_15
create foreign table stripe.disputes (
_15
id text,
_15
amount bigint,
_15
currency text,
_15
charge text,
_15
payment_intent text,
_15
reason text,
_15
status text,
_15
created timestamp,
_15
attrs jsonb
_15
)
_15
server stripe_server
_15
options (
_15
object 'disputes'
_15
);

Notes

  • Disputes are read-only records of customer payment disputes in your Stripe account
  • Each dispute includes amount, currency, charge, and payment intent information
  • Use the attrs jsonb column to access additional dispute details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • charge
    • payment_intent

Events

This is an object representing events that occur in your Stripe account, letting you know when something interesting happens.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Events

Usage


_11
create foreign table stripe.events (
_11
id text,
_11
type text,
_11
api_version text,
_11
created timestamp,
_11
attrs jsonb
_11
)
_11
server stripe_server
_11
options (
_11
object 'events'
_11
);

Notes

  • Events are read-only records of activities in your Stripe account
  • Each event includes type, API version, and timestamp information
  • Use the attrs jsonb column to access additional event details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • type

Files

This is an object representing a file hosted on Stripe's servers.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Files

Usage


_16
create foreign table stripe.files (
_16
id text,
_16
filename text,
_16
purpose text,
_16
title text,
_16
size bigint,
_16
type text,
_16
url text,
_16
created timestamp,
_16
expires_at timestamp,
_16
attrs jsonb
_16
)
_16
server stripe_server
_16
options (
_16
object 'files'
_16
);

Notes

  • Files are read-only records of files hosted on Stripe's servers
  • Each file includes filename, purpose, size, type, and URL information
  • Files may have an expiration date specified in expires_at
  • Use the attrs jsonb column to access additional file details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • purpose

This is an object representing a link that can be used to share the contents of a File object with non-Stripe users.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
File Links

Usage


_13
create foreign table stripe.file_links (
_13
id text,
_13
file text,
_13
url text,
_13
created timestamp,
_13
expired bool,
_13
expires_at timestamp,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'file_links'
_13
);

Notes

  • File Links are read-only records that provide shareable access to Stripe files
  • Each link includes a reference to the file and a public URL
  • Links can be configured to expire at a specific time
  • Use the expired boolean to check if a link has expired
  • Use the attrs jsonb column to access additional link details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • file

Invoices

This is an object representing statements of amounts owed by a customer, which are either generated one-off or periodically from a subscription.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Invoices

Usage


_15
create foreign table stripe.invoices (
_15
id text,
_15
customer text,
_15
subscription text,
_15
status text,
_15
total bigint,
_15
currency text,
_15
period_start timestamp,
_15
period_end timestamp,
_15
attrs jsonb
_15
)
_15
server stripe_server
_15
options (
_15
object 'invoices'
_15
);

Notes

  • Invoices are read-only records of amounts owed by customers
  • Each invoice includes customer, subscription, status, and amount information
  • Invoices track billing periods with period_start and period_end timestamps
  • Use the attrs jsonb column to access additional invoice details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • customer
    • status
    • subscription

Mandates

This is an object representing a record of the permission a customer has given you to debit their payment method.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Mandates

Usage


_11
create foreign table stripe.mandates (
_11
id text,
_11
payment_method text,
_11
status text,
_11
type text,
_11
attrs jsonb
_11
)
_11
server stripe_server
_11
options (
_11
object 'mandates'
_11
);

Notes

  • Mandates are read-only records of customer payment permissions
  • Each mandate includes payment method, status, and type information
  • Use the attrs jsonb column to access additional mandate details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id

Meters

This is an object representing a billing meter that allows you to track usage of a particular event.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Meters

Usage


_12
create foreign table stripe.meter (
_12
id text,
_12
display_name text,
_12
event_name text,
_12
event_time_window text,
_12
status text,
_12
attrs jsonb
_12
)
_12
server stripe_server
_12
options (
_12
object 'billing/meters'
_12
);

Notes

  • Meters are read-only records for tracking event usage in billing
  • Each meter includes display name, event name, and time window information
  • The status field indicates whether the meter is active
  • Use the attrs jsonb column to access additional meter details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id

Payment Intents

This is an object representing a guide through the process of collecting a payment from your customer.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Payment Intents

Usage


_13
create foreign table stripe.payment_intents (
_13
id text,
_13
customer text,
_13
amount bigint,
_13
currency text,
_13
payment_method text,
_13
created timestamp,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'payment_intents'
_13
);

Notes

  • Payment Intents are read-only records that guide the payment collection process
  • Each intent includes customer, amount, currency, and payment method information
  • The created timestamp tracks when the payment intent was initiated
  • Use the attrs jsonb column to access additional payment intent details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • customer

Payouts

This is an object representing funds received from Stripe or initiated payouts to a bank account or debit card of a connected Stripe account.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Payouts

Usage


_15
create foreign table stripe.payouts (
_15
id text,
_15
amount bigint,
_15
currency text,
_15
arrival_date timestamp,
_15
description text,
_15
statement_descriptor text,
_15
status text,
_15
created timestamp,
_15
attrs jsonb
_15
)
_15
server stripe_server
_15
options (
_15
object 'payouts'
_15
);

Notes

  • Payouts are read-only records of fund transfers
  • Each payout includes amount, currency, and status information
  • The arrival_date indicates when funds will be available
  • The statement_descriptor appears on your bank statement
  • Use the attrs jsonb column to access additional payout details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • status

Prices

This is an object representing pricing configurations for products to facilitate multiple currencies and pricing options.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Prices

Usage


_14
create foreign table stripe.prices (
_14
id text,
_14
active bool,
_14
currency text,
_14
product text,
_14
unit_amount bigint,
_14
type text,
_14
created timestamp,
_14
attrs jsonb
_14
)
_14
server stripe_server
_14
options (
_14
object 'prices'
_14
);

Notes

  • Prices are read-only records that define product pricing configurations
  • Each price includes currency, unit amount, and product reference
  • The active boolean indicates if the price can be used
  • The type field specifies the pricing model (e.g., one-time, recurring)
  • Use the attrs jsonb column to access additional price details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • active

Products

This is an object representing all products available in Stripe.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Products

Usage


_15
create foreign table stripe.products (
_15
id text,
_15
name text,
_15
active bool,
_15
default_price text,
_15
description text,
_15
created timestamp,
_15
updated timestamp,
_15
attrs jsonb
_15
)
_15
server stripe_server
_15
options (
_15
object 'products',
_15
rowid_column 'id'
_15
);

Notes

  • Products can be created, read, updated, and deleted
  • Each product includes name, description, and active status
  • The default_price links to the product's default Price object
  • The updated timestamp tracks the last modification time
  • Use the attrs jsonb column to access additional product details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • active

Refunds

This is an object representing refunds for charges that have previously been created but not yet refunded.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Refunds

Usage


_15
create foreign table stripe.refunds (
_15
id text,
_15
amount bigint,
_15
currency text,
_15
charge text,
_15
payment_intent text,
_15
reason text,
_15
status text,
_15
created timestamp,
_15
attrs jsonb
_15
)
_15
server stripe_server
_15
options (
_15
object 'refunds'
_15
);

Notes

  • Refunds are read-only records of charge reversals
  • Each refund includes amount, currency, and status information
  • The charge and payment_intent fields link to the original transaction
  • The reason field provides context for the refund
  • Use the attrs jsonb column to access additional refund details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • charge
    • payment_intent

SetupAttempts

This is an object representing attempted confirmations of SetupIntents, tracking both successful and unsuccessful attempts.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
SetupAttempts

Usage


_16
create foreign table stripe.setup_attempts (
_16
id text,
_16
application text,
_16
customer text,
_16
on_behalf_of text,
_16
payment_method text,
_16
setup_intent text,
_16
status text,
_16
usage text,
_16
created timestamp,
_16
attrs jsonb
_16
)
_16
server stripe_server
_16
options (
_16
object 'setup_attempts'
_16
);

Notes

  • SetupAttempts are read-only records of payment setup confirmation attempts
  • Each attempt includes customer, payment method, and status information
  • The setup_intent field links to the associated SetupIntent
  • The usage field indicates the intended payment method usage
  • Use the attrs jsonb column to access additional attempt details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • setup_intent

SetupIntents

This is an object representing a guide through the process of setting up and saving customer payment credentials for future payments.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
SetupIntents

Usage


_15
create foreign table stripe.setup_intents (
_15
id text,
_15
client_secret text,
_15
customer text,
_15
description text,
_15
payment_method text,
_15
status text,
_15
usage text,
_15
created timestamp,
_15
attrs jsonb
_15
)
_15
server stripe_server
_15
options (
_15
object 'setup_intents'
_15
);

Notes

  • SetupIntents are read-only records for saving customer payment credentials
  • Each intent includes customer, payment method, and status information
  • The client_secret is used for client-side confirmation
  • The usage field indicates how the payment method will be used
  • Use the attrs jsonb column to access additional intent details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • customer
    • payment_method

Subscriptions

This is an object representing customer recurring payment schedules.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Subscriptions

Usage


_13
create foreign table stripe.subscriptions (
_13
id text,
_13
customer text,
_13
currency text,
_13
current_period_start timestamp,
_13
current_period_end timestamp,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'subscriptions',
_13
rowid_column 'id'
_13
);

Notes

  • Subscriptions can be created, read, updated, and deleted
  • Each subscription includes customer and currency information
  • The current_period_start and current_period_end track billing cycles
  • The rowid_column option enables modification operations
  • Use the attrs jsonb column to access additional subscription details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • customer
    • price
    • status

Tokens

This is an object representing a secure way to collect sensitive card, bank account, or personally identifiable information (PII) from customers.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Tokens

Usage


_13
create foreign table stripe.tokens (
_13
id text,
_13
type text,
_13
client_ip text,
_13
created timestamp,
_13
livemode boolean,
_13
used boolean,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'tokens'
_13
);

Notes

  • Tokens are read-only, single-use objects for secure data collection
  • Each token includes type information (card, bank_account, pii, etc.)
  • The client_ip field records where the token was created
  • The used field indicates if the token has been used
  • Use the attrs jsonb column to access token details like card or bank information
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • type
    • used

Top-ups

This is an object representing a way to add funds to your Stripe balance.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Top-ups

Usage


_13
create foreign table stripe.topups (
_13
id text,
_13
amount bigint,
_13
currency text,
_13
description text,
_13
status text,
_13
created timestamp,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'topups'
_13
);

Notes

  • Top-ups are read-only records of balance additions
  • Each top-up includes amount and currency information
  • The status field tracks the top-up state (e.g., succeeded, failed)
  • Use the attrs jsonb column to access additional top-up details
  • While any column is allowed in a where clause, it is most efficient to filter by:
    • id
    • status

Transfers

This is an object representing fund movements between Stripe accounts as part of Connect.

Ref: Stripe docs

Operations

ObjectSelectInsertUpdateDeleteTruncate
Transfers

Usage


_13
create foreign table stripe.transfers (
_13
id text,
_13
amount bigint,
_13
currency text,
_13
description text,
_13
destination text,
_13
created timestamp,
_13
attrs jsonb
_13
)
_13
server stripe_server
_13
options (
_13
object 'transfers'
_13
);

Notes

  • Transfers are read-only records of fund movements between accounts
  • Each transfer includes amount, currency, and destination information
  • The destination field identifies the receiving Stripe account
  • Use the attrs jsonb column to access additional transfer details
  • 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


_10
select * from stripe.customers where id = 'cus_xxx';

will be translated to a 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.

Limitations

This section describes important limitations and considerations when using this FDW:

  • Large result sets may experience slower performance due to full data transfer requirement
  • Webhook events and real-time updates are not supported
  • API version mismatches can cause unexpected data format issues
  • Materialized views using these foreign tables may fail during logical backups

Examples

Some examples on how to use Stripe foreign tables.

Basic example


_10
-- always limit records to reduce API calls to Stripe
_10
select * from stripe.customers limit 10;
_10
select * from stripe.invoices limit 10;
_10
select * from stripe.subscriptions limit 10;

Query JSON attributes


_11
-- extract account name for an invoice
_11
select id, attrs->>'account_name' as account_name
_11
from stripe.invoices where id = 'in_xxx';
_11
_11
-- extract invoice line items for an invoice
_11
select id, attrs#>'{lines,data}' as line_items
_11
from stripe.invoices where id = 'in_xxx';
_11
_11
-- extract subscription items for a subscription
_11
select id, attrs#>'{items,data}' as items
_11
from stripe.subscriptions where id = 'sub_xxx';

Data modify


_16
-- insert
_16
insert into stripe.customers(email,name,description)
_16
values ('test@test.com', 'test name', null);
_16
_16
-- update
_16
update stripe.customers
_16
set description='hello fdw'
_16
where id = 'cus_xxx';
_16
_16
update stripe.customers
_16
set attrs='{"metadata[foo]": "bar"}'
_16
where id = 'cus_xxx';
_16
_16
-- delete
_16
delete from stripe.customers
_16
where id = 'cus_xxx';

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:


_12
-- create the subscription table for data insertion, the 'customer'
_12
-- and 'items[0][price]' fields are required.
_12
create foreign table stripe.subscriptions (
_12
id text,
_12
customer text,
_12
"items[0][price]" text -- column name will be used in API Post request
_12
)
_12
server stripe_server
_12
options (
_12
object 'subscriptions',
_12
rowid_column 'id'
_12
);

And then we can insert a subscription like below:


_10
insert into stripe.subscriptions(customer, "items[0][price]")
_10
values ('cus_Na6dX7aXxi11N4', 'price_1MowQULkdIwHu7ixraBm864M');

Note this foreign table is only for data insertion, it cannot be used in select statement.