> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scrip.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Start with https://docs.scrip.dev/agents.md and https://docs.scrip.dev/which-endpoints-you-need.md. Your application only needs a few API calls as users earn and spend (`POST /v1/events`, balance/history reads, and redemptions); program setup happens in the dashboard or setup scripts.
> Use `https://api-sandbox.scrip.dev` with `sk_test_` keys for testing, and `https://api.scrip.dev` with `sk_live_` keys for production. Keep API keys on your server.
> Pass your own user ID as `external_id` on events and prefix it with `ext:` in participant URL paths (e.g., `GET /v1/participants/ext:user_123/balances`). By default (`on_unknown_participant: CREATE`), the first event for a new `external_id` creates and enrolls the participant automatically.
> Events process asynchronously: `POST /v1/events` returns `202 Accepted` when queued, and rules evaluate in the background. Pass an `idempotency_key` (such as an order ID) on every event, and wait for the `event.completed` webhook or poll `GET /v1/events/{event_id}` before reading updated balances.
> Connect the hosted MCP server at https://mcp.scrip.dev/mcp (OAuth, defaults to Sandbox) to inspect programs, validate and simulate rules, and trace events. Append `.md` to any docs URL for Markdown, or fetch https://docs.scrip.dev/openapi.json for full endpoint schemas.

# Pay with points with Stripe Checkout Sessions

> Hold points, create a one-time Stripe coupon for them, and start a Checkout Session that charges the rest.

When Stripe hosts your payment page through Stripe Checkout Sessions, your server holds the shopper's points in Scrip, creates a one-time Stripe coupon for that discount, and attaches the coupon to the Checkout Session.

Before following this guide, configure your asset's `value_per_unit`, initialize the `scrip` and `stripe` clients, and wire up `scrip.stripe.handleEvent` using [Pay with points at checkout with Stripe](https://docs.scrip.dev/guides/pay-with-points-at-checkout-with-stripe.md).

## Hold points and start a session

Stripe Checkout does not let you subtract a fixed amount directly from line items. Instead, `scrip.stripe.applyPointsToCheckoutSession` holds the points and returns two values: `couponParams` for creating a one-time Stripe coupon, and a `sessionParams` helper that attaches that coupon and Scrip metadata to your Checkout Session parameters.

```ts theme={null}
export async function startCheckoutSession(cartId: string, shopperId: string, previousHolds?: string[]) {
  // Hold $20.00 of points in Scrip
  const result = await scrip.stripe.applyPointsToCheckoutSession({
    participantId: `ext:${shopperId}`,
    programId: "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
    assetId: "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
    cartId,
    faceValue: { amount_minor: 2000, currency: "usd" },
    orderTotal: { amount_minor: 10000, currency: "usd" }, // $100.00 subtotal before tax and shipping
    replaces: previousHolds,
  });

  if (result.status !== "applied") return result;

  const coupon = await stripe.coupons.create(result.couponParams);

  const session = await stripe.checkout.sessions.create(
    result.sessionParams(coupon.id, {
      mode: "payment" as const,
      line_items: [{ price: "price_123", quantity: 1 }],
      success_url: "https://example.com/thanks",
    }),
  );

  return { status: "applied", url: session.url, redemptionIds: result.redemptionIds };
}
```

`result.sessionParams` sets `discounts` to your one-time \$20.00 coupon, attaches `scrip_redemption_ids` metadata to both the Checkout Session and its underlying PaymentIntent, and sets `expires_at`.

