[PR #4892] [CLOSED] feat(stripe): add one-time payment support with checkout sessions #5642

Closed
opened 2026-03-13 12:30:14 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4892
Author: @Pankaj3112
Created: 9/25/2025
Status: Closed

Base: canaryHead: feat/stripe-one-time-payments


📝 Commits (4)

  • 7d89047 feat(stripe): add one-time payment support with checkout sessions
  • fdfbc8d refactor(stripe): rename oneTimePayments to payments
  • 23547d0 Merge branch 'canary' into feat/stripe-one-time-payments
  • a474e0c fix: correct syntax error in STRIPE_ERROR_CODES definition

📊 Changes

7 files changed (+1319 additions, -124 deletions)

View changed files

📝 packages/stripe/src/client.ts (+8 -13)
📝 packages/stripe/src/hooks.ts (+119 -70)
📝 packages/stripe/src/index.ts (+498 -28)
📝 packages/stripe/src/schema.ts (+69 -3)
📝 packages/stripe/src/stripe.test.ts (+418 -1)
📝 packages/stripe/src/types.ts (+189 -8)
📝 packages/stripe/src/utils.ts (+18 -1)

📄 Description

What this PR does

Adds one-time payment functionality to the Stripe plugin, enabling product purchases through checkout sessions with webhook integration.

Key Changes

  • New API endpoints: POST /payment/create-session, GET /payment/list, GET /payment/status
  • Database schema: Added payment table for tracking purchases
  • Webhook handling: Enhanced to process checkout.session.completed for payment mode
  • Product configuration: Support for products with priceId/lookupKey and custom callbacks
  • Client integration: Added payment methods to stripeClient plugin

Configuration

stripe({
  oneTimePayments: {
    enabled: true,
    products: [
      {
        name: "Premium Course",
        priceId: "price_123",
        onPaymentComplete: async ({ payment }) => {
          // Handle successful payment
        }
      }
    ]
  }
})

Usage

// Client setup
stripeClient({ subscription: true, oneTimePayments: true })

// Create payment
await authClient.payment.createSession({
  productName: "Premium Course",
  successUrl: "/success"
})

Testing

Payment session creation and webhook processing
Product lookup and callback execution
Payment status tracking and user association

Breaking Changes

None - feature is opt-in and doesn't affect existing functionality.


Summary by cubic

Adds one-time payment support to the Stripe plugin using Checkout Sessions. This adds payment APIs, a payment table, webhook handling, and client methods — all opt-in.

  • New Features

    • Endpoints: POST /payment/create-session, GET /payment/status, GET /payment/list
    • Webhook: handles checkout.session.completed (payment mode), updates payment, runs product onPaymentComplete
    • Schema: new payment table (status, amount, currency, refs, Stripe IDs)
    • Products: configure via priceId or lookupKey; supports per-product callbacks
    • Security: reference authorization for payments; optional email verification gate
    • Client: stripeClient now supports oneTimePayments with createSession, getStatus, list
  • Migration

    • Enable oneTimePayments in stripe() and define products (priceId or lookupKey)
    • Run DB migrations to add the payment table (if your adapter requires it)
    • Update client to pass oneTimePayments: true
    • Optionally set authorizeReference, success/cancel URLs, and requireEmailVerification
    • No breaking changes; feature is opt-in

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4892 **Author:** [@Pankaj3112](https://github.com/Pankaj3112) **Created:** 9/25/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/stripe-one-time-payments` --- ### 📝 Commits (4) - [`7d89047`](https://github.com/better-auth/better-auth/commit/7d89047f9d4fc18fd56acbcada700ca215b2e625) feat(stripe): add one-time payment support with checkout sessions - [`fdfbc8d`](https://github.com/better-auth/better-auth/commit/fdfbc8dbfabf83bb17d6ed8bba7ca27523da9ed6) refactor(stripe): rename oneTimePayments to payments - [`23547d0`](https://github.com/better-auth/better-auth/commit/23547d0ffb08377f7d24356afcc6fc77349be77b) Merge branch 'canary' into feat/stripe-one-time-payments - [`a474e0c`](https://github.com/better-auth/better-auth/commit/a474e0cb02cdf37914173cb77eeacd0bca074622) fix: correct syntax error in STRIPE_ERROR_CODES definition ### 📊 Changes **7 files changed** (+1319 additions, -124 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/client.ts` (+8 -13) 📝 `packages/stripe/src/hooks.ts` (+119 -70) 📝 `packages/stripe/src/index.ts` (+498 -28) 📝 `packages/stripe/src/schema.ts` (+69 -3) 📝 `packages/stripe/src/stripe.test.ts` (+418 -1) 📝 `packages/stripe/src/types.ts` (+189 -8) 📝 `packages/stripe/src/utils.ts` (+18 -1) </details> ### 📄 Description ## What this PR does Adds one-time payment functionality to the Stripe plugin, enabling product purchases through checkout sessions with webhook integration. ## Key Changes - **New API endpoints**: `POST /payment/create-session`, `GET /payment/list`, `GET /payment/status` - **Database schema**: Added `payment` table for tracking purchases - **Webhook handling**: Enhanced to process `checkout.session.completed` for payment mode - **Product configuration**: Support for products with `priceId`/`lookupKey` and custom callbacks - **Client integration**: Added payment methods to `stripeClient` plugin ## Configuration ```typescript stripe({ oneTimePayments: { enabled: true, products: [ { name: "Premium Course", priceId: "price_123", onPaymentComplete: async ({ payment }) => { // Handle successful payment } } ] } }) ``` ## Usage ```typescript // Client setup stripeClient({ subscription: true, oneTimePayments: true }) // Create payment await authClient.payment.createSession({ productName: "Premium Course", successUrl: "/success" }) ``` ## Testing ✅ Payment session creation and webhook processing ✅ Product lookup and callback execution ✅ Payment status tracking and user association ## Breaking Changes None - feature is opt-in and doesn't affect existing functionality. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds one-time payment support to the Stripe plugin using Checkout Sessions. This adds payment APIs, a payment table, webhook handling, and client methods — all opt-in. - **New Features** - Endpoints: POST /payment/create-session, GET /payment/status, GET /payment/list - Webhook: handles checkout.session.completed (payment mode), updates payment, runs product onPaymentComplete - Schema: new payment table (status, amount, currency, refs, Stripe IDs) - Products: configure via priceId or lookupKey; supports per-product callbacks - Security: reference authorization for payments; optional email verification gate - Client: stripeClient now supports oneTimePayments with createSession, getStatus, list - **Migration** - Enable oneTimePayments in stripe() and define products (priceId or lookupKey) - Run DB migrations to add the payment table (if your adapter requires it) - Update client to pass oneTimePayments: true - Optionally set authorizeReference, success/cancel URLs, and requireEmailVerification - No breaking changes; feature is opt-in <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:30:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5642