RevKeenDocs

Convert a cart session into a checkout session

Atomically materialise a pending checkout session from the cart snapshot, flip the cart to converted, and emit commerce.cart.converted + commerce.checkout.started through the outbox.

Idempotent on re-call (returns the existing checkout session). Concurrency-safe via a compare-and-swap lock on cart status.

Validation that runs inside the lock and rolls back on failure:

  • CART_SESSION_EMPTY — the cart has no line items.
  • CART_SESSION_DISCOUNT_PENDING — the cart has a discount code set; clear it first.
  • CART_SESSION_NOT_FOUND — no cart for this id under the calling merchant.
  • CART_SESSION_CLOSED — the cart is already abandoned or expired.

On rollback the cart returns to open and the customer can retry after fixing the cause.


Related endpoints

  • POST /cart-sessions — Create a cart session
  • GET /cart-sessions/{id} — Retrieve a cart session
  • POST /cart-sessions/{id}/line-items — Add a line item to a cart session
  • PATCH /cart-sessions/{id}/line-items/{lineId} — Update a line item's quantity
  • DELETE /cart-sessions/{id}/line-items/{lineId} — Remove a line item from a cart session
  • POST /cart-sessions/{id}/add-ons — Toggle an add-on on a cart session
  • POST /cart-sessions/{id}/discount-code — Set or clear a cart discount code

Common errors

  • 401 unauthenticated — missing, malformed, or revoked API key.
  • 404 resource_missing — the referenced resource does not exist or is not visible to your key.
  • 409 conflict — Idempotency-Key collision with a different body, or a concurrent state-transition conflict.

Idempotency

Pass an Idempotency-Key header (UUID v4 recommended) to make retries safe. Keys are valid for 24 hours; see the idempotency guide.

POST
/cart-sessions/{id}/convert
x-api-key<token>

Your RevKeen API key (powered by Unkey). Get it from Dashboard > Settings > API Keys. Use rk_sandbox_* for test mode and rk_live_* for production.

In: header

Path Parameters

id*string
Formatuuid

Response Body

application/json

application/json

application/json

application/json

curl -X POST "https://api.revkeen.com/v2/cart-sessions/550e8400-e29b-41d4-a716-446655440000/convert" \  -H "x-api-key: $REVKEEN_API_KEY"
{
  "data": {
    "cart_session": {
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      "object": "cart_session",
      "merchant_id": "500924a8-3f5e-4c00-beb8-2efcde988aea",
      "customer_id": "160c0c4b-9966-4dc1-a916-8407eb10d74e",
      "currency": "str",
      "mode": "payment",
      "status": "open",
      "line_items": [
        {
          "id": "cli_550e8400-e29b-41d4-a716-446655440000",
          "product_id": "0d012afa-f885-4e65-aeca-37e27701e2d1",
          "name": "string",
          "quantity": 0,
          "unit_price_minor": 0,
          "currency": "str",
          "recurring": {
            "interval": "month",
            "interval_count": 1
          },
          "metadata": {
            "property1": null,
            "property2": null
          }
        }
      ],
      "add_ons_offered": [
        "497f6eca-6276-4993-bfeb-53cbbbba6f08"
      ],
      "add_ons_selected": [
        "497f6eca-6276-4993-bfeb-53cbbbba6f08"
      ],
      "discount_code": "string",
      "subtotal_minor": 0,
      "total_minor": 0,
      "metadata": {
        "property1": null,
        "property2": null
      },
      "converted_to_checkout_session_id": "5d37f263-6519-4765-9535-e6aa5913d87c",
      "public_token": "string",
      "created_at": "2019-08-24T14:15:22Z",
      "updated_at": "2019-08-24T14:15:22Z",
      "expires_at": "2019-08-24T14:15:22Z"
    },
    "checkout_session": {
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      "object": "checkout_session",
      "merchant_id": "500924a8-3f5e-4c00-beb8-2efcde988aea",
      "customer_id": "160c0c4b-9966-4dc1-a916-8407eb10d74e",
      "session_token": "string",
      "status": "pending",
      "mode": "string",
      "amount_minor": 0,
      "currency": "string",
      "line_items": [
        {
          "id": "cli_550e8400-e29b-41d4-a716-446655440000",
          "product_id": "0d012afa-f885-4e65-aeca-37e27701e2d1",
          "name": "string",
          "quantity": 0,
          "unit_price_minor": 0,
          "currency": "str",
          "recurring": {
            "interval": "month",
            "interval_count": 1
          },
          "metadata": {
            "property1": null,
            "property2": null
          }
        }
      ],
      "metadata": {
        "property1": null,
        "property2": null
      },
      "expires_at": "2019-08-24T14:15:22Z",
      "created_at": "2019-08-24T14:15:22Z",
      "updated_at": "2019-08-24T14:15:22Z"
    }
  }
}
{
  "error": "string"
}
{
  "error": "Cart session not found",
  "code": "CART_SESSION_NOT_FOUND"
}
{
  "error": "Cart session not found",
  "code": "CART_SESSION_NOT_FOUND"
}