@scrip-systems/checkout-sdk gives your server methods that manage Scrip holds and return updated parameters for your Stripe calls. @scrip-systems/checkout-widget provides an optional UI control for your checkout page.
Choose a path
Start by picking the Stripe integration your checkout uses:
Jump directly to a specific task:
Set up
Setvalue_per_unit on your points asset so Scrip knows what one point is worth in your Stripe checkout currency. For example, if 100 points equal $1.00, set one point to 0.01 USD:
value_per_unit is set, participant balances include their money value in available_value, and redemptions accept a face_value in money. See Value per unit and Redeem a price in money. Make sure the asset is linked to your program and the participant has a balance.
Quickstart
Finish Set up first. Integrating PaymentIntents takes three steps.1
Install the packages
2
Hold the points and lower the PaymentIntent amount
Call In this request,
scrip.stripe.applyPoints before creating the PaymentIntent. It holds the points in Scrip and returns updated PaymentIntent parameters with a lower amount and the hold IDs stored in metadata.participantId identifies the shopper in Scrip (ext: followed by your shopper ID, or the Scrip participant UUID), programId and assetId specify the program and points asset, and faceValue is the discount in minor currency units (2000 is $20.00 in USD cents).For a $100.00 cart, result.params.amount is 8000. Save result.redemptionIds on your cart record so you can pass them back if the shopper changes their cart, and block edits once the order is paid. See Refuse changes to a paid cart.3
Forward Stripe webhooks to handleEvent
After verifying the Stripe webhook signature, pass the event to
scrip.stripe.handleEvent. Subscribe your Stripe webhook endpoint to payment_intent.succeeded and payment_intent.canceled.Use one environment
Scrip production and sandbox have separate API addresses, keys, and data. See Environments. Match your Scrip and Stripe credentials to the same environment:
Always pass
baseUrl explicitly and fail on startup if it is missing. Omitting baseUrl defaults to production.
The checkout widget holds no API URL or keys. It renders whatever your server passes to it, so it needs no environment configuration.
Hold points and lower the charge
scrip.stripe.applyPoints takes the PaymentIntentCreateParams you would send without points, places a hold on the requested points, and returns updated parameters with the lowered charge:
To combine points from multiple assets on one order, pass
points (an array of { assetId, faceValue }) instead of assetId and faceValue. Scrip places one hold per asset.
When applyPoints succeeds, result.params preserves all of your original PaymentIntent fields and updates two of them:
amountbecomes the order total minus the applied points.metadata.scrip_redemption_idsrecords the held redemption IDs.
result.params directly to stripe.paymentIntents.create. When updating an existing PaymentIntent with stripe.paymentIntents.update, pass only { amount: result.params.amount, metadata: result.params.metadata }, because Stripe’s update endpoint does not accept create-only fields.
Always pass an idempotencyKey to stripe.paymentIntents.create so retries or double-clicks do not create duplicate PaymentIntents. If a PaymentIntent is cancelled and you create a new one for the same cart, increment a counter on the cart (cart.cancelledIntents) and include it in the key (for example, pi-${cart.id}-${cart.cancelledIntents}-${cart.redemptionIds.join("-") || "full"}), because Stripe returns the cancelled PaymentIntent if you reuse its idempotency key.
A hold can end earlier than ttlSeconds if your program sets a shorter pending_redemption_ttl, or if the held points expire sooner. Read result.expiresAt from the response rather than calculating the deadline yourself. Holds cannot be extended. See Use the returned deadline.
Bank debits and other async payment methods can stay processing longer than a 1-hour hold, so start by restricting points checkouts to cards (allowed_payment_method_types: ["card"], or payment_method_types on older Stripe API versions). If you support slower payment methods, set a longer ttlSeconds (up to 365 days).
Read the result
applyPoints returns a status field for every expected checkout outcome instead of throwing:
To calculate the exact point count for a money amount before calling
applyPoints, use priceFaceValue. It matches the API’s rounding rules:
replaces ID belonging to another participant) throw TypeError or RangeError before any hold is placed. Unexpected API failures throw ScripError. See Errors.
The SDK checks remaining card charges against a built-in table of Stripe currency minimums (for example, 50 cents for USD). To override those minimums, create custom helpers with createStripeHelpers:
Complete or release the points
scrip.stripe.handleEvent reads metadata.scrip_redemption_ids from the PaymentIntent or Checkout Session inside the Stripe webhook event. If the event has no scrip_redemption_ids or is an event type Scrip does not act on, handleEvent returns { handled: false }.
For Checkout Session webhook events, see Pay with points with Stripe Checkout Sessions. If both a PaymentIntent event and a Checkout Session event arrive for the same payment, the second delivery is a safe no-op.
Stripe delivers webhook events in your account’s configured API version, which can differ from the version your SDK requests use.
handleEvent handles both shapes.
Act on what handleEvent returns
When a payment succeeds, handleEvent completes each redemption. Even if the original hold expired or was released during a cart edit, Scrip attempts to redeem the same points again so the shopper cannot receive a discounted order for free.
handleEvent returns a per-redemption outcome for every hold in results. Two outcomes require your store to take recovery action:
All other outcomes represent normal completion, cancellation, or safe duplicate deliveries:
Because retrying cannot change any of these outcomes,
handleEvent returns them instead of throwing. Your webhook endpoint returns 200, so handle points_unavailable and completed_by_other_payment explicitly:
intentId and redemptionIds on your cart record so a subsequent checkout attempt starts clean.
handleEvent throws on errors that should be retried: network failures, timeouts, StripeDeadlineError, 5xx or 429 responses, and 401/403 responses (so you can fix a rotated or misconfigured key without losing events). Let those errors propagate so your webhook returns a 5xx and Stripe retries delivery.
Make your order step safe to run twice
Stripe can deliver the same webhook event more than once, out of order, or concurrently. Two concurrent deliveries can both returncompleted, while Scrip spends the points only once. Make your fulfillOrder step idempotent by keying it on the PaymentIntent ID or Stripe event ID and skipping work you already completed.
These SDK calls are safe to retry: applyPoints with the same cart and amount, handleEvent with the same event, completeWithoutPayment, removePoints, and scrip.redemptions.reverse with the same idempotencyKey.
Timeouts
handleEvent enforces built-in timeouts so webhook handlers do not hang:
Run
handleEvent inline if your webhook handler can wait up to 8 seconds. Otherwise, verify and enqueue the event, return 200 immediately, and call handleEvent from a background worker. To customize timeouts, pass them to createStripeHelpers:
Cart changes and page refreshes
Store cart state on your server rather than trusting totals or hold IDs from the browser. The examples below assume a server-sideCart record and two small app helpers:
cart.redemptionIds in replaces when calling applyPoints:
- Unchanged request (page refresh, double-click, or timeout retry): Scrip returns the existing holds without placing a second hold or releasing anything.
- Changed points amount: Scrip releases the saved holds and places a new hold for the updated amount.
- Changed cart total with the same points amount: Scrip keeps the existing holds and updates
result.params.amountto match the new total.
result.redemptionIds after every successful call, even when the same holds are returned. On a page refresh, reuse the cart’s existing PaymentIntent instead of creating a new one.
When the shopper changes their points amount, call applyPoints with replaces and update the existing PaymentIntent:
replaces from your server’s cart record, never from client input. The SDK verifies that each ID belongs to the same participant and program, throwing TypeError otherwise. Process one cart update at a time per cart (for example, with a per-cart lock) so concurrent clicks cannot race.
Do not reuse hold IDs across a cancelled PaymentIntent: its payment_intent.canceled webhook releases any holds listed in its metadata. Keep a one-to-one mapping between an active hold and its PaymentIntent.
Refuse changes to a paid cart
Once a cart’s card payment succeeds or points cover the order in full, treat the cart as locked. Check that the cart is still open at the top of every mutating route (creating or updating the PaymentIntent, applying or removing points, changing items, or placing a points-only order). Blocking updates early also prevents Stripe’s400 payment_intent_unexpected_state error when updating a PaymentIntent that has already succeeded.
Because the shopper’s browser can return from Stripe before your webhook arrives, check Stripe directly when cart.paid is still false:
paid in the cart payload sent to your checkout page so the UI renders the confirmation screen with no points control or Pay button.
Remove points
When a shopper removes points from their cart, callscrip.stripe.removePoints. It cancels each held redemption, releases the points back to the shopper’s balance, and returns result.params with the full card amount and metadata.scrip_redemption_ids set to "" (which instructs Stripe to delete that metadata key while keeping your other metadata).
scrip_redemption_ids on the PaymentIntent when releasing a hold. If a PaymentIntent still references a released hold when it succeeds, handleEvent will redeem those points again.
Conversely, if you need to cancel a PaymentIntent while keeping its hold (for example, when points now cover the full order), clear scrip_redemption_ids on the PaymentIntent before cancelling it so the payment_intent.canceled webhook does not release the hold.
Calling removePoints on an already-released hold is a safe no-op, so retries are safe. If a hold has already completed, removePoints releases nothing and returns { status: "already_completed" } with no params. To return points after completion, reverse the redemption instead.
Orders that points pay in full
When points cover the entire cart total,applyPoints places the hold and returns status: "fully_covered". No Stripe payment or webhook occurs. When the shopper places the order, call scrip.stripe.completeWithoutPayment to spend the held points.
If the cart already had a PaymentIntent referencing that hold, clear scrip_redemption_ids on the PaymentIntent before cancelling it (as shown in Add the widget), or the payment_intent.canceled webhook will release the hold you are about to complete.
completeWithoutPayment does not set provider or order_id by default. To record your own order reference on the redemption, pass orderId and provider together.
If the hold expired before the shopper clicked Place order, completeWithoutPayment redeems the points again (retaken), the same way as a card payment. A duplicate call returns already_completed, and requireOpen blocks duplicate order submissions once cart.paid is true.
Return points after a partial refund
To refund part of a split-payment order, issue the card refund in Stripe, then callscrip.redemptions.reverse with the points’ share as face_value. Your store decides how to split refunds and taxes between card and points; Scrip converts face_value back to points using the exact rate locked in when the points were held. See Reversals.
For example, suppose a $100.00 order was paid with $80.00 by card and $20.00 in points (2,000 points at $0.01/point). On a $30.00 proportional refund, $24.00 goes back to the card and $6.00 (600 points) goes back to Scrip:
COMPLETED or PARTIALLY_REVERSED redemptions. Before a payment succeeds, points are only held and are returned by cancelling the PaymentIntent or calling removePoints. The checkout SDK does not issue Stripe refunds or calculate refund splits and tax.
If something goes wrong
To inspect a redemption or debug a balance mismatch, callscrip.redemptions.get, scrip.redemptions.listForParticipant, or scrip.participants.listBalances (which returns available, held, and available_value).
Add the checkout points widget
Mount a points control on your checkout page or wire up your own UI.
Use Stripe Checkout Sessions
Apply points as a one-time coupon on Stripe-hosted Checkout pages.
Pending redemptions
Hold deadlines, states, and ledger entries underneath checkout.