Stripe Payment Intents SQL Template

SQL table creation template for syncing Stripe payment intent data to your PostgreSQL database.

Updated: 15 Dec 2025

Stripe Payment Intents SQL Template

Create a database table to store Stripe payment intent data including payment attempts, amounts, and statuses.

What Data is Synced?

The Stripe Payment Intents sync captures essential payment transaction information from your Stripe account:

  • Payment Intent ID: Unique Stripe payment intent identifier
  • Customer Reference: Which customer initiated the payment (can be null for guest checkouts)
  • Amount Details: Payment amount, amount received, currency
  • Status Information: Payment status (succeeded, processing, requires_payment_method, etc.)
  • Description: Optional payment description
  • Livemode Flag: Whether this is a live or test mode payment
  • Timestamps: When the payment intent was created
  • Complete Payment Data: Full Stripe payment intent object stored as JSONB
  • Sync Tracking: Timestamp of when CLS last synced this record

SQL Table Template

Table Schema Explanation

Here's what each column in the table represents:

ColumnTypeDescription
idTEXTStripe payment intent ID (e.g., pi_abc123). Primary key.
customerTEXTStripe customer ID who initiated payment (e.g., cus_xyz789). Can be null for guest checkouts.
amountINTEGERPayment amount in smallest currency unit (e.g., cents). Required.
amount_receivedINTEGERAmount successfully captured/received (in cents). Defaults to 0.
currencyTEXTThree-letter ISO currency code (e.g., usd, gbp, eur). Required.
statusTEXTPayment status: requires_payment_method, requires_confirmation, requires_action, processing, succeeded, canceled. Required.
descriptionTEXTOptional description of the payment.
dataJSONBComplete Stripe payment intent object stored as JSON.
livemodeBOOLEANWhether this is a live mode payment (true) or test mode (false). Required.
createdTIMESTAMPTZTimestamp when payment intent was created in Stripe.
synced_atTIMESTAMPTZTimestamp when CLS last synced this payment intent record. Auto-updated.

All amount fields (amount, amount_received) are stored in cents (or smallest currency unit). For example, $25.00 USD is stored as 2500. Divide by 100 to get the dollar amount.

Usage Examples

After syncing, you can query your payment intent data using standard SQL:

-- Get all successful payments
SELECT * FROM stripe_payment_intents
WHERE status = 'succeeded';

-- Calculate total revenue by currency
SELECT
  currency,
  SUM(amount_received) / 100.0 AS total_revenue
FROM stripe_payment_intents
WHERE status = 'succeeded'
GROUP BY currency;

-- Find canceled payments
SELECT
  id,
  customer,
  amount / 100.0 AS amount_dollars,
  status,
  created
FROM stripe_payment_intents
WHERE status = 'canceled';

-- Get payment methods breakdown using data JSONB
SELECT
  data->>'payment_method_types'->0 AS payment_method_type,
  COUNT(*) AS count,
  SUM(amount_received) / 100.0 AS total_amount
FROM stripe_payment_intents
WHERE status = 'succeeded'
GROUP BY payment_method_type;

-- Find recent payments for a customer
SELECT
  id,
  amount / 100.0 AS amount_dollars,
  status,
  created
FROM stripe_payment_intents
WHERE customer = 'cus_abc123'
ORDER BY created DESC;

-- Get payments requiring action
SELECT * FROM stripe_payment_intents
WHERE status IN ('requires_action', 'requires_confirmation', 'requires_payment_method');

-- Find payments created in the last 7 days
SELECT * FROM stripe_payment_intents
WHERE created > NOW() - INTERVAL '7 days'
ORDER BY created DESC;

Common Customizations

The template includes performance indexes for customer, status, created, and livemode columns. You can add additional table-specific customizations:

Add Index for Currency Filtering

CREATE INDEX idx_stripe_payment_intents_currency
ON stripe_payment_intents(currency);

Add Computed Column for Success Status

ALTER TABLE stripe_payment_intents
ADD COLUMN is_successful BOOLEAN
GENERATED ALWAYS AS (status = 'succeeded') STORED;

Add Compound Index for Status and Amount

CREATE INDEX idx_stripe_payment_intents_status_amount
ON stripe_payment_intents(status, amount);

Payment Intent Status Explained

Understanding payment intent statuses helps track the payment lifecycle:

StatusDescription
requires_payment_methodAwaiting customer to provide payment method
requires_confirmationPayment method attached, awaiting confirmation
requires_actionRequires additional action (e.g., 3D Secure)
processingPayment is being processed
succeededPayment completed successfully
canceledPayment was canceled before completion

Only succeeded status represents completed payments where funds have been captured. Use this status for revenue calculations and financial reporting.