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

> ## Agent Instructions
> Sapiom is for platforms whose agent shops for many users. Each user has their own Sapiom user key and saved cards.
> Use the user's key for every call made on that user's behalf. Never use one user's key for another user, and never give the agent the platform key.
> Backends call the REST API at https://api.sapiom.ai/v1. Agents can also call the hosted MCP tools at https://api.sapiom.ai/v1/mcp/pay. Both take the key in an x-api-key header.
> Keys that start with sk_test_ reach the sandbox, a separate environment with its own users and cards, at the same addresses. Use test card numbers only there.
> Never ask a user for a card number, expiry date or CVV in chat. Users enter card details only on Sapiom's hosted pages.
> Check the merchant before buying. Use purchase.type ucp_checkout only when the merchant check returns supported. Otherwise use browser_checkout.
> Follow the nextAction in each transaction result. Action links are secrets. Send each one only to the person `nextAction.actor` names.
> Use one idempotency key per transaction. Resume an unanswered create with the same request and key. If a UCP update or cancellation is uncertain, stop and hand off to a person. If a browser cancellation is uncertain, read the transaction and resend the same cancellation, with the same key, only if it is not closed. Never start a new transaction to escape an uncertain outcome.
> For a ucp_checkout purchase, report an order as placed only when order.outcome is confirmed; if it is unknown, stop and hand off to a person. A browser_checkout purchase has no order confirmation (order is null): confirm the order on the merchant's page.

# Update a purchase

