# Payment Intents

URL: https://doc.securepayapi.com/payment-intents
Last updated: 2026-11-12

> A Payment Intent represents a payment you want to collect — one-off or the first charge of a subscription. Create it on your server, complete it in the browser, confirm it on your server.

A **Payment Intent** represents a single payment you want to collect. You create
it on your server with the amount and currency, complete it in the browser with
the card, and then **confirm it on your server** before you deliver anything.

## Create a Payment Intent

Call the API with your secret key. Amounts are in the smallest currency unit
(cents). Only `amount` and `currency` are required; every other field is
optional:

```bash
curl https://checkout.securepayapi.com/api/v1/payment-intents \
  -H "Authorization: Bearer sp_secret_…" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 2000,
    "currency": "USD",
    "reference": "order_123",
    "externalid": "shop-123-2026-10-28",
    "descriptor": "ACME Store order 123",
    "description": "Blue hoodie, size M",
    "metadata": { "order_id": "123", "customer_id": "cust_88213" },
    "theme": "dark",
    "mode": "live"
  }'
```

| Field | What it does |
| --- | --- |
| `amount`, `currency` | What is charged. `USD` in v1. The browser can never change it. |
| `reference` | Your order id. Returned when you [read the intent back](#confirm-the-payment-on-your-server). |
| `externalid` | Your identifier **on the transaction**: it is forwarded to the payment platform and comes back in [webhooks](https://doc.securepayapi.com/webhooks) and on the [transaction](https://doc.securepayapi.com/transactions). When omitted, the intent `id` is used on the transaction. **Keep it to 128 characters**: this endpoint accepts up to 200, but a longer value than 128 makes every payment attempt fail when the customer submits the card. It can also be [set later](#set-your-reference-later), while the intent is unpaid. |
| `descriptor`, `description` | Accepted and stored, but **not applied to the payment at present**. The text on the customer's statement is your account's billing descriptor (dashboard → **Settings**), not this field. |
| `metadata` | Flat string key–value pairs, stored on the intent and returned when you read it back. It stays with the intent: the payment platform does not keep it, so it does not appear on the transaction or in webhooks. |
| `notify_url` | An `https` address on your server that is called when this payment goes through, so your order does not depend on the customer's browser — see [Payment notification](https://doc.securepayapi.com/api-reference#payment-notification). |
| `theme` | `light` (default) or `dark` — the widget's colour scheme. |
| `mode` | `live` (default) or `sandbox` — see below. |
| `subscription` | Makes this payment the setup of a **recurring agreement** — see [Recurring payments](#recurring-payments-subscriptions). |

There is **no idempotency key**: a retried `POST` creates a second intent. If a
create call times out, create a new intent for the order and use only the one
whose `id` you stored.

Limits and validation for each field are in the [API reference](https://doc.securepayapi.com/api-reference#create-a-payment-intent).

The response includes a `client_secret`:

```json
{
  "id": "k3m9q2x7v1b8n4c6d0f5g7h2",
  "client_secret": "pi_k3m9q2x7v1b8n4c6d0f5g7h2_secret_…",
  "amount": 2000,
  "currency": "USD",
  "status": "requires_payment",
  "mode": "live"
}
```

Pass the `client_secret` to the [JavaScript SDK](https://doc.securepayapi.com/sdk) or the
[embedded checkout](https://doc.securepayapi.com/embedded-checkout) widget to collect the card.

## Live or sandbox

Whether a payment is real or a test is decided **at intent creation**, with the
`mode` field — not in the browser:

```bash
curl https://checkout.securepayapi.com/api/v1/payment-intents \
  -H "Authorization: Bearer sp_secret_…" \
  -H "Content-Type: application/json" \
  -d '{ "amount": 2000, "currency": "USD", "mode": "sandbox" }'
```

| `mode` | Result |
| --- | --- |
| `live` (default) | A real payment — real money moves. |
| `sandbox` | A test payment — pay with a [test card](https://doc.securepayapi.com/sandbox#test-cards), no money moves. |

`mode` is fixed on the intent and the browser cannot change it, so a buyer can
never move a live payment into sandbox. If you mount the widget with
`mode: 'sandbox'` on a **live** intent, the widget refuses to load and reports a
`mode_mismatch` error — a guard for pages still passing the old option. The one
that decides is the `mode` you set here, on the server. See [Sandbox](https://doc.securepayapi.com/sandbox).

## The client secret

- It is the single credential that lets the browser complete this payment —
  treat it like a password and only hand it to your own customer's session.
- It cannot read or change anything else on your account.
- It is valid for **7 days** and the payment can succeed **once**. After a
  declined attempt the same intent can be retried with another card until it
  expires. An intent whose capture outcome is **uncertain** (the widget reported
  `status: "pending"`) is closed to further attempts — money may already be
  moving.

## Payment statuses

| Status | Meaning |
| --- | --- |
| `requires_payment` | Nothing has been charged. This is the status at creation **and while the customer enters a card, approves a wallet sheet or passes 3-D Secure** — an attempt that never reaches the charge (an abandoned or failed authentication, a closed sheet) leaves it here. `transaction_reference` may already be set: it is bound when an attempt starts, not when it captures. |
| `processing` | The **charge has been sent** and its result is not final yet. Normally a moment; see below for when it stays. |
| `succeeded` | Payment captured. `paid_at` is set. |
| `failed` | The last charge was declined — nothing was taken, and the customer can retry until the intent expires. It keeps reading `failed` while the customer enters another card, and turns `processing` only when that new charge is sent. |

An intent past its 7-day window (`expires_at`) can no longer be paid, whatever
its status reads — there is no separate `expired` status; compare `expires_at`
with the current time.

> **Warning:**
`processing` means **money may have moved**. Never treat it as unpaid and never
treat it as paid: wait, then read the intent again.

It can **stay** `processing` in two cases, both rare:

- the charge ended with an **uncertain outcome** (`status: "pending"` in the
  browser): the intent keeps `paid_at: null` and is **closed to further
  attempts**, so the customer cannot be charged twice;
- the answer to the charge **never arrived** (a network failure between us and
  the payment platform): the intent can still be retried.

The API does not distinguish the two, and the intent can still turn
`succeeded` later. Do not fulfil and do not ask for payment again until the
intent reads `succeeded`, or the [transaction](https://doc.securepayapi.com/transactions) or the dashboard
tells you whether the money moved.

## Set your reference later

A store often knows its order number only after the intent exists. While the
intent is unpaid you can set (or clear) its `externalid`:

```bash
curl https://checkout.securepayapi.com/api/v1/payment-intents/k3m9q2x7v1b8n4c6d0f5g7h2 \
  -H "Authorization: Bearer sp_secret_…" \
  -H "Content-Type: application/json" \
  -d '{ "externalid": "order-10452" }'
```

`externalid` is a string of up to 128 characters (trimmed), or `null` to clear
it. The answer is `{ "id": "…", "externalid": "order-10452" }`. The new value
travels with the **next** payment attempt; an attempt already started keeps the
reference it was opened with — which is the case for Apple Pay and Google Pay,
prepared as soon as the widget loads. The call does not rewrite an existing
transaction and does not change `reference`. A paid intent, or one closed after an
uncertain charge, answers `409`. See the
[API reference](https://doc.securepayapi.com/api-reference#update-the-external-id).

## Confirm the payment on your server

The browser saying "success" is **not evidence** — that message reaches your page
through the customer's own browser. Before you ship goods or activate anything,
read the intent back with your secret key and compare it with your order:

```bash
curl https://checkout.securepayapi.com/api/v1/payment-intents/k3m9q2x7v1b8n4c6d0f5g7h2 \
  -H "Authorization: Bearer sp_secret_…"
```

```json
{
  "id": "k3m9q2x7v1b8n4c6d0f5g7h2",
  "status": "succeeded",
  "amount": 2000,
  "currency": "USD",
  "mode": "live",
  "reference": "order_123",
  "externalid": "shop-123-2026-10-28",
  "metadata": { "order_id": "123", "customer_id": "cust_88213" },
  "transaction_reference": "LU494ZZ07K7814E3",
  "last_attempt": null,
  "created_at": "2026-10-28T19:02:11.000Z",
  "expires_at": "2026-11-04T19:02:11.000Z",
  "paid_at": "2026-10-28T19:04:58.000Z"
}
```

Check all of these before marking the order paid:

1. **The id is the one you created for this order** — stored when you created
   the intent, never one the browser handed you. Any succeeded intent passes a
   status check, including one the same customer legitimately paid earlier.
2. `status` is `succeeded` and `paid_at` is set.
3. `amount` and `currency` equal your order.
4. `mode` is `live` — a `sandbox` intent moved no money.

Store `transaction_reference`: it is the payment platform's reference for this
payment (the `id` in [webhooks](https://doc.securepayapi.com/webhooks) and on the
[transaction](https://doc.securepayapi.com/transactions)), and what refunds, reconciliation and support work
with. `externalid` reads `null` here when you never set one — the transaction
then carries the intent `id`.

> **Warning:**
**Google Pay with a bank redirect.** When the customer pays with Google Pay in
the widget and the bank sends them through a redirect 3-D Secure page, the
payment can be captured while the intent still reads `requires_payment`. For an
intent that stays `requires_payment` after the customer approved a wallet
payment, look the payment up before asking for another one: read the
transaction with `GET https://app.securepayapi.com/api/v1/transactions/{transaction_reference}`
(see [Transactions](https://doc.securepayapi.com/transactions)) or check the dashboard.

If you passed a `notify_url`, our server also calls it when the payment goes
through. That call is unsigned and is only a cue to run the same check: read
the intent back and settle from that answer — see
[Payment notification](https://doc.securepayapi.com/api-reference#payment-notification).

## Recurring payments (subscriptions)

A Payment Intent can set up a **recurring agreement**: the customer pays the
first charge in the widget, consents to the terms, and the payment platform then
stores the card securely and bills the following periods itself — you never
handle the card.

The plan (price, interval, terms) is created once with your secret key through
`POST /api/v1/subscription-plans` — see [Recurring payments](https://doc.securepayapi.com/recurring-payments)
for plans, variable pricing, trials, renewals and cancellation. The intent
then names that plan:

```bash
curl https://checkout.securepayapi.com/api/v1/payment-intents \
  -H "Authorization: Bearer sp_secret_…" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 1999,
    "currency": "USD",
    "reference": "membership-42-setup",
    "subscription": {
      "planExternalReference": "monthly-gold",
      "shopperExternalReference": "cust_88213",
      "subscriptionExternalReference": "membership-42",
      "termsVersion": "2026-10-01",
      "termsText": "I authorize … USD 19.99 every month … until I cancel.",
      "termsHash": "5d48345db32747eed3f5666e43c946652760795f35d09d81c4e0f6f29c353ed3",
      "billingAnchor": "2026-11-28T12:00:00-04:00",
      "billingTimezone": "America/New_York"
    }
  }'
```

| Field | What it is |
| --- | --- |
| `planExternalReference` | The plan, as you created it with `POST /api/v1/subscription-plans` **in the same `mode`** as this intent (a sandbox plan does not exist for a live intent). `currency` must equal the plan's; `amount` must equal a fixed plan's amount, or be above zero and at most a variable plan's `maximumAmount`. **Checked when the customer pays, not here** — see the note below the table. |
| `shopperExternalReference` | **Your** customer id — never an email or other personal data. |
| `subscriptionExternalReference` | Your id for this agreement. You use it later to read, pause or cancel it. |
| `termsVersion`, `termsHash` | Must equal the plan's current terms. `termsHash` is the lowercase SHA-256 of `termsText`. |
| `termsText` | The exact consent text the customer sees and agrees to. It is checked against `termsHash`, so what is shown is what was hashed. |
| `billingAnchor` | When recurring billing starts: ISO-8601 **with an explicit UTC offset**, at least one hour in the future at creation — and still in the future when the customer pays, otherwise the payment is refused (the intent lives 7 days, so give the anchor room). |
| `billingTimezone` | IANA zone the schedule follows (default `UTC`). Validated and canonicalised (`america/new_york` is stored as `America/New_York`). |

For every rule and limit see the
[API reference](https://doc.securepayapi.com/api-reference#the-subscription-object). Billing cadence is
**not** a field here — it belongs to the plan.

> **Warning:**
Creating the intent checks only the **shape** of the block, and that `termsText`
hashes to the `termsHash` you sent. Whether the plan exists and is active,
whether the terms are the plan's current ones, and whether the amount and
currency fit the plan are checked by the payment platform **when the customer
pays**. A wrong plan reference, outdated terms or a wrong amount therefore give
you a normal `200` intent that fails in the widget. Create a test payment in
[sandbox](https://doc.securepayapi.com/sandbox) after every plan change, and do not reuse intents created
before a new plan version.

What changes in the widget, automatically:

- it shows a **Subscription — recurring payment** badge, the first charge, when
  recurring billing starts, the full `termsText` and a consent checkbox — the
  **Subscribe** button stays disabled until the customer ticks it (in external
  submit mode `submit()` is refused instead);
- the customer's **email is required** (the platform sends renewal notices and
  receipts to it) — `email: false` on the SDK is ignored, and the server refuses
  the attempt without one;
- **cards only** — Apple Pay and Google Pay are not offered for a subscription
  setup, and the server refuses a wallet attempt on such an intent.

The `success` result carries `subscription: { status: "pending_activation",
externalReference }`. The payment is captured, but the agreement becomes
**active only once the payment platform has confirmed the authorisation** — a
step that happens on its side moments later. There is **no webhook for
activation**: read the agreement with your secret key
(`GET /api/v1/subscriptions/{externalReference}`, see
[Recurring payments](https://doc.securepayapi.com/recurring-payments#activation)) until its status is
`active` before treating it as live.

> **Note:**
To replace the card on an existing agreement that has an unpaid period, create
an intent for the exact recovery amount with
`"subscription": { "operation": "recoverPaymentMethod", "subscriptionExternalReference": "…", "termsVersion": "…", "termsHash": "…", "termsText": "…" }`.
The widget then collects the new card under the same rules (consent box, required
email, cards only), with the texts adjusted: the badge reads **Subscription —
card update**, the heading **Update the card for your subscription**, the
amount is labelled **Total** and the button **Pay**; there is no billing-start
line, since the agreement already has its schedule.

## Server is the source of truth

The amount, the mode and the subscription terms live on the Payment Intent you
created server-side. The browser never sets or changes them, so a customer
cannot alter what they are charged — or what they agree to.
