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

# 创建结账会话

> 创建结账会话，请求限定于密钥所属组织。

购买输入、幂等与付款状态说明见[结账会话指南](/zh/api-reference/checkout-sessions)。


## OpenAPI

````yaml api-reference/openapi.json POST /v1/checkout-sessions
openapi: 3.0.3
info:
  description: >-
    Organization-scoped commerce API for merchant backends: create and manage
    checkout sessions, and query commerce records.
  title: Anyway Merchant API
  contact: {}
  version: '1.0'
  x-source: anyway-backend-go
servers:
  - url: https://merchant-api-prod.anyway.sh
security: []
paths:
  /v1/checkout-sessions:
    post:
      tags:
        - checkout-sessions
      summary: Create a checkout session
      description: >-
        Unknown request fields, including nested fields, return 400. The request
        body must be a single JSON object of at most 64 KiB.
      parameters:
        - description: >-
            Unique creation request key: 1-255 ASCII characters in the range
            0x21-0x7E (no spaces or control characters)
          name: Idempotency-Key
          in: header
          required: true
          schema:
            type: string
            minLength: 1
            maxLength: 255
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/checkoutsession.CreateRequest'
        description: Purchase and checkout configuration
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/response.ApiResponse-merchantapi_CheckoutSessionResponse
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
        '503':
          description: Service Unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/response.ApiResponse-any'
      security:
        - APIKeyAuth: []
components:
  schemas:
    checkoutsession.CreateRequest:
      type: object
      properties:
        cancelUrl:
          type: string
        customerEmail:
          type: string
          description: >-
            Optional customer email, at most 255 bytes. Mutually exclusive with
            customerId.
        customerId:
          type: string
          description: >-
            Optional existing customer ID. Omit both customer fields or provide
            only one.
        expiresIn:
          type: integer
          description: >-
            Lifetime in seconds: 1800-86400 for card checkout, 60-86400 for
            cryptocurrency checkout.
          default: 3600
        merchantReference:
          type: string
          description: >-
            Optional business correlation value, at most 255 bytes; not a
            uniqueness constraint.
        metadata:
          type: object
          additionalProperties:
            type: string
          description: >-
            At most 50 string pairs. Keys must contain 1-40 characters without [
            or ]; values may contain at most 500 characters.
        pricingData:
          $ref: '#/components/schemas/checkoutsession.PricingData'
        pricingId:
          type: string
        provider:
          type: string
          enum:
            - STRIPE
            - CRYPTO
          description: Omit for card checkout; use CRYPTO for cryptocurrency checkout.
        quantity:
          type: integer
          default: 1
          maximum: 999999
          minimum: 1
        successUrl:
          type: string
    response.ApiResponse-merchantapi_CheckoutSessionResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/merchantapi.CheckoutSessionResponse'
        error:
          $ref: '#/components/schemas/response.ErrorDetail'
        message:
          type: string
        success:
          type: boolean
    response.ApiResponse-any:
      type: object
      properties:
        data: {}
        error:
          $ref: '#/components/schemas/response.ErrorDetail'
        message:
          type: string
        success:
          type: boolean
    checkoutsession.PricingData:
      type: object
      properties:
        amount:
          type: integer
        billingInterval:
          $ref: '#/components/schemas/product.BillingInterval'
        billingIntervalCount:
          type: integer
        currency:
          type: string
        pricingName:
          type: string
        pricingType:
          $ref: '#/components/schemas/product.PricingType'
        productData:
          $ref: '#/components/schemas/product.ProductDetails'
        productId:
          type: string
    merchantapi.CheckoutSessionResponse:
      type: object
      properties:
        amount:
          type: integer
        createdAt:
          type: string
        currency:
          type: string
        customerEmail:
          type: string
        customerId:
          type: string
          nullable: true
        expiresAt:
          type: string
          nullable: true
        id:
          type: string
        lastError:
          $ref: '#/components/schemas/checkoutsession.ProviderFailure'
        merchantReference:
          type: string
          nullable: true
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
        orderId:
          type: string
          nullable: true
        orderStatus:
          type: string
        paymentLinkId:
          type: string
          nullable: true
        pricing:
          $ref: '#/components/schemas/checkoutsession.MerchantPricing'
        product:
          $ref: '#/components/schemas/checkoutsession.MerchantProduct'
        productName:
          type: string
        provider:
          type: string
        quantity:
          type: integer
        status:
          $ref: '#/components/schemas/checkoutsession.Status'
        url:
          type: string
          nullable: true
    response.ErrorDetail:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
    product.BillingInterval:
      type: string
      enum:
        - DAY
        - MONTH
        - YEAR
      x-enum-varnames:
        - BillingIntervalDay
        - BillingIntervalMonth
        - BillingIntervalYear
    product.PricingType:
      type: string
      enum:
        - SUBSCRIPTION
        - ONE_TIME
      x-enum-varnames:
        - PricingTypeSubscription
        - PricingTypeOneTime
    product.ProductDetails:
      type: object
      properties:
        description:
          type: string
        name:
          type: string
    checkoutsession.ProviderFailure:
      type: object
      properties:
        code:
          type: string
        occurredAt:
          type: string
        operation:
          type: string
        requestId:
          type: string
    checkoutsession.MerchantPricing:
      type: object
      properties:
        amount:
          description: Amount in the smallest currency unit.
          type: integer
        billingInterval:
          type: string
          enum:
            - DAY
            - MONTH
            - YEAR
            - null
          nullable: true
        billingIntervalCount:
          type: integer
        currency:
          type: string
        flexibleAmount:
          type: boolean
        maxAmount:
          type: integer
          nullable: true
        minAmount:
          type: integer
          nullable: true
        pricingId:
          type: string
          nullable: true
        pricingName:
          type: string
        pricingType:
          $ref: '#/components/schemas/product.PricingType'
    checkoutsession.MerchantProduct:
      type: object
      properties:
        description:
          type: string
        name:
          type: string
        productId:
          type: string
          nullable: true
    checkoutsession.Status:
      type: string
      enum:
        - CREATED
        - COMPLETE
        - EXPIRED
        - FAILED
      x-enum-comments:
        StatusComplete: Checkout is consumed; payment status belongs to Order.
        StatusFailed: >-
          Checkout failed or has no confirmed successful result; operation
          details are stored separately.
      x-enum-descriptions:
        - ''
        - Checkout is consumed; payment status belongs to Order.
        - ''
        - >-
          Checkout failed or has no confirmed successful result; operation
          details are stored separately.
      x-enum-varnames:
        - StatusCreated
        - StatusComplete
        - StatusExpired
        - StatusFailed
  securitySchemes:
    APIKeyAuth:
      description: 'Merchant API key (format: ak_BASE64)'
      type: apiKey
      name: X-API-Key
      in: header

````

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