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

# Cart Purchase Cancel

> Stop a purchase that has not bought anything yet: no further attempt is made, the purchase is not finished by hand, and the order settles as `cancelled`. Allowed while the order is `pending` / `processing` and no attempt is running (`purchase.state` is `needs_action` or `pending`). An order that bought anything, already settled as `failed`, or has an attempt running answers `409`; cancelling an already cancelled order returns it unchanged.



## OpenAPI

````yaml /v1/api-reference/openapi.documented.json post /cart/purchase/cancel
openapi: 3.1.0
info:
  title: Henry Labs API
  version: 1.18.0
  description: Playground for Henry Labs API endpoints
  contact:
    name: Henry Labs API Support
    email: support@henrylabs.ai
servers:
  - url: https://api.henrylabs.ai/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Product
    description: Product search, details, and data enrichment
  - name: Cart
    description: Universal user shopping cart management
  - name: Orders
    description: Order management post purchase
  - name: Merchants
    description: Merchant information and status
  - name: Card
    description: Card tokenization and management
paths:
  /cart/purchase/cancel:
    post:
      tags:
        - Cart
      summary: Cart Purchase Cancel
      description: >-
        Stop a purchase that has not bought anything yet: no further attempt is
        made, the purchase is not finished by hand, and the order settles as
        `cancelled`. Allowed while the order is `pending` / `processing` and no
        attempt is running (`purchase.state` is `needs_action` or `pending`). An
        order that bought anything, already settled as `failed`, or has an
        attempt running answers `409`; cancelling an already cancelled order
        returns it unchanged.
      operationId: cartPurchaseCancel
      requestBody:
        content:
          application/json:
            example:
              refId: ckp-ref_3fa85f64-5717-4562-b3fc
              reason: The buyer chose to complete the purchase themselves
            schema:
              $ref: '#/components/schemas/cartPurchaseCancelInput'
      responses:
        '200':
          description: The order, now `cancelled`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/cartPurchaseStatusResponse'
        '400':
          description: Bad request - Invalid parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  status:
                    type: string
                  message:
                    type: string
                required:
                  - success
                  - status
                  - message
                additionalProperties: false
        '401':
          description: Unauthorized - Invalid API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  status:
                    type: string
                  message:
                    type: string
                required:
                  - success
                  - status
                  - message
                additionalProperties: false
        '404':
          description: Order not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  status:
                    type: string
                  message:
                    type: string
                required:
                  - success
                  - status
                  - message
                additionalProperties: false
        '409':
          description: >-
            The purchase cannot be cancelled: something was bought, it already
            ended as `failed`, or an attempt is running
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  status:
                    type: string
                  message:
                    type: string
                required:
                  - success
                  - status
                  - message
                additionalProperties: false
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import HenrySDK from '@henrylabs/sdk';

            const client = new HenrySDK({
              apiKey: process.env['HENRY_SDK_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.cart.checkout.cancelPurchase({
              refId: 'ckp-ref_3fa85f64-5717-4562-b3fc',
              reason: 'The buyer chose to complete the purchase themselves',
            });

            console.log(response.details);
components:
  schemas:
    cartPurchaseCancelInput:
      type: object
      properties:
        refId:
          type: string
          pattern: ^[a-zA-Z]{3}-ref_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[0-9a-f]{4}$
          description: The order's reference ID, as returned by Cart Purchase
          example: ckp-ref_3fa85f64-5717-4562-b3fc
        reason:
          description: >-
            Why the purchase is being cancelled. Returned as `result.reason` on
            the cancelled order and on the `order.purchase.cancelled` webhook.
          example: The buyer chose to complete the purchase themselves
          type: string
          maxLength: 500
      required:
        - refId
    cartPurchaseStatusResponse:
      type: object
      properties:
        refId:
          type: string
          pattern: ^[a-zA-Z]{3}-ref_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[0-9a-f]{4}$
        status:
          type: string
          enum:
            - pending
            - processing
            - complete
            - partially_complete
            - failed
            - cancelled
          description: >-
            `pending` / `processing` while the purchase runs. It then settles:
            `complete` (every item bought), `partially_complete` (some items
            bought — see `products[].status`), `failed` (nothing bought — see
            `error`), or `cancelled` (stopped by Cart Purchase Cancel before
            anything was bought). After a failed attempt an order can stay
            `processing` for up to an hour before it settles; `purchase` says
            what is happening meanwhile.
        purchase:
          type: object
          properties:
            state:
              type: string
              enum:
                - pending
                - attempting
                - retrying
                - needs_action
                - settled
              description: >-
                `pending` — no attempt yet. `attempting` — the first attempt is
                running. `retrying` — an attempt failed (see `error`) and
                another is running. `needs_action` — an attempt failed, nothing
                is retrying it, and the purchase can still be finished by hand
                within the hour or cancelled. `settled` — the outcome is final;
                read `status`.
            attempt:
              type: integer
              minimum: 0
              maximum: 9007199254740991
              description: >-
                How many purchase attempts have been made, the running one
                included. `0` before the first.
              example: 1
            error:
              description: >-
                Why the most recent attempt failed, as the same client-safe `{
                code, message }` the order's `error` uses. Present while
                `retrying`, while `needs_action`, and once settled as `failed`.
              type: object
              properties:
                code:
                  type: string
                  enum:
                    - CARD_DECLINED
                    - ITEM_UNAVAILABLE
                    - SHIPPING_UNAVAILABLE
                    - MINIMUM_ORDER_NOT_MET
                    - PURCHASE_FAILED
                    - MULTIPLE_ERRORS
                  description: >-
                    `CARD_DECLINED` — the merchant did not accept the card; a
                    different card may work. `ITEM_UNAVAILABLE` — an item is out
                    of stock or no longer sold. `SHIPPING_UNAVAILABLE` — the
                    merchant does not ship to the address.
                    `MINIMUM_ORDER_NOT_MET` — the order is under the merchant's
                    minimum. `PURCHASE_FAILED` — the purchase could not be
                    completed for a reason on Henry's side; contact support with
                    the reference ID. `MULTIPLE_ERRORS` — the order's merchants
                    failed for different reasons.
                  example: CARD_DECLINED
                message:
                  type: string
                  description: >-
                    A short description of the failure, safe to show the buyer.
                    `PURCHASE_FAILED` and `MULTIPLE_ERRORS` carry the order's
                    reference ID for support.
                  example: The merchant did not accept the card
              required:
                - code
                - message
              additionalProperties: false
          required:
            - state
            - attempt
          additionalProperties: false
          description: >-
            What is happening with the purchase while `status` is `pending` /
            `processing`: which attempt is running, whether it is a retry,
            whether the purchase needs action, and why the last attempt failed.
        products:
          type: array
          items:
            type: object
            properties:
              status:
                type: string
                enum:
                  - pending
                  - processing
                  - complete
                  - failed
                description: >-
                  The item's own outcome: `complete` once bought, `failed` once
                  it could not be. It stays `processing` while it is being
                  bought and, after a failed attempt, for up to an hour before
                  it settles.
              purchase:
                type: object
                properties:
                  state:
                    type: string
                    enum:
                      - pending
                      - attempting
                      - retrying
                      - needs_action
                      - settled
                    description: >-
                      `pending` — no attempt yet. `attempting` — the first
                      attempt is running. `retrying` — an attempt failed (see
                      `error`) and another is running. `needs_action` — an
                      attempt failed, nothing is retrying it, and the purchase
                      can still be finished by hand within the hour or
                      cancelled. `settled` — the outcome is final; read
                      `status`.
                  attempt:
                    type: integer
                    minimum: 0
                    maximum: 9007199254740991
                    description: >-
                      How many purchase attempts have been made, the running one
                      included. `0` before the first.
                    example: 1
                  error:
                    description: >-
                      Why the most recent attempt failed, as the same
                      client-safe `{ code, message }` the order's `error` uses.
                      Present while `retrying`, while `needs_action`, and once
                      settled as `failed`.
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - CARD_DECLINED
                          - ITEM_UNAVAILABLE
                          - SHIPPING_UNAVAILABLE
                          - MINIMUM_ORDER_NOT_MET
                          - PURCHASE_FAILED
                          - MULTIPLE_ERRORS
                        description: >-
                          `CARD_DECLINED` — the merchant did not accept the
                          card; a different card may work. `ITEM_UNAVAILABLE` —
                          an item is out of stock or no longer sold.
                          `SHIPPING_UNAVAILABLE` — the merchant does not ship to
                          the address. `MINIMUM_ORDER_NOT_MET` — the order is
                          under the merchant's minimum. `PURCHASE_FAILED` — the
                          purchase could not be completed for a reason on
                          Henry's side; contact support with the reference ID.
                          `MULTIPLE_ERRORS` — the order's merchants failed for
                          different reasons.
                        example: CARD_DECLINED
                      message:
                        type: string
                        description: >-
                          A short description of the failure, safe to show the
                          buyer. `PURCHASE_FAILED` and `MULTIPLE_ERRORS` carry
                          the order's reference ID for support.
                        example: The merchant did not accept the card
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - state
                  - attempt
                additionalProperties: false
                description: >-
                  What is happening with this item's purchase: the attempt it is
                  on, whether it is being retried or needs action, and why its
                  last attempt failed.
              link:
                type: string
                format: uri
              affiliateProductLink:
                type: string
                format: uri
              quantity:
                type: integer
                exclusiveMinimum: 0
                maximum: 9007199254740991
              merchant:
                type: string
              host:
                type: string
              selectedOptions:
                type: array
                items:
                  type: string
              selectedShipping:
                type: object
                properties:
                  id:
                    type: string
                  value:
                    type: string
                additionalProperties: false
            required:
              - status
              - purchase
              - link
              - quantity
              - merchant
              - host
            additionalProperties: false
        details:
          type: object
          properties:
            hasAccount:
              type: boolean
            name:
              type: object
              properties:
                firstName:
                  type: string
                middleName:
                  type: string
                lastName:
                  type: string
              required:
                - firstName
                - lastName
              additionalProperties: false
            email:
              type: string
            phone:
              type: object
              properties:
                countryCode:
                  type: string
                nationalNumber:
                  type: string
                e164:
                  type: string
                country:
                  type: string
              required:
                - countryCode
                - nationalNumber
                - e164
              additionalProperties: false
            shippingAddress:
              type: object
              properties:
                name:
                  type: object
                  properties:
                    firstName:
                      type: string
                    middleName:
                      type: string
                    lastName:
                      type: string
                  required:
                    - firstName
                    - lastName
                  additionalProperties: false
                email:
                  type: string
                  format: email
                  pattern: >-
                    ^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$
                phone:
                  type: object
                  properties:
                    countryCode:
                      type: string
                    nationalNumber:
                      type: string
                    e164:
                      type: string
                    country:
                      type: string
                  required:
                    - countryCode
                    - nationalNumber
                    - e164
                  additionalProperties: false
                line1:
                  type: string
                line2:
                  type: string
                city:
                  type: string
                province:
                  type: string
                postalCode:
                  type: string
                countryCode:
                  type: string
              required:
                - line1
                - city
                - province
                - postalCode
                - countryCode
              additionalProperties: false
            card:
              type: object
              properties:
                nameOnCard:
                  type: object
                  properties:
                    firstName:
                      type: string
                    middleName:
                      type: string
                    lastName:
                      type: string
                  required:
                    - firstName
                    - lastName
                  additionalProperties: false
                details:
                  type: object
                  properties: {}
                  additionalProperties: false
                billingAddress:
                  type: object
                  properties:
                    name:
                      type: object
                      properties:
                        firstName:
                          type: string
                        middleName:
                          type: string
                        lastName:
                          type: string
                      required:
                        - firstName
                        - lastName
                      additionalProperties: false
                    email:
                      type: string
                      format: email
                      pattern: >-
                        ^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$
                    phone:
                      type: object
                      properties:
                        countryCode:
                          type: string
                        nationalNumber:
                          type: string
                        e164:
                          type: string
                        country:
                          type: string
                      required:
                        - countryCode
                        - nationalNumber
                        - e164
                      additionalProperties: false
                    line1:
                      type: string
                    line2:
                      type: string
                    city:
                      type: string
                    province:
                      type: string
                    postalCode:
                      type: string
                    countryCode:
                      type: string
                  required:
                    - line1
                    - city
                    - province
                    - postalCode
                    - countryCode
                  additionalProperties: false
              required:
                - nameOnCard
                - details
              additionalProperties: false
            settings:
              type: object
              properties:
                collectEmail:
                  type: boolean
                collectAddress:
                  type: boolean
                collectPhone:
                  type: boolean
              additionalProperties: false
          required:
            - hasAccount
            - name
            - card
          additionalProperties: false
        result:
          type: object
          properties:
            items:
              type: array
              items:
                type: object
                properties:
                  productLink:
                    type: string
                    format: uri
                  confirmationNumber:
                    type: string
                  quantity:
                    anyOf:
                      - type: integer
                        exclusiveMinimum: 0
                        maximum: 9007199254740991
                      - type: 'null'
                  shipping:
                    type: object
                    properties:
                      id:
                        type: string
                      name:
                        type: string
                      cost:
                        type: object
                        properties:
                          value:
                            type: number
                          currency:
                            type: string
                            enum:
                              - USD
                              - EUR
                              - AUD
                              - SGD
                              - TWD
                              - GBP
                              - CAD
                              - MXN
                              - NPR
                              - INR
                              - DKK
                              - NOK
                              - SEK
                              - CHF
                              - PLN
                              - CZK
                              - JPY
                              - NZD
                              - HKD
                              - AED
                              - LBP
                              - SAR
                        required:
                          - value
                          - currency
                        additionalProperties: false
                      timeEstimate:
                        type: string
                      minDate:
                        type: string
                      maxDate:
                        type: string
                    required:
                      - id
                      - name
                      - cost
                    additionalProperties: false
                  costs:
                    type: object
                    properties:
                      subtotal:
                        type: object
                        properties:
                          value:
                            type: number
                          currency:
                            type: string
                            enum:
                              - USD
                              - EUR
                              - AUD
                              - SGD
                              - TWD
                              - GBP
                              - CAD
                              - MXN
                              - NPR
                              - INR
                              - DKK
                              - NOK
                              - SEK
                              - CHF
                              - PLN
                              - CZK
                              - JPY
                              - NZD
                              - HKD
                              - AED
                              - LBP
                              - SAR
                        required:
                          - value
                          - currency
                        additionalProperties: false
                      tax:
                        type: object
                        properties:
                          value:
                            type: number
                          currency:
                            type: string
                            enum:
                              - USD
                              - EUR
                              - AUD
                              - SGD
                              - TWD
                              - GBP
                              - CAD
                              - MXN
                              - NPR
                              - INR
                              - DKK
                              - NOK
                              - SEK
                              - CHF
                              - PLN
                              - CZK
                              - JPY
                              - NZD
                              - HKD
                              - AED
                              - LBP
                              - SAR
                        required:
                          - value
                          - currency
                        additionalProperties: false
                      shipping:
                        type: object
                        properties:
                          value:
                            type: number
                          currency:
                            type: string
                            enum:
                              - USD
                              - EUR
                              - AUD
                              - SGD
                              - TWD
                              - GBP
                              - CAD
                              - MXN
                              - NPR
                              - INR
                              - DKK
                              - NOK
                              - SEK
                              - CHF
                              - PLN
                              - CZK
                              - JPY
                              - NZD
                              - HKD
                              - AED
                              - LBP
                              - SAR
                        required:
                          - value
                          - currency
                        additionalProperties: false
                      discount:
                        type: object
                        properties:
                          value:
                            type: number
                          currency:
                            type: string
                            enum:
                              - USD
                              - EUR
                              - AUD
                              - SGD
                              - TWD
                              - GBP
                              - CAD
                              - MXN
                              - NPR
                              - INR
                              - DKK
                              - NOK
                              - SEK
                              - CHF
                              - PLN
                              - CZK
                              - JPY
                              - NZD
                              - HKD
                              - AED
                              - LBP
                              - SAR
                        required:
                          - value
                          - currency
                        additionalProperties: false
                      total:
                        type: object
                        properties:
                          value:
                            type: number
                          currency:
                            type: string
                            enum:
                              - USD
                              - EUR
                              - AUD
                              - SGD
                              - TWD
                              - GBP
                              - CAD
                              - MXN
                              - NPR
                              - INR
                              - DKK
                              - NOK
                              - SEK
                              - CHF
                              - PLN
                              - CZK
                              - JPY
                              - NZD
                              - HKD
                              - AED
                              - LBP
                              - SAR
                        required:
                          - value
                          - currency
                        additionalProperties: false
                    required:
                      - total
                    additionalProperties: false
                  appliedCoupon:
                    type: object
                    properties:
                      code:
                        type: string
                      savedAmount:
                        type: object
                        properties:
                          value:
                            type: number
                          currency:
                            type: string
                            enum:
                              - USD
                              - EUR
                              - AUD
                              - SGD
                              - TWD
                              - GBP
                              - CAD
                              - MXN
                              - NPR
                              - INR
                              - DKK
                              - NOK
                              - SEK
                              - CHF
                              - PLN
                              - CZK
                              - JPY
                              - NZD
                              - HKD
                              - AED
                              - LBP
                              - SAR
                        required:
                          - value
                          - currency
                        additionalProperties: false
                    required:
                      - code
                    additionalProperties: false
                  metadata:
                    type: object
                    propertyNames:
                      type: string
                    additionalProperties: {}
                required:
                  - productLink
                  - confirmationNumber
                  - costs
                additionalProperties: false
            costs:
              type: object
              properties:
                subtotal:
                  type: object
                  properties:
                    value:
                      type: number
                    currency:
                      type: string
                      enum:
                        - USD
                        - EUR
                        - AUD
                        - SGD
                        - TWD
                        - GBP
                        - CAD
                        - MXN
                        - NPR
                        - INR
                        - DKK
                        - NOK
                        - SEK
                        - CHF
                        - PLN
                        - CZK
                        - JPY
                        - NZD
                        - HKD
                        - AED
                        - LBP
                        - SAR
                  required:
                    - value
                    - currency
                  additionalProperties: false
                serviceFee:
                  type: object
                  properties:
                    value:
                      type: number
                    currency:
                      type: string
                      enum:
                        - USD
                        - EUR
                        - AUD
                        - SGD
                        - TWD
                        - GBP
                        - CAD
                        - MXN
                        - NPR
                        - INR
                        - DKK
                        - NOK
                        - SEK
                        - CHF
                        - PLN
                        - CZK
                        - JPY
                        - NZD
                        - HKD
                        - AED
                        - LBP
                        - SAR
                  required:
                    - value
                    - currency
                  additionalProperties: false
                total:
                  type: object
                  properties:
                    value:
                      type: number
                    currency:
                      type: string
                      enum:
                        - USD
                        - EUR
                        - AUD
                        - SGD
                        - TWD
                        - GBP
                        - CAD
                        - MXN
                        - NPR
                        - INR
                        - DKK
                        - NOK
                        - SEK
                        - CHF
                        - PLN
                        - CZK
                        - JPY
                        - NZD
                        - HKD
                        - AED
                        - LBP
                        - SAR
                  required:
                    - value
                    - currency
                  additionalProperties: false
              required:
                - subtotal
                - serviceFee
                - total
              additionalProperties: false
          required:
            - items
            - costs
          additionalProperties: false
        error:
          description: >-
            Why items failed, once the order has settled as `failed` or
            `partially_complete`. Absent while the purchase runs and when every
            item was bought.
          type: object
          properties:
            code:
              type: string
              enum:
                - CARD_DECLINED
                - ITEM_UNAVAILABLE
                - SHIPPING_UNAVAILABLE
                - MINIMUM_ORDER_NOT_MET
                - PURCHASE_FAILED
                - MULTIPLE_ERRORS
              description: >-
                `CARD_DECLINED` — the merchant did not accept the card; a
                different card may work. `ITEM_UNAVAILABLE` — an item is out of
                stock or no longer sold. `SHIPPING_UNAVAILABLE` — the merchant
                does not ship to the address. `MINIMUM_ORDER_NOT_MET` — the
                order is under the merchant's minimum. `PURCHASE_FAILED` — the
                purchase could not be completed for a reason on Henry's side;
                contact support with the reference ID. `MULTIPLE_ERRORS` — the
                order's merchants failed for different reasons.
              example: CARD_DECLINED
            message:
              type: string
              description: >-
                A short description of the failure, safe to show the buyer.
                `PURCHASE_FAILED` and `MULTIPLE_ERRORS` carry the order's
                reference ID for support.
              example: The merchant did not accept the card
          required:
            - code
            - message
          additionalProperties: false
      required:
        - refId
        - status
        - purchase
        - products
        - details
      additionalProperties: false
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

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