Subscribe your Stripe webhook endpoint to these Checkout Session events and pass them to [`scrip.stripe.handleEvent`](https://docs.scrip.dev/guides/pay-with-points-at-checkout-with-stripe#complete-or-release-the-points):

| Stripe event | What `handleEvent` does |
| - | - |
| `checkout.session.completed` (when `payment_status` is `paid`) | Completes each held redemption using the session's PaymentIntent ID as `order_id`. |
| `checkout.session.async_payment_succeeded` | Completes each held redemption for delayed payment methods. |
| `checkout.session.expired` | Releases the held points back to the shopper's balance. |
| `checkout.session.async_payment_failed` | Does nothing (`{ handled: false }`). The hold stays active. |

`applyPointsToCheckoutSession` adds three session-specific options alongside the standard [`applyPoints` options](https://docs.scrip.dev/guides/pay-with-points-at-checkout-with-stripe#hold-points-and-lower-the-charge):

| Option | Description |
| - | - |
| `orderTotal` | The pre-tax, pre-shipping subtotal in minor units. Stripe Checkout applies coupons before tax and shipping, so pass the subtotal and let Stripe calculate tax. |
| `sessionExpiresInSeconds` | How long the Checkout Session stays open, from `1800` (30 minutes) to `86400` (24 hours). Defaults to `1860` (31 minutes). |
| `ttlSeconds` | How long the Scrip hold lasts. Defaults to 5 minutes longer than the Checkout Session. |

The Scrip hold must outlive the Checkout Session. `applyPointsToCheckoutSession` rejects a `ttlSeconds` that ends less than 1 minute after the session, as well as a `sessionExpiresInSeconds` outside Stripe's 30-minute to 24-hour range.

Create the Stripe coupon and Checkout Session right after `applyPointsToCheckoutSession` returns. If an existing hold is too close to expiring to cover a new Checkout Session, the SDK returns `hold_ending_soon`. Call `applyPointsToCheckoutSession` again with `replaces` set to `result.redemptionIds` to place a fresh hold. All other return statuses match [`applyPoints`](https://docs.scrip.dev/guides/pay-with-points-at-checkout-with-stripe#read-the-result).

On a page refresh, reuse the open Checkout Session for that cart rather than creating another one. Multiple open sessions for the same cart share one Scrip hold: if the unused session expires first, its `checkout.session.expired` webhook releases the hold. If the shopper then pays on the other session, `handleEvent` tries to redeem the points again (`retaken`) or reports `points_unavailable` if the points were spent elsewhere. See [Act on what `handleEvent` returns](https://docs.scrip.dev/guides/pay-with-points-at-checkout-with-stripe#act-on-what-handleevent-returns).

The minimum-charge check evaluates `orderTotal` minus the applied points. If points cover the full `orderTotal`, `applyPointsToCheckoutSession` places the hold and returns `fully_covered` without building a zero-dollar session. Skip Stripe and finish the order with [`completeWithoutPayment`](https://docs.scrip.dev/guides/pay-with-points-at-checkout-with-stripe#orders-that-points-pay-in-full).

### If a session expires

When a Checkout Session expires, Stripe sends `checkout.session.expired` and `handleEvent` releases the points (`cancelled`). To let the shopper try again, start a new Checkout Session and pass the previous hold IDs in `replaces`.

## Promotion codes on Checkout Sessions

Stripe Checkout allows only one coupon or promotion code per session. Because `result.sessionParams` uses that discount slot for points and overwrites any `discounts` field you pass, a shopper cannot enter a Stripe promotion code and apply points on the same Checkout Session.

If your store supports promotion codes alongside points, apply your promotion on your server before calling `applyPointsToCheckoutSession`: reduce the `line_items` prices by the promotion discount and pass that discounted subtotal as `orderTotal`. The Checkout Session then carries a single Stripe coupon for the points on top of your already-discounted items.

With PaymentIntents, Stripe does not use a coupon for points, so this limit does not apply: your server calculates any promotion discounts and passes the final card charge as the PaymentIntent `amount`.

> [card] [PaymentIntents integration](https://docs.scrip.dev/guides/pay-with-points-at-checkout-with-stripe.md)
>
> Full reference for `applyPoints`, `handleEvent`, timeouts, and refunds.

> [card] [Add the checkout points widget](https://docs.scrip.dev/guides/checkout-points-widget.md)
>
> Mount a points control on a custom PaymentIntents checkout page.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.