Skip to main content

Stripe Integration

Accept credit cards, Apple Pay, Google Pay, and 40+ payment methods globally using Stripe as your payment provider.

Prerequisites

Before you begin, make sure you have:
Use test mode keys (sk_test_... / pk_test_...) during development. Switch to live keys only when you’re ready to accept real payments.

Environment Variables

Add the following environment variables to your API server:
For your frontend application, add the publishable key:
Never expose STRIPE_SECRET_KEY or STRIPE_WEBHOOK_SECRET to the client. These must only be used server-side.

Checkout Flow

The complete Stripe checkout flow involves four steps: creating a cart, initiating checkout, confirming payment on the client, and handling the webhook confirmation.

Webhook Setup

Headless Commerce listens for Stripe webhook events to keep order and payment statuses in sync. Configure webhooks in the Stripe Dashboard:
  1. Go to DevelopersWebhooks in the Stripe Dashboard
  2. Click Add endpoint
  3. Enter your webhook URL: https://api.headlesscommerce.io/v1/webhooks/stripe
  4. Select the following events:
    • payment_intent.succeeded
    • payment_intent.payment_failed
    • charge.refunded
    • charge.dispute.created
  5. Copy the Signing secret and set it as STRIPE_WEBHOOK_SECRET

Event handling

Refunds

Issue full or partial refunds through the Admin API:
The refund is processed through Stripe automatically and the order is updated accordingly.

Testing

Test mode keys

Always use test mode API keys during development. These keys create test-only transactions that never hit real payment networks.

Test card numbers

Use these card numbers in test mode: Use any future expiration date, any 3-digit CVC, and any postal code.

Testing webhooks locally

Use the Stripe CLI to forward webhook events to your local development server:

Error Handling

Handle payment errors gracefully in your frontend:
Common Stripe-specific errors after confirmPayment():

Next Steps

Webhooks

Learn about all webhook events and payload formats.

TossPayments

Set up TossPayments for Korean payment methods.

API Reference

Explore all checkout and payment endpoints.

SDKs

Full SDK reference with every resource and method.