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

# Create Session

> Create a payment session for a customer and order — standard checkout or mandate setup.

Create a short-lived, single-use session tied to one merchant, customer, and order. The response gives you a `session_token` + `iframe_url` for the frontend — embed the iframe via the [SDK](https://docs.prava.space/sdk/overview.md) or open the [hosted checkout](https://docs.prava.space/sdk/integration-modes.md) directly.

`POST /v1/sessions` · Authenticated with your secret key.

## Which flow?

> [tab] Standard checkout
>
> Omit `mandate_setup` (or send `intent: "checkout"`). The session collects a card and charges immediately.

> [tab] Mandate setup
>
> Include a `mandate_setup` block with `intent: "mandate_setup"`. The session is **authorize-only**: it returns an `iframe_url` for passkey approval, and completing setup issues **no** payment credentials. Charge later with [Charge a Mandate](https://docs.prava.space/api-reference/mandate-charge.md). There is no separate `POST /v1/mandates` create endpoint — a [mandate](https://docs.prava.space/concepts/mandates.md) is always set up through this endpoint.

## Mandate setup

**Mandate creation is part of the Session APIs — this endpoint is how mandates are created.** Send a `mandate_setup` block (see [Body](#body)) with `intent: "mandate_setup"` and the session becomes authorize-only: the response carries an `iframe_url` where the owner approves **once** with their passkey. Completing setup does not issue payment credentials. Once the mandate is `active`, charge it with [Charge a Mandate](https://docs.prava.space/api-reference/mandate-charge.md) within its approved terms — no further passkey needed.

The `mandate_setup` field reference below covers `recurring_frequency`, `merchant_scope`, `max_charges`, and `valid_until`; see [Mandates](https://docs.prava.space/concepts/mandates.md) for the concept and guardrails.

> [!NOTE]
>
> **Choosing a card source.** Omit `card` to let the cardholder select or enter a card in the collection surface. Send `card.card_id` to pre-select an already-enrolled card, or `card.vault_ref_id` (a Skyflow UUID) for the vault-ref flow. Send **exactly one** — if both are present, `card_id` wins.
> After collection, [Get Payment Result](https://docs.prava.space/api-reference/get-payment-result.md) returns the card bound to
> each transaction as `transactions[].card_id`.

## Body

**user\_id** `string` *required*

Unique identifier for the customer in your system (1–255 chars). Required for merchant (secret-key) sessions — omitting it returns `400 VAL_2001`.

**user\_email** `string` *required*

Customer email. Required for merchant sessions. Must be a valid email address.

**total\_amount** `string` *required*

Total order amount as a decimal string with up to 2 decimals, e.g. `"49.99"`. Need not equal the sum of line items (it may include tax, shipping, and fees). This value becomes the authorized amount cap.

**currency** `string` *required*

ISO 4217 code — 3 uppercase letters — and must be a **supported currency**. Supported: USD, EUR, GBP, INR, CAD, AUD, JPY, SGD, AED, HKD, MXN, BRL, CHF, CNY, NZD, SEK, NOK, DKK, ZAR, THB, KRW, PLN, TWD, PHP, IDR, MYR, CZK, ILS, CLP, ARS, COP, PEN, SAR, QAR, KWD, BHD, OMR, EGP, NGN, KES, GHS, TZS, UGX, PKR, BDT, LKR, VND, MMK, NPR. Other codes are rejected.

This is your **pricing currency** and is independent of the card's issuing country: there is no requirement that it match `country_code_iso2` (the merchant's location) or the cardholder's country. A US-issued card can pay an INR-denominated session; the card network settles the cross-currency conversion. Price in whatever currency your product uses — you don't need to re-denominate.

**purchase\_context** `object` *required*

What is being bought. Two modes — pick **one**:

* **From a quote** — send `quote: true` and the opaque `quote_id` (`qte_…`) returned when the quote
  was created. Merchant and product details come from that quote, so nothing else is needed.
* **Custom** — omit `quote` (or send `false`) and describe the merchant and products yourself in `custom`.

**purchase\_context properties**

**quote** `boolean` (default: false)

Set `true` to build the session from an existing quote. When `true`, pass `quote_id` and
nothing else — `custom` must be omitted. When `false` or absent, `custom` is required and
`quote_id` must be omitted.

**quote\_id** `string`

**Required when `quote` is `true`.** The opaque public quote id returned by quote creation
(for example, `qte_…`). The quote carries the merchant, products, and locked price.
Create the session before the quote expires; its expiry is separate from the session's
lifetime. `total_amount` and `currency` must match the quote's final total.
Do not send a merchant checkout-session id.

**custom** `object[]`

**Required when `quote` is not `true`.** Exactly one entry — multi-merchant sessions are not
yet supported.

**custom\[] properties**

**merchant\_details** `object` *required*

The **destination merchant** — the business the cardholder is buying from, **not your
application**. The `name` renders as the header on the checkout page and is forwarded to
Visa as the merchant of record for the token.

**merchant\_details properties**

**name** `string` *required*

Merchant display name. Sanitized to a Visa-safe character set (e.g. `H&M` → `HM`); must contain at least one usable character.

**url** `string` *required*

Merchant website URL. **Must use `https`** — the URL is forwarded to Visa.

**country\_code\_iso2** `string` *required*

Merchant country — 2 uppercase ISO 3166-1 letters, e.g. `"US"`.

**category\_code** `string`

Merchant category code (MCC). Free-form string, max 10 characters.

**category** `string`

Merchant category description, max 100 characters.

**product\_details** `object[]` *required*

At least one product.

**product\_details\[] properties**

**description** `string` *required*

Product description.

**unit\_price** `string` *required*

Unit price as a string, e.g. `"24.99"`.

**product\_id** `string`

Your external product identifier, max 50 characters.

**quantity** `integer` (default: 1)

Quantity of this product. Positive integer.

**effective\_until\_minutes** `integer` (default: 15)

How long the resulting mandate stays effective, in minutes. Positive integer.

**integration\_type** `string` (default: full\_checkout)

`full_checkout` (hosted redirect) or `embedding` (mount the iframe via the SDK). Read by the frontend to choose the surface.

**callback\_url** `string`

For hosted checkout: the URL Prava redirects the cardholder to after they finish. **Must use `https`**, max 2048 chars. Optional for all integration types.

**card** `object`

Pre-select a card. Send one of the two fields below (see the note above).

**card properties**

**card\_id** `string`

An enrolled card id (the `enrollmentId` from the SDK's [`collectPAN()`](https://docs.prava.space/sdk/cards/collect-pan), or a `card_id` from [List Cards](https://docs.prava.space/api-reference/list-cards.md)). Scoped to this customer + merchant.

**vault\_ref\_id** `string`

A Skyflow vault reference UUID. Triggers provisioning at session-create.

**mandate\_setup** `object`

Turns the session into mandate setup (authorize-only). See the Mandate setup tab above.

**mandate\_setup properties**

**intent** `string`

`mandate_setup` (authorize-only, no charge) or `checkout`. Defaults to `mandate_setup` when this block is present.

**recurring\_frequency** `string`

`one_time`, `weekly`, `monthly`, or `yearly`.

**merchant\_scope** `string`

`listed` (locked to this merchant) or `any` (any merchant). Recurring frequencies force `listed` — sending `any` with a recurring frequency returns `400 MANDATE_RECURRING_MUST_BE_SCOPED`.

**valid\_until** `string`

ISO 8601 datetime. **Ignored for `one_time`**, which is always clamped to 7 days. Recurring horizons: yearly 5y, monthly 2y, weekly 1y.

**max\_charges** `integer` (default: 1)

Maximum number of charges allowed against this mandate. Positive integer. (The per-charge *amount* cap is enforced separately, at the card network.)

**user\_phone** `string`

Customer phone number.

**user\_country\_code\_iso2** `string`

Customer country — 2 uppercase ISO 3166-1 letters.

**external\_order\_ref** `string`

Your external order reference id, max 255 chars.

**description** `string`

Human-readable description of the order.

**sandbox\_simulation** `object`

Optional, sandbox-only payment success simulation for quote-backed checkout. The exact shape
is `{ "stage": "payment", "outcome": "success" }`; both fields are required and additional
fields are rejected. Custom checkout, production, and mandate-setup sessions cannot use it.
Normal card collection and verification still run. An eligible terminal payment result can
complete the sandbox lifecycle while `observed_result` retains the actual outcome.
See [Sandbox simulation](https://docs.prava.space/api-reference/testing.md#simulate-successful-payment-completion).

## Response

**session\_id** `string`

Unique session identifier.

**session\_token** `string`

JWT authenticating client-side SDK calls within this session.

**iframe\_url** `string`

Secure card-collection (or, for mandate setup, passkey-approval) surface.

**order\_id** `string`

Internal order identifier.

**expires\_at** `string`

ISO 8601 timestamp when the session expires.

## Notes

* Sessions are **short-lived** and **single-use**, tied to a specific merchant, customer, and order.
* `session_token` and `iframe_url` are used on the frontend: embedded via the [SDK](https://docs.prava.space/sdk/overview.md), or opened directly for [hosted checkout](https://docs.prava.space/sdk/integration-modes.md).
* Sessions can be revoked before use via [`POST /v1/sessions/:id/revoke`](https://docs.prava.space/api-reference/revoke-session).

## Error responses

| Status | Code | Cause |
| - | - | - |
| 400 | `VAL_2001` | Validation error (missing/invalid fields; `user_id`/`user_email` missing on a merchant session; `quote: true` without a `quote_id`; `custom` missing when `quote` is not true). `details` names the fields. |
| 400 | `CARD_NOT_FOUND` | Pre-selected `card_id` does not exist for this customer + merchant |
| 400 | `CARD_INACTIVE` | Pre-selected card is not active |
| 400 | `MANDATE_RECURRING_MUST_BE_SCOPED` | Recurring frequency sent with `merchant_scope: "any"` |
| 400 | `SANDBOX_SIMULATION_NOT_ALLOWED` | Simulation requested outside sandbox, for a custom checkout, or for mandate setup |
| 401 | `AUTH_1001` | Invalid API key |
| 401 | `AUTH_1002` | Missing or invalid Authorization header |
| 409 | `QUOTE_SESSION_MISMATCH` | Session amount or currency differs from the quote's final total |
| 410 | `QUOTE_EXPIRED` | The quote expired before session creation |
| 429 | `TRIES_EXHAUSTED` | Sandbox test-transaction limit reached for this merchant |
| 500 | `MERCHANT_LOOKUP_ERROR` | Failed to load the merchant account for the key |
| 500 | `CONFIG_ERROR` | Server-side configuration issue (Visa or Skyflow not configured) |

```bash cURL theme={null}
curl -X POST https://sandbox.api.prava.space/v1/sessions \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "user_123",
    "user_email": "jane@example.com",
    "total_amount": "49.99",
    "currency": "USD",
    "purchase_context": {
      "custom": [{
        "merchant_details": { "name": "Acme Store", "url": "https://acme.example.com", "country_code_iso2": "US" },
        "product_details": [{ "description": "Widget", "unit_price": "24.99", "quantity": 2 }]
      }]
    },
    "integration_type": "full_checkout",
    "callback_url": "https://acme.example.com/return"
  }'
```

```bash cURL · From a quote theme={null}
curl -X POST https://sandbox.api.prava.space/v1/sessions \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "user_123",
    "user_email": "jane@example.com",
    "total_amount": "22.45",
    "currency": "USD",
    "purchase_context": {
      "quote": true,
      "quote_id": "qte_9f2c..."
    }
  }'
```

```python Python theme={null}
import requests

resp = requests.post(
    "https://sandbox.api.prava.space/v1/sessions",
    headers={"Authorization": "Bearer sk_test_..."},
    json={
        "user_id": "user_123",
        "user_email": "jane@example.com",
        "total_amount": "49.99",
        "currency": "USD",
        "purchase_context": {
            "custom": [{
                "merchant_details": {"name": "Acme Store", "url": "https://acme.example.com", "country_code_iso2": "US"},
                "product_details": [{"description": "Widget", "unit_price": "24.99", "quantity": 2}],
            }],
        },
        "integration_type": "full_checkout",
        "callback_url": "https://acme.example.com/return",
    },
)
```

```javascript JavaScript theme={null}
const resp = await fetch("https://sandbox.api.prava.space/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: "Bearer sk_test_...",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    user_id: "user_123",
    user_email: "jane@example.com",
    total_amount: "49.99",
    currency: "USD",
    purchase_context: {
      custom: [{
        merchant_details: { name: "Acme Store", url: "https://acme.example.com", country_code_iso2: "US" },
        product_details: [{ description: "Widget", unit_price: "24.99", quantity: 2 }],
      }],
    },
    integration_type: "full_checkout",
    callback_url: "https://acme.example.com/return",
  }),
});
```

```bash cURL · Mandate setup theme={null}
curl -X POST https://sandbox.api.prava.space/v1/sessions \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "user_123",
    "user_email": "jane@example.com",
    "total_amount": "40.00",
    "currency": "USD",
    "purchase_context": {
      "custom": [{
        "merchant_details": { "name": "Acme Store", "url": "https://acme.example.com", "country_code_iso2": "US" },
        "product_details": [{ "description": "Monthly plan", "unit_price": "40.00" }]
      }]
    },
    "mandate_setup": {
      "intent": "mandate_setup",
      "recurring_frequency": "monthly",
      "merchant_scope": "listed",
      "max_charges": 12
    }
  }'
```

```json 201 Standard theme={null}
{
  "session_id": "ses_9f2c...",
  "session_token": "eyJhbGciOi...",
  "iframe_url": "https://checkout.prava.space/s/ses_9f2c...",
  "order_id": "ord_4a1b...",
  "expires_at": "2026-07-26T12:15:00Z"
}
```

```json 201 Mandate setup theme={null}
{
  "session_id": "ses_7d1a...",
  "session_token": "eyJhbGciOi...",
  "iframe_url": "https://checkout.prava.space/s/ses_7d1a...",
  "order_id": "ord_88c2...",
  "expires_at": "2026-07-26T12:15:00Z"
}
```

```json 400 Validation theme={null}
{
  "error": {
    "code": "VAL_2001",
    "message": "Validation failed",
    "details": { "currency": "Unsupported currency code" }
  }
}
```

```json 401 Unauthorized theme={null}
{
  "error": { "code": "AUTH_1001", "message": "Invalid API key" }
}
```


## OpenAPI

````yaml api-reference/openapi.json POST /v1/sessions
openapi: 3.1.0
info:
  title: Prava Payments API
  description: >-
    Server-side REST API for Prava Payments. All requests are authenticated with
    your secret key (sk_test_* in sandbox, sk_live_* in production).
  version: 1.0.0
servers:
  - url: https://sandbox.api.prava.space
    description: Sandbox
  - url: https://api.prava.space
    description: Production
security:
  - bearerAuth: []
paths:
  /v1/sessions:
    post:
      summary: Create Session
      description: Create a new payment session for a customer and order.
      operationId: createSession
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSessionRequest'
      responses:
        '201':
          description: Session created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateSessionResponse'
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/Error'
        '429':
          $ref: '#/components/responses/Error'
        '500':
          $ref: '#/components/responses/Error'
components:
  schemas:
    CreateSessionRequest:
      type: object
      additionalProperties: false
      required:
        - user_id
        - user_email
        - total_amount
        - currency
        - purchase_context
      properties:
        user_id:
          type: string
          minLength: 1
          maxLength: 255
          description: Unique identifier for the customer in your system
        user_email:
          type: string
          format: email
          maxLength: 320
          description: Customer's email address
        total_amount:
          type: string
          minLength: 1
          pattern: ^\d+(\.\d{1,2})?$
          description: Total order amount in decimal format (e.g. "49.99")
        currency:
          type: string
          minLength: 3
          maxLength: 3
          pattern: ^[A-Z]{3}$
          description: >-
            ISO 4217 currency code — exactly 3 uppercase letters, and one of
            Prava's supported currencies (e.g. USD, EUR, GBP, INR) - other codes
            are rejected
        purchase_context:
          $ref: '#/components/schemas/PurchaseContext'
        user_phone:
          type: string
          description: Customer's phone number
        user_country_code_iso2:
          type: string
          minLength: 2
          maxLength: 2
          pattern: ^[A-Z]{2}$
          description: Customer's country — 2 uppercase ISO 3166-1 letters
        external_order_ref:
          type: string
          maxLength: 255
          description: Your external order reference ID
        description:
          type: string
          description: Human-readable description of the order
        integration_type:
          type: string
          enum:
            - full_checkout
            - embedding
          default: full_checkout
          description: >-
            How the card is collected. full_checkout = hosted redirect;
            embedding = mount the iframe via the SDK.
        callback_url:
          type: string
          format: uri
          pattern: ^https://
          maxLength: 2048
          description: >-
            For hosted checkout: the https URL Prava redirects the cardholder to
            after they finish. Optional for all integration types.
        card:
          type: object
          description: >-
            Pre-select a card. Send card_id OR vault_ref_id; if both are sent,
            card_id wins.
          properties:
            card_id:
              type: string
              minLength: 1
              description: An existing enrolled card ID
            vault_ref_id:
              type: string
              format: uuid
              description: A valid UUID referencing a vaulted card
        mandate_setup:
          type: object
          description: >-
            Turns the session into mandate setup (authorize-only). Absent =
            standard checkout.
          properties:
            intent:
              type: string
              enum:
                - checkout
                - mandate_setup
              description: >-
                mandate_setup = authorize-only (no charge/credentials). Defaults
                to mandate_setup when this block is present.
            recurring_frequency:
              type: string
              enum:
                - one_time
                - weekly
                - monthly
                - yearly
            merchant_scope:
              type: string
              enum:
                - any
                - listed
              description: >-
                Recurring frequencies force listed; any with a recurring
                frequency returns 400 MANDATE_RECURRING_MUST_BE_SCOPED.
            valid_until:
              type: string
              format: date-time
              description: >-
                Ignored for one_time (clamped to 7 days). Recurring horizons:
                yearly 5y, monthly 2y, weekly 1y.
            max_charges:
              type: integer
              minimum: 1
              default: 1
              description: Positive integer; per-charge cap is network-enforced.
        sandbox_simulation:
          type: object
          description: >-
            Sandbox-only success simulation for quote-backed payment sessions.
            Fixed at session creation; production, custom checkout, and mandate
            setup reject this option. Normal card collection and verification
            still run. See Testing in Sandbox.
          additionalProperties: false
          required:
            - stage
            - outcome
          properties:
            stage:
              type: string
              const: payment
            outcome:
              type: string
              const: success
    CreateSessionResponse:
      type: object
      properties:
        session_id:
          type: string
          description: Unique session identifier
        session_token:
          type: string
          description: JWT to authenticate client-side SDK operations within this session
        iframe_url:
          type: string
          description: URL for the secure card collection surface
        order_id:
          type: string
          description: Internal order identifier
        expires_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp when the session expires
    PurchaseContext:
      description: >-
        What is being bought. Two modes — send exactly one: quote: true +
        quote_id (session built from an existing quote), or custom (describe the
        merchant and products yourself).
      oneOf:
        - title: Custom checkout
          type: object
          additionalProperties: false
          required:
            - custom
          properties:
            quote:
              type: boolean
              const: false
              description: Omit or set to false when describing the purchase in custom.
            custom:
              type: array
              minItems: 1
              maxItems: 1
              description: >-
                Exactly one entry — multi-merchant sessions are not currently
                supported.
              items:
                $ref: '#/components/schemas/CustomPurchaseContext'
        - title: Quote checkout
          type: object
          additionalProperties: false
          required:
            - quote
            - quote_id
          properties:
            quote:
              type: boolean
              const: true
              description: Build the session from an existing quote.
            quote_id:
              type: string
              minLength: 1
              description: >-
                The opaque public quote ID returned by quote creation (for
                example, qte_...). Do not send a merchant checkout-session ID.
                Merchant and product details come from the quote.
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Machine-readable error code (e.g. VAL_2001, AUTH_1001)
            message:
              type: string
              description: Human-readable error message
            details:
              type: object
              description: >-
                Optional — included for validation errors to specify which
                fields failed
    CustomPurchaseContext:
      type: object
      required:
        - merchant_details
        - product_details
      properties:
        merchant_details:
          type: object
          required:
            - name
            - url
            - country_code_iso2
          properties:
            name:
              type: string
              minLength: 1
              description: Merchant display name
            url:
              type: string
              format: uri
              pattern: ^https://
              description: >-
                Merchant website URL. Must use https - the URL is forwarded to
                Visa.
            country_code_iso2:
              type: string
              minLength: 2
              maxLength: 2
              pattern: ^[A-Z]{2}$
              description: Two uppercase ISO 3166-1 country code (e.g. "US")
            category_code:
              type: string
              maxLength: 10
              description: Merchant category code
            category:
              type: string
              maxLength: 100
              description: Merchant category description
        product_details:
          type: array
          minItems: 1
          items:
            type: object
            required:
              - description
              - unit_price
            properties:
              description:
                type: string
                minLength: 1
                description: Product description
              unit_price:
                type: string
                minLength: 1
                description: Unit price as a string (no fixed decimal format enforced)
              product_id:
                type: string
                maxLength: 50
                description: Your external product identifier
              quantity:
                type: integer
                minimum: 1
                default: 1
                description: Quantity of this product
        effective_until_minutes:
          type: integer
          minimum: 1
          default: 15
          description: >-
            How long the mandate remains effective, in minutes. Positive
            integer, no maximum.
  responses:
    Error:
      description: Error response
      headers:
        X-Response-ID:
          $ref: '#/components/headers/XResponseId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  headers:
    XResponseId:
      description: >-
        UUID correlation identifier for this response. Include it when
        contacting Prava support.
      schema:
        type: string
        format: uuid
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Your secret key: sk_test_* (sandbox) or sk_live_* (production).'

````

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