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

# Create a checkout session

> Creates a PrimePay payment page for one order. Redirect the customer to `url`; it can be paid for 30 minutes.

Guide: [hosted checkout](/api-reference/checkout-overview) and [checkout errors](/api-reference/checkout-overview#checkout-errors).




## OpenAPI

````yaml /api-reference/openapi.yaml post /v1/checkout/sessions
openapi: 3.1.0
info:
  title: PrimePay API
  version: '1.0'
  description: >-
    Collect mobile money payments, send transfers and make payouts with the
    PrimePay API.
servers:
  - url: https://api.primepay.mw
    description: Live API (live keys, `sk_live_…`)
  - url: https://sandbox-api.primepay.mw
    description: Sandbox API (test keys, `sk_test_…`)
security:
  - bearerAuth: []
tags:
  - name: Operators
  - name: Payments
  - name: Refunds
  - name: Transfers
  - name: Payouts
  - name: Payment links
  - name: Checkout sessions
paths:
  /v1/checkout/sessions:
    post:
      tags:
        - Checkout sessions
      summary: Create a checkout session
      description: >
        Creates a PrimePay payment page for one order. Redirect the customer to
        `url`; it can be paid for 30 minutes.


        Guide: [hosted checkout](/api-reference/checkout-overview) and [checkout
        errors](/api-reference/checkout-overview#checkout-errors).
      operationId: createCheckoutSession
      parameters:
        - $ref: '#/components/parameters/CheckoutIdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CheckoutSessionRequest'
            example:
              amount: 42500
              currency: MWK
              reference: ORDER-5531
              description: 2 x School shoes
              return_url: https://shop.example.com/orders/5531/done
              cancel_url: https://shop.example.com/cart
              customer:
                first_name: Chikondi
                last_name: Banda
                email: customer@example.com
                phone: '0991234567'
              line_items:
                - name: School shoes
                  quantity: 2
                  unit_amount: 20000
                - name: Delivery
                  quantity: 1
                  unit_amount: 2500
              metadata:
                cart: '88412'
      responses:
        '201':
          description: The session. Redirect the customer to `url`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckoutSession'
              example:
                id: 3c0f6f4e-7a1b-4c59-9a3e-0d5b7f2c8e11
                object: checkout.session
                url: >-
                  https://checkout.primepay.mw/c/3c0f6f4e-7a1b-4c59-9a3e-0d5b7f2c8e11
                status: open
                livemode: true
                amount: 42500
                currency: MWK
                reference: ORDER-5531
                description: 2 x School shoes
                customer:
                  first_name: Chikondi
                  last_name: Banda
                  email: customer@example.com
                  phone: '+265991234567'
                line_items:
                  - name: School shoes
                    description: null
                    quantity: 2
                    unit_amount: 20000
                  - name: Delivery
                    description: null
                    quantity: 1
                    unit_amount: 2500
                metadata:
                  cart: '88412'
                sub_merchant_account_code: null
                return_url: https://shop.example.com/orders/5531/done
                cancel_url: https://shop.example.com/cart
                payment: null
                created_at: '2026-11-12T08:00:00Z'
                expires_at: '2026-11-12T08:30:00Z'
                completed_at: null
        '400':
          $ref: '#/components/responses/CheckoutError'
        '409':
          $ref: '#/components/responses/CheckoutError'
components:
  parameters:
    CheckoutIdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      schema:
        type: string
        minLength: 8
        maxLength: 255
        example: 9b2f4c6e8a1d4f3b9c7e5a2d1f0b3c4e
      description: >
        A new value for every new session (a UUID is ideal), 8 to 255
        characters. If your request times out, send it again with the same key
        to get the first session back. `description` and `metadata` may differ
        on the retry.
  schemas:
    CheckoutSessionRequest:
      type: object
      required:
        - amount
        - reference
        - return_url
        - cancel_url
      properties:
        amount:
          type: number
          minimum: 1
          maximum: 10000000
          description: At most 2 decimal places.
        currency:
          type: string
          default: MWK
          description: >-
            `MWK` today. Other currencies are accepted once PrimePay takes
            payments in that country.
        reference:
          type: string
          maxLength: 100
          description: Your order or invoice number. One open or paid session per order.
        description:
          type: string
          maxLength: 255
          nullable: true
          description: Shown to the customer.
        return_url:
          type: string
          maxLength: 2048
          description: >-
            Where the customer goes after paying. A public `https://` address
            (sandbox also allows `http://localhost`). `session_id`, `reference`
            and `status` are added to it.
        cancel_url:
          type: string
          maxLength: 2048
          description: >-
            Where the customer goes if they go back without paying. Same rules
            as `return_url`.
        customer:
          $ref: '#/components/schemas/CheckoutCustomer'
        line_items:
          type: array
          maxItems: 50
          description: Shown on the page. They must add up to `amount`.
          items:
            $ref: '#/components/schemas/CheckoutLineItem'
        metadata:
          type: object
          additionalProperties: true
          nullable: true
          description: >-
            Your own values, up to 50 keys and 8 KB. Returned with the session
            and in webhooks.
        sub_merchant_account_code:
          type: string
          nullable: true
          description: >-
            Aggregator accounts only. The 8-digit account code of a linked,
            active sub-merchant to collect for. The agreed fee always applies.
    CheckoutSession:
      type: object
      properties:
        id:
          type: string
          format: uuid
        object:
          type: string
          example: checkout.session
        url:
          type: string
          nullable: true
          description: The payment page. `null` once the session can no longer be paid.
        status:
          type: string
          enum:
            - open
            - processing
            - complete
            - expired
            - cancelled
        livemode:
          type: boolean
        amount:
          type: number
        currency:
          type: string
          example: MWK
        reference:
          type: string
        description:
          type: string
          nullable: true
        customer:
          $ref: '#/components/schemas/CheckoutCustomer'
        line_items:
          type: array
          items:
            $ref: '#/components/schemas/CheckoutLineItem'
        metadata:
          type: object
          additionalProperties: true
          nullable: true
        sub_merchant_account_code:
          type: string
          nullable: true
        return_url:
          type: string
        cancel_url:
          type: string
        payment:
          $ref: '#/components/schemas/CheckoutPayment'
        created_at:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
        completed_at:
          type: string
          format: date-time
          nullable: true
    CheckoutCustomer:
      type: object
      properties:
        first_name:
          type: string
          maxLength: 100
          nullable: true
        last_name:
          type: string
          maxLength: 100
          nullable: true
        email:
          type: string
          format: email
          nullable: true
        phone:
          type: string
          nullable: true
          description: >-
            A Malawi mobile number, for example `0991234567` or `265991234567`.
            Returned as `+265991234567`.
    CheckoutLineItem:
      type: object
      required:
        - name
        - quantity
        - unit_amount
      properties:
        name:
          type: string
          maxLength: 200
        description:
          type: string
          maxLength: 500
          nullable: true
        quantity:
          type: integer
          minimum: 1
        unit_amount:
          type: number
          minimum: 0
    CheckoutPayment:
      type: object
      nullable: true
      description: The payment that completed the session. `null` until it is paid.
      properties:
        transaction_id:
          type: string
          format: uuid
        transaction_reference:
          type: string
          example: TXN-WRYF6S2W3DQW
        method:
          type: string
          example: wallet
        provider:
          type: string
          nullable: true
          example: airtel
        amount:
          type: number
          example: 42500
        fee:
          type: number
          example: 1275
        levy:
          type: number
          example: 0
        aggregator_fee:
          type: number
          example: 0
          description: 'Aggregator sessions: the aggregator''s share.'
        net:
          type: number
          example: 41225
          description: What reaches the account after fees.
        paid_at:
          type: string
          format: date-time
          nullable: true
    CheckoutError:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
              example: invalid_request_error
            code:
              type: string
              example: line_items_total_mismatch
            param:
              type: string
              nullable: true
              example: line_items
            message:
              type: string
              example: line_items add up to 40000.00 but amount is 42500.00.
  responses:
    CheckoutError:
      description: >-
        An error. `param` names the field at fault. Use `code` in your code;
        show `message` to people.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CheckoutError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Your API key: `sk_live_…` / `sk_test_…` (secret), `pk_live_…` /
        `pk_test_…` (publishable, read-only reference data) or `rk_live_…` /
        `rk_test_…` (payments only).

````

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