Embedded payments with Stripe Elements
Take a card or wallet payment on your own checkout page. The buyer types the card into Stripe Elements, Stripe.js turns it into a single-use credential, and your backend sends that credential to Flint. Flint charges it against the order, runs 3D Secure when the issuer asks for it, and marks the order paid. Card numbers never reach your servers or Flint's.
Use this when checkout lives on your domain. If a Flint-hosted payment page is enough, follow Accept your first payment instead. Cart building, delivery, receipts, and checkout sessions for a full merchant-owned checkout are in Build your own checkout; this guide covers the payment step inside it.
Before you start#
Get a test API key. Create one on the dashboard's API keys page. A test key starts with flint_test_ and is bound to a sandbox, so payments run in Stripe test mode and no real money moves. Test and live keys use the same base URL, https://api.withflintpay.com; the key decides the mode.
Give the key the permissions this guide uses. A write permission also grants its read.
| Permission | Covers |
|---|---|
commerce.orders.write | Creating, reading, and paying orders, and creating payment legs on them |
merchants.profile.read | The readiness check below |
payments.payment_intents.write | Capturing or canceling a payment leg |
checkouts.checkout_sessions.write | Creating a headless checkout session, if you use one |
Registering a wallet domain needs payments.payment_method_domains.write. Put it on a separate administrative key rather than the one your checkout uses.
Keep the key on your backend. The browser talks to Stripe.js and to your backend, never to the Flint API. Flint has no publishable key and does not accept API requests from merchant browser origins. The browser can open Flint payment authentication pages and show the gift card challenge in a frame.
Selling for a merchant your platform created? Send a partner app token for the merchant's mode instead of an API key, and name the merchant in Flint-Merchant-Id. The merchant's install must hold the scopes in the table. Registering a wallet domain stays with the merchant's own live credential. Build payments into your platform follows the whole flow, from a merchant signup to the first sale.
Check that your sandbox can take card payments:
<!-- docs-test {"scenario":"merchant","status":200,"expect":{"data.merchant_id":"mer_Example"}} -->
curl https://api.withflintpay.com/v1/merchant \
-H "Authorization: Bearer YOUR_API_KEY"
data.readiness.payments.status is ready when the account can charge cards.
A 200 response confirms the request worked, not that the sandbox can charge cards. While readiness.payments.status is pending or blocked, its status_reason and readiness.requirements name what is still due. Complete it in the dashboard, then run the check again.
Register your checkout hostname for wallets. Apple Pay and Google Pay buttons appear only on HTTPS hostnames registered with POST /v1/payment-method-domains. Apple Pay and Google Pay covers registering, checking, and testing each hostname. Cards work without it.
The flow#
- Your backend sends 1. POST /v1/orders to Flint
- Your backend sends 2. GET /v1/orders/{order_id} to Flint
- Flint returns balance and payment_collection to Your backend
- Your backend returns payment_collection to Browser
- Browser sends 3 and 4. create the credential to Browser
- Browser sends the credential to Your backend
- Your backend sends 5. POST /v1/orders/{order_id}/pay to Flint
- Flint returns payment attempt to Your backend
- Your backend returns 6. client action, if 3D Secure is needed to Browser
- Browser sends challenge finished to Your backend
- Your backend sends action: resume to Flint
- Flint returns 7. order.paid webhook to Your backend
Who confirms the payment#
Flint does. Confirming an order leg runs the order payment coordinator, so one payment attempt records what happened. The browser only creates a credential.
- Never call
stripe.confirmPaymentorstripe.confirmCardPaymentfor an order.payment_collectionholds no PaymentIntent client secret, so there is nothing for the browser to confirm. Flint returns a URL by default for 3D Secure or another buyer step. Only an explicitclient_action_type: "stripe"returns a client secret in a pending action, in step 6. It is a Stripe PaymentIntent client secret, so it can also confirm the payment at Stripe with a different card. Pass it only tohandleNextAction, never toconfirmPaymentorconfirmCardPayment, and read the outcome from your backend. - Pay the order, or confirm its payment intent. To sell items from your own page,
POST /v1/orders/{order_id}/paycreates the leg and confirms it in one call, as this guide does.POST /v1/payment-intents/{payment_intent_id}/confirmalso starts a single leg that covers the order balance, and continues the attempt that holds it. It applies the same order effects aspay, and it takes the samepayment_source. Several unpaid legs or selected gift cards require the order'spay;managed_by_ownernames that command. Checkout credentials can confirm their own session's legs. - Capture and cancel work the same as for a standalone PaymentIntent, through
/v1/payment-intents/{payment_intent_id}/captureand/cancel. Flint finds the order payment attempt that owns the leg and updates the order.
A payment leg is one PaymentIntent on the order. The steps below never create one by hand: action: "pay" creates a full-balance, automatic-capture leg and confirms it in one request. Create legs yourself only for split tender or partial payment and for manual capture.
Step 1: create an order#
The order is Flint's record of the sale, and the payment settles against it. Amounts are integers in the currency's minor unit, so 9900 is $99.00.
<!-- docs-test {"scenario":"main","status":201} -->
curl -X POST https://api.withflintpay.com/v1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: order-pro-annual-001" \
-d '{
"line_items": [{
"type": "custom",
"name": "Pro Plan Annual",
"quantity": 1,
"unit_price_money": {"amount": 9900, "currency": "USD"},
"fulfillment": {"requirement": "none"}
}]
}'
{
"data": {
"order_id": "ord_1kmn0aExample",
"status": "open",
"payment_status": "unpaid",
"version": 1790760000,
"settlement_amounts": {
"paid_money": {"amount": 0, "currency": "USD"},
"outstanding_money": {"amount": 9900, "currency": "USD"}
}
},
"request_id": "req_..."
}
status says whether the order still accepts changes and payments, and payment_status tracks collection. An unpaid order is open and unpaid. Once the full balance is collected it becomes closed and paid. Apply delivery, tax, promotions, and tips before the buyer pays, because each can change the total.
Step 2: read the collection guidance#
Read the order right before you mount Elements. data.payment_collection says what to collect and under which Stripe account, and Flint recalculates it on every read.
<!-- docs-test {"scenario":"main","status":200} -->
curl https://api.withflintpay.com/v1/orders/ord_1kmn0aExample \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": {
"order_id": "ord_1kmn0aExample",
"status": "open",
"payment_status": "unpaid",
"version": 1790760000,
"settlement_amounts": {
"outstanding_money": {"amount": 9900, "currency": "USD"}
},
"payment_collection": {
"stripe": {
"account_id": "acct_1AbcPlaceholder",
"publishable_key": "pk_test_51AbcPlaceholder",
"elements": {
"next_step": "create_confirmation_token",
"submit_to": "pay_order",
"mode": "payment",
"amount_money": {"amount": 9900, "currency": "USD"},
"payment_options": ["card", "apple_pay", "google_pay"],
"payment_method_creation": "manual"
}
}
}
},
"request_id": "req_..."
}
Store settlement_amounts.outstanding_money and version from this response on your backend. They are what the buyer approves, and you send them back with the payment in step 5.
Send payment_collection to the browser as returned. It holds no secrets: the publishable key and account ID exist for Stripe.js. Reading the order creates no payment leg and holds no funds.
next_step names the Stripe.js call the browser makes, and with it the credential your backend sends to Flint:
next_step | Stripe.js call | Credential |
|---|---|---|
create_confirmation_token | stripe.createConfirmationToken | A ctoken_..., sent as credential_type: "stripe_confirmation_token" |
Every payment-mode read returns create_confirmation_token, whether you use an API key, partner token, Dashboard session, or checkout session credential. A zero-balance order returns mode: "setup" with next_step: "collect_setup_payment_source", which creates a PaymentMethod to save instead of charging one; Build your own checkout covers it.
Step 3: mount Stripe Elements#
Initialize Stripe.js with the publishable key. Pass account_id as stripeAccount when it is set. Create deferred Elements with the returned amount, currency, and payment options. Pass on_behalf_of as onBehalfOf when present.
<script src="https://js.stripe.com/v3/"></script>
<form id="payment-form">
<div id="payment-element"></div>
<button id="submit" type="submit" disabled>Pay</button>
</form>
<button id="verify-payment" type="button" hidden>Verify payment</button>
<div id="payment-message" role="status"></div>
let stripe, elements, guidance, paymentElement;
function mountPaymentElement(paymentCollection) {
paymentElement?.destroy();
const {stripe: collection} = paymentCollection;
guidance = collection.elements;
stripe = Stripe(collection.publishable_key, {
...(collection.account_id ? {stripeAccount: collection.account_id} : {}),
});
// Stripe Elements takes processor method types. Apple Pay and Google Pay ride on card.
const STRIPE_METHOD_TYPES = {card: "card", apple_pay: "card", google_pay: "card", affirm: "affirm", ach_debit: "us_bank_account"};
const paymentMethodTypes = [...new Set(guidance.payment_options.flatMap((option) => STRIPE_METHOD_TYPES[option] ?? []))];
elements = stripe.elements({
mode: guidance.mode,
amount: guidance.amount_money.amount,
currency: guidance.amount_money.currency.toLowerCase(),
paymentMethodCreation: guidance.payment_method_creation,
paymentMethodTypes,
...(collection.on_behalf_of ? {onBehalfOf: collection.on_behalf_of} : {}),
});
paymentElement = elements
.create("payment", {
// Show only the wallets Flint offers; Stripe's default can show others.
wallets: {
applePay: guidance.payment_options.includes("apple_pay") ? "auto" : "never",
googlePay: guidance.payment_options.includes("google_pay") ? "auto" : "never",
},
});
paymentElement.mount("#payment-element");
}
paymentMethodCreation: "manual" is what lets Stripe.js create a credential without confirming a payment. Flint confirms it in step 5.
If the total changes after Elements is mounted, for example because the buyer picks a delivery option, read the order again and call elements.update() with the new amount_money.amount. Show the buyer the new total before they pay.
Step 4: create the credential#
When the buyer submits, call elements.submit() to validate the form, then the Stripe.js call that next_step names. Post the credential's ID to your backend.
document.querySelector("#payment-form").addEventListener("submit", async (event) => {
event.preventDefault();
if (submit.disabled) return;
submit.disabled = true;
try {
const {error: submitError} = await elements.submit();
if (submitError) {
submit.disabled = false;
return showMessage(submitError.message);
}
if (guidance.next_step !== "create_confirmation_token") {
throw new Error(`Unsupported collection step: ${guidance.next_step}`);
}
const {error, confirmationToken} = await stripe.createConfirmationToken({elements});
if (error) {
submit.disabled = false;
return showMessage(error.message);
}
const credential = {kind: "confirmation_token", id: confirmationToken.id};
const response = await fetch("/checkout/pay", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({credential}),
});
if (!response.ok) return restoreCheckout();
handlePaymentResult(await response.json());
} catch {
// The pay request may have reached Flint. Check before enabling Pay again.
showMessage("Payment status is unknown. Reload to check it.");
}
});
The credential is single-use and pays one payment leg. Send it to your backend over HTTPS and nowhere else: not to logs, analytics, or browser storage. A Stripe.js error here means Stripe rejected the form, and nothing was sent to Flint.
Step 5: pay#
Your backend sends the credential in payment_source with action: "pay". Flint creates a leg for the full outstanding balance and starts the payment attempt in the same request.
<!-- docs-test {"scenario":"main","status":200,"card":"pm_card_visa"} -->
curl -X POST https://api.withflintpay.com/v1/orders/ord_1kmn0aExample/pay \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: pay-ord_1kmn0aExample-ctoken_1kmn0aExample" \
-d '{
"action": "pay",
"payment_source": {"credential_type": "stripe_confirmation_token", "stripe": {"confirmation_token": "ctoken_1kmn0aExample"}},
"expected_outstanding_money": {"amount": 9900, "currency": "USD"},
"expected_version": 1790760000,
"buyer_contact": {"email": "ada@example.com"}
}'
{
"data": {
"order": {
"order_id": "ord_1kmn0aExample",
"status": "closed",
"payment_status": "paid",
"version": 1790760002,
"settlement_amounts": {
"paid_money": {"amount": 9900, "currency": "USD"},
"outstanding_money": {"amount": 0, "currency": "USD"}
}
},
"order_payment_attempt": {
"order_payment_attempt_id": "opat_1kmn0aExample",
"status": "succeeded",
"is_resumable": false,
"mode": "payment",
"expected_outstanding_money": {"amount": 9900, "currency": "USD"},
"payment_intents": [{
"payment_intent_id": "pi_1kmn0aExample",
"status": "succeeded",
"amount_money": {"amount": 9900, "currency": "USD"},
"tip_money": {"amount": 0, "currency": "USD"}
}],
"pending_actions": [],
"gift_card_redemptions": []
}
},
"request_id": "req_..."
}
The same request from a Node backend, building payment_source from what the browser posted:
app.post("/checkout/pay", async (req, res) => {
const {credential} = req.body;
// The order ID, balance, and version from the read the buyer approved.
const quote = await loadQuote(req.session);
const pay = {
orderId: quote.orderId,
idempotencyKey: crypto.randomUUID(),
body: {
action: "pay",
payment_source: {
credential_type: "stripe_confirmation_token",
stripe: {confirmation_token: credential.id},
},
client_action_type: "stripe",
expected_outstanding_money: quote.outstandingMoney,
expected_version: quote.version,
buyer_contact: {email: quote.buyerEmail},
},
};
await savePendingPay(req.session, pay);
// Also called by /checkout/restore to retry the same operation.
const result = await finishPendingPay(req.session, pay);
res.set("Cache-Control", "no-store").json(result);
});
function paymentResult(attempt) {
return {
status: attempt.status,
clientAction: attempt.pending_actions.find(({client_action}) =>
client_action?.type === "stripe"
)?.client_action ?? null,
};
}
Implement finishPendingPay to send pay.body to POST /v1/orders/{order_id}/pay with pay.idempotencyKey as the Idempotency-Key header and your API key as the bearer token. On success, save the attempt ID and order version, clear the pending request in the same session update, and return paymentResult(attempt). Forward a definitive API error and clear the pending request. For a timeout, lost response, or any other response that leaves the outcome uncertain, keep the pending request and retry it with the same body and key. Store it only on your backend, with access limited to this checkout, and keep the token out of logs. Idempotency covers errors and retries.
What to send#
expected_outstanding_moneyis the balance the buyer approved. If the order's outstanding balance no longer matches, Flint returns409 VERSION_CONFLICTbefore charging. It also returnsVERSION_CONFLICTwithparamapplied_discountswhen a promotion on the order stopped being available; Flint has already removed that discount, so a fresh read shows the new total. Either way, read the order again, show the buyer the new total, and ask them to approve it. Never resubmit silently. It is optional with your API key on an order with no open checkout session, and required otherwise: leaving it out then returns400 INVALID_REQUESTwith detail codeREQUIRED. Send it every time.expected_versionis the order'sversionfrom the same read. It catches an edit that leaves the balance unchanged, such as an item swapped for another at the same price. A mismatch returns409 VERSION_CONFLICTwithparamexpected_versionand the current version indetails[0].current_version. Starting a payment advances the version, so before the buyer tries again after a decline, take it from the order in the pay response.buyer_contact.emailrecords the guest buyer's email on the order, for the receipt. For a signed-in buyer, setcustomer_idon the order before payment instead, so their saved payment methods resolve.
pay also accepts client_action_type and, with an API key, payment_return_url. Other pay fields include payment_source, expected_outstanding_money, expected_version, buyer_contact, accepted_gift_card_allocation, save_payment_method, and save_payment_method_phone. Each action accepts only its own fields, and any other field returns 400 INVALID_REQUEST with detail code UNKNOWN_FIELD. Saving the card during checkout and gift cards are in Build your own checkout. To keep the card for the order's customer with your API key, send save_payment_method: true as Save a card while the customer pays describes.
Read the attempt, not the HTTP status#
A 200 carries every outcome: success, a decline, and a pause for 3D Secure. Flint never answers a decline with 402. Act on order_payment_attempt.status:
status | What to do |
|---|---|
succeeded | Show a confirmation. Fulfill from the webhook in step 7. |
requires_action | Run the client action in the browser, then resume. See step 6. |
failed | Nothing was charged. Show the leg's last_payment_error.message and collect a new card. |
canceled, expired | Nothing was charged. Start a new payment with a new credential. |
processing | Flint is collecting the payments, resolving their outcome, or applying it to the order. Don't start another payment or tell the buyer it failed. Wait for order.paid or read the attempt again; no merchant resume is required. Exceptional unresolved outcomes are reconciled by Flint operators. |
To retry after failed, collect a new credential and send action: "pay" again with a new Idempotency-Key. The declined leg stays on the order, and Flint reuses it when it is the order's one open leg and covers the balance. With several open legs, pay returns 400 INVALID_REQUEST with detail code REQUIRED and the legs in details[0].selectable_resources; select one with action: "confirm_payment_intents". Declines and payment attempts has each retry request, every attempt status, and how to recover a lost response.
Step 6: handle 3D Secure#
When the issuer asks for authentication, the attempt pauses with status: "requires_action", is_resumable: true, and a pending action:
{
"order_payment_attempt": {
"order_payment_attempt_id": "opat_1kmn0aExample",
"status": "requires_action",
"is_resumable": true,
"pending_actions": [{
"pending_action_id": "pendact_1kmn0aExample",
"subject": {
"payment_intent": {"payment_intent_id": "pi_1kmn0aExample"}
},
"action_type": "payment_authentication",
"expires_at": "2026-11-11T12:30:00Z",
"client_action": {
"type": "url",
"url": "https://payment-returns.example/payment-returns/actions/pendact_1kmn0aExample/bearer-token"
}
}]
}
}
Pay returns a Flint URL by default. With an API key, you can send payment_return_url on the order's pay request to choose where the buyer returns. With a checkout credential, set payment_return_url when you create the headless checkout session and omit it from pay and resume requests. Set client_action_type when starting a confirmation to choose the action type. The default is url, and a continuation keeps the original type if the field is omitted. Changing an existing action's type returns 409 ACTION_NOT_ALLOWED with reason field_locked on client_action_type.
A URL action has client_action: {"type": "url", "url": "https://<payment-return-host>/payment-returns/actions/pendact_.../<token>"}. Open each pending action's URL as a redirect, popup, or iframe before expires_at, the attempt's 30-minute cancel time. Treat the URL as a bearer credential: don't log or persist it. Flint's API response contains no Stripe client secret for this type. Stripe's authentication page receives what it needs to run the challenge, including the client secret for hosted 3DS2, so the browser holds that secret during the challenge. If a payment is confirmed with a payment method Flint didn't approve, Flint doesn't count the charge and returns it to the buyer; the payment intent ends canceled with cancellation_reason: payment_returned.
Flint returns the buyer to payment_return_url with exactly one subject parameter: payment_intent_id for a payment leg, or payment_method_id for a setup action whose subject is setup_payment_source. Without a return destination, the completion page posts one of these messages to its parent and opener:
{"type": "flint.payment_action.completed", "payment_intent_id": "pi_1kmn0aExample"}
{"type": "flint.payment_action.completed", "payment_method_id": "pm_1kmn0aExample"}
Check event.origin against the origin of the returned Flint action URL, event.source against the frame or popup you opened, and the message subject against the pending action. A completion message doesn't prove success. Read or resume the order payment attempt to learn its outcome. Return destinations accept HTTPS or a native app scheme; test mode also accepts HTTP loopback URLs. Credentials, queries, fragments, and executable schemes are refused.
If you use a popup, open it directly from the buyer's click. Once you have the action URL, a "Verify payment" button can open it synchronously. If you open a blank popup from the Pay click instead, keep its window reference, navigate it when the action URL arrives, and close it if no challenge is needed. Offer a redirect if the browser blocks the popup.
For an iframe, reserve at least 250 pixels of width and 400 pixels of height, the smallest standard 3D Secure challenge size. Give it more room when available and offer a full-page redirect on small screens. Follow the checkout CSP example to allow Stripe's challenge and Flint's return frame and to diagnose CSP reports in Safari.
Stripe and the issuer control the challenge's appearance. Flint's action URL has no dark theme option, and Stripe Elements' appearance settings only style Elements. A light challenge can appear inside a dark checkout.
For a step that can't open as a URL, pay returns 409 ACTION_NOT_ALLOWED, reason provider_action_unsupported. Continue the same attempt with client_action_type: "stripe". Reader payments support only stripe.
Opt in to Stripe.js#
Send client_action_type: "stripe" explicitly on the request that starts the confirmation. The client secret can also confirm the underlying payment with another card, so use it only with handleNextAction. Flint returns charges made with a payment method it did not approve.
Load Stripe.js using the pending action's publishable_key and account_id, not the order's earlier collection settings. For a split payment, account_id is null, so omit stripeAccount. The action's on_behalf_of identifies the collecting merchant; don't pass it to handleNextAction or use it as stripeAccount. After the challenge, resume the same order payment attempt without sending a new credential or splits.
The Node sample in step 5 opts in for this single-card flow. Run the Stripe action from a Verify payment click. The same result handler is used after pay, resume, and page restore.
const verify = document.querySelector("#verify-payment");
const submit = document.querySelector("#submit");
function handlePaymentResult(result) {
verify.hidden = true;
verify.onclick = null;
submit.disabled = true;
if (result.status === "succeeded") return showConfirmation();
if (["processing", "finalizing"].includes(result.status)) {
return showMessage("Payment is processing. Reload to check its status.");
}
if (result.status === "requires_action") {
const action = result.clientAction?.stripe;
if (!action) return showMessage("Waiting for authentication. Reload to check its status.");
showMessage("Verify your payment to continue.");
verify.textContent = "Verify payment";
verify.hidden = false;
verify.onclick = async () => {
verify.hidden = true;
verify.onclick = null;
try {
const actionStripe = Stripe(action.publishable_key, action.account_id ? {stripeAccount: action.account_id} : {});
const {error} = await actionStripe.handleNextAction({
clientSecret: action.payment_intent.client_secret,
});
// Resume even if Stripe.js reports an error.
const response = await fetch("/checkout/resume", {method: "POST"});
if (!response.ok) return restoreCheckout();
const resumed = await response.json();
handlePaymentResult(resumed);
if (error && resumed.status === "requires_action") showMessage(error.message);
} catch {
showMessage("Payment status is unknown. Reload to check it.");
}
};
return;
}
showMessage(paymentMessage(result));
// Refresh the quote before collecting another credential.
if (["failed", "canceled", "expired"].includes(result.status)) {
verify.textContent = "Reload checkout";
verify.hidden = false;
verify.onclick = () => window.location.reload();
}
}
async function restoreCheckout() {
submit.disabled = true;
verify.hidden = true;
verify.onclick = null;
try {
const response = await fetch("/checkout/restore", {method: "POST"});
if (!response.ok) throw new Error("Checkout state unavailable");
const {paymentCollection, amountLabel, result} = await response.json();
if (result) handlePaymentResult(result);
if (paymentCollection) {
verify.hidden = true;
verify.onclick = null;
mountPaymentElement(paymentCollection);
submit.textContent = `Pay ${amountLabel}`;
submit.disabled = false;
}
} catch {
showMessage("Couldn't load checkout. Reload to try again.");
}
}
// Fires on a fresh load, reload, and when Back restores the page from cache.
window.addEventListener("pageshow", restoreCheckout);
In this sample, showMessage writes to #payment-message, showConfirmation displays the paid state, and paymentMessage displays the failed, canceled, or expired outcome and tells the buyer to try again. Serve the script before pageshow.
Tie both backend routes to the same signed browser session used in step 5. Use your own CSRF and origin checks and send Cache-Control: no-store on responses. Serialize pay and restore requests for the same checkout. If a pay request is already pending, resolve it before accepting a new credential.
POST /checkout/restoreloads the session's order ID and any saved attempt ID. If the session has a pending pay request, resolve it first withfinishPendingPay. Keep Pay disabled until that request resolves, even if the order read shows no active attempt. Read the order and checkpayment_statusfirst. If it's paid, return{result: {status: "succeeded"}}. Otherwise, prefer the order'sactive_payment_attemptover the saved ID and read the full attempt. If it'srequires_actionandis_resumableis true, resume it once and use the returned attempt. For an active payment, return{result: paymentResult(attempt)}and keep Pay disabled. If the order can accept a new payment, save its fresh quote and return{paymentCollection: order.payment_collection, amountLabel}, whereamountLabelis the freshly formatted total, along with the last failed, canceled, or expired result when available.POST /checkout/resumeloads the attempt's ID from the session and reads the full attempt to get its originalexpected_outstanding_money. Resume if it's still resumable. If the attempt is processing or has already finished, return its current result. When restore finds an attempt through the order, save its ID in the session so the resume route can load it. Both routes use the samepaymentResultmapping as pay. Never persist the Stripe client secret or a Flint action URL.
If your return URL opens the checkout page again, use the same restore path. Use a fresh resume idempotency key for each new resume operation and reuse it when retrying that same request. Read the order and attempt through your backend even if the buyer arrives with a payment intent ID in the URL.
Your backend resumes the attempt with action: "resume" and its order_payment_attempt_id:
<!-- docs-test {"skip":"Requires a completed browser 3DS challenge before continuation; API-only test does not complete authentication."} -->
curl -X POST https://api.withflintpay.com/v1/orders/ord_1kmn0aExample/pay \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: resume-opat_1kmn0aExample-1" \
-d '{
"action": "resume",
"order_payment_attempt_id": "opat_1kmn0aExample",
"expected_outstanding_money": {"amount": 9900, "currency": "USD"}
}'
- Use a new
Idempotency-Key. Reusing the start request's key with a resume body returnsIDEMPOTENCY_KEY_REUSED. - Send no credential. The resume continues the same attempt with the credential it already has. The sample sends
order_payment_attempt_idandexpected_outstanding_money. Sendingpayment_sourcereturns400 INVALID_REQUESTwith detail codeUNKNOWN_FIELD. - The amount guard checks the attempt. On a resume,
expected_outstanding_moneyis compared with the amount frozen on the attempt when it started, not the live balance. A mismatch returnsVERSION_CONFLICTwith the attempt's amount indetails[0].expected_attempt_outstanding_money.
With an API key, you can instead confirm the leg's payment intent again without payment_source, as Finish 3D Secure shows. A resume returns 200 with data.order and data.order_payment_attempt, the same shape as step 5. If the attempt finished before the buyer returned, the response includes its recorded outcome, such as succeeded, failed, or canceled. For processing or finalizing, wait for order.paid or read the attempt again before offering another payment. An attempt still waiting for authentication 30 minutes after it started is canceled. If another attempt already paid the order, resume returns 409 ACTION_NOT_ALLOWED with reason payment_collected. Finish 3D Secure covers each outcome.
Step 7: verify and fulfill#
Fulfill from the order.paid webhook, or from a fresh read of the order on your backend. A buyer can close the tab before your page hears the result, and a success message in the browser proves nothing to your server. Check the order's dispute_status before you fulfill (access rules).
<!-- docs-test {"scenario":"main","status":200,"expect":{"data.payment_status":"paid"}} -->
curl https://api.withflintpay.com/v1/orders/ord_1kmn0aExample \
-H "Authorization: Bearer YOUR_API_KEY"
Fulfill when payment_status is paid. Check payment_status, not status: an order can also close without payment, and closed_reason says why. A later refund doesn't reopen the order or change its payment_status.
Other credentials#
payment_source takes one of these credentials, chosen by credential_type. All of them use action: "pay" and the same attempt, 3D Secure, and retry flow. A fourth credential, reader, presents a card on a reader and belongs to card-present payments.
credential_type | Field | Where it comes from |
|---|---|---|
stripe_payment_method | stripe.payment_method | A pm_... from stripe.createPaymentMethod |
stripe_confirmation_token | stripe.confirmation_token | A ctoken_... from stripe.createConfirmationToken |
payment_method | payment_method_id | A saved Flint payment method belonging to the order's customer |
Your API key accepts any of them, whatever next_step the read returned. A saved payment method must belong to the customer paying, so set customer_id on the order before you pay with one. Listing and choosing saved cards is in Build your own checkout.
Collect under a checkout session#
A headless checkout session gives the buyer's side of checkout its own credential. Create one when that side needs Flint delivery selection, a checkout expiry, the checkout customer's saved payment methods, card saving, or a receipt resend. Create it on your backend with surface: "headless":
<!-- docs-test {"scenario":"headless","status":201,"fixtures":{"order":9900},"expect":{"data.status":"open"}} -->
curl -X POST https://api.withflintpay.com/v1/checkout-sessions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: checkout-pro-annual-001" \
-d '{
"type": "order",
"order_id": "ord_1kmn0aExample",
"surface": "headless",
"page_origin": "https://shop.example.com",
"payment_return_url": "https://shop.example.com/checkout/return"
}'
The response is the checkout session with checkout_auth_token among its fields. It has no url, because there is no Flint page to send the buyer to. page_origin is the origin of your checkout page, and only that page can show the gift card challenge. The optional payment_return_url is where Flint sends the buyer after a redirect action. It's required to offer Affirm; see Affirm and ACH debit.
Requests with the checkout credential send it as the bearer token, with no API key. The token names its session, so no session ID goes beside it:
Authorization: Bearer ckat_1kmn0aExample
A request carries either the checkout credential or your API key, never both. In the SDKs, the checkout auth mode sends it for you.
Under the checkout credential, the flow above changes in three places:
- The order read returns
next_step: "create_confirmation_token", so the browser callsstripe.createConfirmationTokenand your backend sendscredential_type: "stripe_confirmation_token". expected_outstanding_moneyis required on every pay and resume.- The credential reaches only this checkout: its session and order, the buyer's delivery, promotion, tip, and tax choices, the checkout customer's saved payment methods, payment, canceling its own order's legs, and the receipt resend. Manual-capture legs, refunds, and other merchant operations use your API key.
Keep the credential on your backend, tied to your own signed browser session, and relay checkout calls through your backend with your own CSRF and origin checks. Never put it in local storage, URLs, logs, or analytics. Decide whether you need a checkout session has the full list of what it can do, and Securing a headless checkout covers the boundary and what changes for PCI scope once your JavaScript runs on the payment page.
Pay in more than one leg#
Split tender, partial payment, and a staged amount need legs you create first, with POST /v1/payment-intents and order_id. Collect a credential for each leg in your own UI, then confirm them together with action: "confirm_payment_intents", one entry per leg in payment_intents. While legs exist, payment_collection.stripe.elements.selectable_payment_intents lists the ones the buyer can still pay, each with its own payment_collection. Split one payment across two cards walks through a two-card order request by request.
Hosted checkout pays an order with one payment method, so it can collect at most one unpaid leg, meaning a leg still waiting for a payment method or for its first confirmation:
- Creating a hosted checkout session for an order with two or more unpaid legs returns
409 RESOURCE_IN_USE, with the legs aspayment_intentreferences indetails[0].blocking_resources. - While a hosted session is open, creating a leg on an order that already has an unpaid one returns
409 RESOURCE_IN_USE.details[0].blocking_resourceslists the unpaid leg, anddetails[0].current_resourcenames the session.
In either case, cancel a leg with POST /v1/payment-intents/{payment_intent_id}/cancel, or collect the split payment in your own UI. A headless checkout session has no such limit, because your UI collects each leg.
Manual capture#
To authorize now and capture later, create one leg with "capture_method": "manual" through POST /v1/payment-intents with order_id, then confirm it with action: "confirm_payment_intents". The attempt ends requires_capture, and the order stays open and unpaid until you capture.
Capture with POST /v1/payment-intents/{payment_intent_id}/capture, or release the hold with /cancel. Neither takes an attempt ID. Both accept expected_version, which is the PaymentIntent's own version, not the order's. A stale value returns 409 VERSION_CONFLICT before Flint contacts Stripe, so nothing is captured or released. Stripe events also advance the leg's version, so read the leg just before you capture, and on a conflict read it again and check status and capturable_money before you decide.
A manual-capture attempt confirms exactly one leg, so split payment with delayed capture is refused. Amounts, partial capture, and authorization expiry are in Manual capture on orders.
Divide a payment between sellers#
Send splits on POST /v1/payment-intents, or on POST /v1/orders/{order_id}/pay with action: "pay". Each split names a seller's partner_app_install_id and a positive amount_money in the payment's currency. This divides one payment's funds between merchants. Split tender divides how the buyer pays.
{
"action": "pay",
"payment_source": {
"credential_type": "stripe_confirmation_token",
"stripe": {"confirmation_token": "ctoken_buyer"}
},
"splits": [
{
"partner_app_install_id": "pinst_01KF3A8C2D4E6F8G0H2J4K6M8N",
"amount_money": {"amount": 6000, "currency": "USD"},
"description": "Order 1042: mugs",
"external_reference_id": "1042-mugs"
}
]
}
Use the collecting merchant's own credentials. The seller must approve splits on that merchant's partner app and be ready to receive payouts. For a staged split payment, mount Elements using that payment's payment_collection. Its stripe.account_id is null, and stripe.on_behalf_of is the collecting merchant's Stripe account ID.
If you send splits with action: "pay", the split payment doesn't exist when you collect the token. Use the order's payment_collection.stripe.account_id as on_behalf_of in the settings you pass to mountPaymentElement above, and set account_id to null so Stripe.js initializes without stripeAccount.
const collection = order.payment_collection.stripe;
mountPaymentElement({
stripe: {...collection, on_behalf_of: collection.account_id, account_id: null},
});
If the attempt reports last_payment_error.code: "confirmation_token_account_mismatch", use the failed leg's collection guidance on the order to create Elements with the correct account. Collect a new token and confirm the existing leg.
On pay, the split total must fit the processor payment after gift cards and Flint's largest fee for its payment options, leaving one minor unit for the collecting merchant. Seller splits require a processor payment. They aren't accepted when gift cards cover the whole order or its balance is zero. Saved payment credentials, save_payment_method: true, and platform_fee can't be combined with splits. Only action: "pay" accepts new splits; confirm existing split legs with action: "confirm_payment_intents" and a new confirmation token for each leg.
Splits are part of the idempotency fingerprint and stay fixed after creation, except for final amounts at capture. See seller approval and payment splits for admission, amount limits, and seller payment timing. Checkout sessions, payment links, invoices, and subscriptions don't accept splits.
Errors#
A declined card is not an error: it comes back as a 200 with a failed attempt. These are the errors this flow returns for misuse or changed state.
Test it#
In a sandbox, enter these cards in the Payment Element with any future expiry date and any CVC:
| Card | What happens |
|---|---|
4242 4242 4242 4242 | The payment succeeds and the order becomes paid. |
4000 0025 0000 3155 | The attempt returns requires_action. Complete the challenge and the resume succeeds; fail it and the attempt ends failed. |
4000 0000 0000 0002 | The attempt ends failed with card_declined, so you can exercise the retry. |
Testing lists every test card. To run these scenarios from a terminal without a browser, pay with a Stripe test token such as pm_card_visa, as in Pay from the API with a test token.