PackagesPayment providers

@prood/payment-stripe

Stripe provider using Checkout Sessions with the embedded Payment Element.

@prood/payment-stripe implements the PaymentProvider interface for Stripe, using the Checkout Sessions API with the embedded Payment Element.

Installation

Workspace package. Available from the source repo for now.

Usage

ts
import { StripePaymentProvider } from '@prood/payment-stripe'

const provider = new StripePaymentProvider({
  secretKey: config.secretKey,
  webhookSecret: config.webhookSecret,
  publishableKey: config.publishableKey,
})

Via commerce factory (preferred in apps):

ts
import { getTenantPaymentProvider } from '@prood/commerce'
const { provider } = await getTenantPaymentProvider(orgId, 'stripe')

Configuration

FieldRequiredDescription
secretKeyYesServer-side secret key
webhookSecretWebhooksSigning secret
publishableKeyClient UIPublishable key for Payment Element

Each store enters these under Integrations in the dashboard. There is no environment fallback.

Payment flow

  1. createSession() → creates a Checkout Session
  2. Client renders the Payment Element with its clientSecret
  3. Customer submits → Stripe handles 3DS if required
  4. confirmSession() → reads the Checkout Session's status
  5. Webhook checkout.session.completed → the source of truth

Webhook events

EventAction
checkout.session.completedpayment.captured when paid, otherwise payment.authorized
checkout.session.async_payment_succeededpayment.captured
checkout.session.async_payment_failedpayment.failed
checkout.session.expiredpayment.cancelled
charge.refundedRecord a refund, including one made in the Stripe dashboard. Stripe's refunded totals decide between refunded and partially_refunded

Webhook URL: https://checkout.example.com/api/webhooks/stripe/{orgId}

Refunds

ts
await provider.refund({
  sessionId: 'cs_xxx', // the Checkout Session on the order
  amount: 50, // partial refund in major units
  reason: 'requested_by_customer',
})

refund() resolves when Stripe accepts the refund and reads nothing back. Stripe honours idempotencyKey, so a retry can't send the money twice.

Test mode

Use Stripe test keys (sk_test_..., pk_test_...):

CardResult
4242 4242 4242 4242Success
4000 0000 0000 32203DS required
4000 0000 0000 9995Declined