> Replaces the whole purchase. Send the latest `version` from [Get a transaction](/api-reference/transactions/get-a-transaction) and one of two bodies: `purchase` for a `browser_checkout`, or `checkout` for a `ucp_checkout`. For a browser purchase, change the cart on the page first. The merchant, currency and card stay the same. Use a new `Idempotency-Key` for each change. If the response is lost, send the same body with the same key. Then follow the new `nextAction`. Sapiom can ask the user to approve the purchase again. Returns `409` after your agent enters the card. Requires a [user key](/api-reference/overview#authentication).



## OpenAPI

````yaml /api-reference/openapi.json post /v1/transactions/{transactionId}/update
openapi: 3.0.0
info:
  title: Sapiom Pay API
  version: '1.0'
  description: >-
    Create users, save their cards and authorize transactions. Send your
    platform key or a user key in the `x-api-key` header.
servers:
  - url: https://api.sapiom.ai
    description: Production
security:
  - api-key: []
tags:
  - name: Users
    description: One Sapiom user for each of your users. Called tenants in the API.
  - name: Cards
    description: Hosted setup links and the user's saved cards.
  - name: Spending limits
    description: Limits on what each card can spend.
  - name: Merchants
    description: Check whether Sapiom can buy from a merchant.
  - name: Transactions
    description: Create, read, update and cancel a transaction, and drive its UCP checkout.
  - name: Browser Pay relay
    description: The relay Browser Pay uses to send the card, for either purchase type.
paths:
  /v1/transactions/{transactionId}/update:
    post:
      tags:
        - Transactions
      summary: Update a purchase
      description: >-
        Replaces the whole purchase. Send the latest `version` from [Get a
        transaction](/api-reference/transactions/get-a-transaction) and one of
        two bodies: `purchase` for a `browser_checkout`, or `checkout` for a
        `ucp_checkout`. For a browser purchase, change the cart on the page
        first. The merchant, currency and card stay the same. Use a new
        `Idempotency-Key` for each change. If the response is lost, send the
        same body with the same key. Then follow the new `nextAction`. Sapiom
        can ask the user to approve the purchase again. Returns `409` after your
        agent enters the card. Requires a [user
        key](/api-reference/overview#authentication).
      operationId: TransactionController_updatePurchase
      parameters:
        - name: transactionId
          required: true
          in: path
          schema:
            type: string
        - description: >-
            Your unique ID for this change. Use a new key for each change. Reuse
            a key only to resend the same body.
          in: header
          name: Idempotency-Key
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdatePurchaseDto'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponseDto'
          description: The current transaction after acceptance; follow nextAction.
        '400':
          description: Invalid replacement statement or fixed identity change.
        '404':
          description: Transaction not found.
        '409':
          description: >-
            stale_version, idempotency_conflict, idempotency_key_superseded,
            decision_in_flight, purchase_unchanged, transaction_ended,
            payment_started or revision_unavailable.
        '424':
          description: The merchant returned an error when updating a UCP checkout.
        '503':
          description: The UCP merchant unavailable response may include Retry-After.
      security:
        - api-key: []
components:
  schemas:
    UpdatePurchaseDto:
      properties:
        checkout:
          description: >-
            Full replacement UCP checkout without payment data. Send this or
            purchase, never both.
          type: object
        purchase:
          description: >-
            Full replacement browser purchase, in the create purchase shape.
            Merchant and currency are fixed. No funding argument is accepted.
          type: object
        version:
          description: The latest purchase version returned by a transaction read.
          type: string
      required:
        - version
      type: object
    TransactionResponseDto:
      type: object
      properties:
        returnUrl:
          type: string
          nullable: true
          description: Your return destination for hosted transaction steps
        nextAction:
          type: object
          description: >-
            The next step in one vocabulary (`type` + `actor`: `wait`,
            `buyer_security_code`, `approval`, `payment_ready`, `closed`, …),
            always present for a purchase. For a transaction that buys nothing,
            only an approval or security-code step, absent when nobody needs to
            act. Links are derived at read time.
        purchase:
          type: object
          description: >-
            The purchase details and their source (`assertedBy`). UCP uses
            `merchant` throughout the purchase, including while checkout details
            are pending. Browser purchases use `agent` for the caller's
            statement. For a UCP purchase, a `merchant.nameSource` of `caller`
            identifies an optional display name supplied at create. The purchase
            is absent for a transaction that buys nothing.
          example:
            type: ucp_checkout
            assertedBy: merchant
            merchant:
              origin: https://shop.example
              name: Example Shop
              nameSource: caller
            total:
              amount: '19.99'
              currency: USD
            lineItems:
              - title: Mug
                itemId: item_123
                quantity: 1
                unitAmount: '19.99'
            revision: 1
        order:
          type: object
          nullable: true
          description: >-
            For a purchase: the merchant-confirmed order outcome (`confirmed`,
            `not_confirmed`, `unknown`). With `confirmed`, the merchant's
            confirmation from its completed answer, for the platform to show the
            user: `id`, `label` (the order number the user sees), `permalinkUrl`
            (the order on the merchant's site) and `links` (its refund,
            shipping, terms, privacy and contact pages, `{ type, url, title?
            }`), each null or empty when the merchant sent none. Null for a
            browser purchase, which has no order confirmation.
          example:
            outcome: confirmed
            id: gid://shopify/Order/1
            label: '#1008'
            permalinkUrl: https://shop.example/orders/1
            links:
              - type: refund_policy
                url: https://shop.example/policies/refund-policy
                title: Refund policy
        version:
          type: string
          description: >-
            For a purchase: changes whenever anything the caller acts on
            changes. Pass it back as `since` to wait for the next change, or as
            version when updating this purchase. A browser version includes its
            accepted revision and payment attempt.
        approvals:
          type: object
          description: >-
            Approval obligations and linked successor attempts; inspect an
            approval for current authority
        id:
          type: string
          description: Transaction ID
          example: 123e4567-e89b-12d3-a456-426614174000
        tenantId:
          type: string
          description: Organization ID
          example: 123e4567-e89b-12d3-a456-426614174000
        serviceName:
          type: string
          description: Service identifier
          example: openai
        actionName:
          type: string
          description: Action being performed
          example: completion
        resourceName:
          type: string
          description: Resource being accessed
          example: gpt-4
        serviceId:
          type: string
          nullable: true
          description: Service entity ID (foreign key reference)
          example: 123e4567-e89b-12d3-a456-426614174000
        status:
          enum:
            - pending
            - preparing
            - waiting_approval
            - authorized
            - completed
            - denied
            - cancelled
            - needs_revision
          type: string
          description: Transaction status
          example: authorized
        requiresPayment:
          type: boolean
          description: Whether the transaction requires payment
          example: true
        qualifiers:
          type: object
          description: Additional qualifiers for the transaction
          example:
            model: gpt-4
            tokens: 1000
        metadata:
          type: object
          description: Additional metadata for the transaction
        createdAt:
          format: date-time
          type: string
          description: Creation timestamp
          example: '2024-01-01T00:00:00.000Z'
        updatedAt:
          format: date-time
          type: string
          description: Last update timestamp
          example: '2024-01-01T00:00:00.000Z'
        authorizedAt:
          format: date-time
          type: string
          description: Authorization timestamp
          example: '2024-01-01T00:00:00.000Z'
        completedAt:
          format: date-time
          type: string
          description: Completion timestamp
          example: '2024-01-01T00:00:00.000Z'
        outcome:
          enum:
            - success
            - error
          type: string
          description: Transaction outcome (set when completed)
          example: success
        currentPaymentTransactionId:
          type: string
          nullable: true
          description: Current payment transaction ID if transaction requires payment
          example: 123e4567-e89b-12d3-a456-426614174000
        payment:
          description: Payment transaction details when transaction requires payment
          allOf:
            - $ref: '#/components/schemas/PaymentTransactionResponseDto'
        trace:
          description: Trace information for workflow grouping
          allOf:
            - $ref: '#/components/schemas/TraceResponseDto'
        agentId:
          type: string
          nullable: true
          description: Agent ID if transaction is associated with an agent
          example: 123e4567-e89b-12d3-a456-426614174000
        agent:
          description: Agent information if transaction is associated with an agent
          allOf:
            - $ref: '#/components/schemas/AgentResponseDto'
      required:
        - id
        - tenantId
        - serviceName
        - actionName
        - resourceName
        - status
        - requiresPayment
        - createdAt
        - updatedAt
    PaymentTransactionResponseDto:
      type: object
      properties:
        id:
          type: string
          description: Payment transaction ID
          example: 123e4567-e89b-12d3-a456-426614174000
        transactionId:
          type: string
          description: Transaction ID this payment belongs to
          example: 123e4567-e89b-12d3-a456-426614174000
        fiatAmount:
          type: string
          description: The payment amount in USD, as a decimal string.
        status:
          enum:
            - pending
            - preparing
            - authorized
            - settling
            - completed
            - failed
            - cancelled
          type: string
          description: Payment status
          example: authorized
        fundingSource:
          type: string
          description: '`external_card`: the user''s saved card pays.'
          enum:
            - external_card
        paymentCardId:
          type: string
          nullable: true
          description: The card paying a card-funded payment
          format: uuid
        credentialRoute:
          type: string
          description: >-
            `real_card_number`: the relay puts the real card into the merchant's
            payment request.
          enum:
            - real_card_number
          nullable: true
        placeholder:
          description: >-
            An authorized card payment's placeholder card, while it can still be
            relayed. Submit it in the merchant's card form; the relay swaps it
            for the real credential once.
          allOf:
            - $ref: '#/components/schemas/CardPlaceholderDto'
        billing:
          description: >-
            The card's billing country and postal code, for the merchant's
            billing fields. Present only beside `placeholder`; null when the
            card was saved without them or they cannot be read right now. There
            is no street address or name on card: fill only fields these cover,
            and never invent the rest.
          nullable: true
          allOf:
            - $ref: '#/components/schemas/CardBillingDto'
        reason:
          type: string
          nullable: true
          description: >-
            Why the payment failed, when it is a public code: `sapiom_error` (a
            fault on Sapiom's side; report the transaction's requestId). Absent
            otherwise; a transaction's checkout `nextAction` says why it ended.
          enum:
            - sapiom_error
          example: sapiom_error
        createdAt:
          format: date-time
          type: string
          description: Creation timestamp
          example: '2024-01-01T00:00:00.000Z'
        updatedAt:
          format: date-time
          type: string
          description: Last update timestamp
          example: '2024-01-01T00:00:00.000Z'
        authorizedAt:
          format: date-time
          type: string
          nullable: true
          description: Authorization timestamp
          example: '2024-01-01T00:00:00.000Z'
      required:
        - id
        - transactionId
        - fiatAmount
        - status
        - createdAt
        - updatedAt
    TraceResponseDto:
      type: object
      properties:
        id:
          type: string
          description: Trace ID
          example: 123e4567-e89b-12d3-a456-426614174000
        externalId:
          type: string
          nullable: true
          description: Optional user-supplied external ID for trace correlation
          example: checkout-session-abc123
      required:
        - id
    AgentResponseDto:
      type: object
      properties:
        id:
          type: string
        tenantId:
          type: string
        label:
          type: string
        name:
          type: string
        description:
          type: string
          nullable: true
        status:
          type: string
        createdAt:
          format: date-time
          type: string
        updatedAt:
          format: date-time
          type: string
      required:
        - id
        - tenantId
        - label
        - name
        - status
        - createdAt
        - updatedAt
    CardPlaceholderDto:
      type: object
      properties:
        number:
          type: string
          description: Card number shaped like the real card's brand; not a real card
          example: '4000123412341234'
        expMonth:
          type: number
          example: 7
        expYear:
          type: number
          example: 2029
        cvc:
          type: string
          example: '123'
        brand:
          type: string
          example: visa
        expiresAt:
          type: string
          description: After this the placeholder no longer relays
          example: '2026-10-13T13:00:00.000Z'
        injectionRef:
          type: string
          description: The armed injection the relay looks the placeholder up by
        transactionId:
          type: string
          description: The transaction the placeholder is relayed through
      required:
        - number
        - expMonth
        - expYear
        - cvc
        - brand
        - expiresAt
        - injectionRef
        - transactionId
    CardBillingDto:
      type: object
      properties:
        country:
          type: string
          description: ISO 3166-1 alpha-2
          example: US
        postalCode:
          type: string
          description: >-
            ZIP or postal code; absent only where the country has none in common
            use
          example: '94105'
      required:
        - country
  securitySchemes:
    api-key:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your platform key for user management, or a user key for everything
        else.

````

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