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

# Create checkout session

> Create a hosted checkout link (unified payment SDK) for M-PESA, Airtel Money and bank transfer.

Walkthrough: [Checkout guide](https://api.tandapay.io/guides/collections/checkout.md).


## OpenAPI

````yaml POST /api/b2b/fiat/payment-sdk
openapi: 3.1.0
info:
  title: Tanda API
  version: 1.0.0
  description: >-
    Collect and send KES payments in Kenya through M-PESA, Airtel Money and bank
    transfer.
servers:
  - url: https://api.tandapay.io
    description: Sandbox and production (your keys decide which)
security:
  - bearerAuth: []
tags:
  - name: Authentication
  - name: Account
  - name: Checkout
  - name: Collections
  - name: Payouts
  - name: Beneficiaries
  - name: Transactions
  - name: Reference data
  - name: Webhooks
paths:
  /api/b2b/fiat/payment-sdk:
    post:
      tags:
        - Checkout
      summary: Create checkout session
      description: >-
        Creates a hosted checkout session (the unified payment SDK) and returns
        a `paymentSdkLink`. Redirect your customer to the link; they choose
        M-PESA, Airtel Money or bank transfer and pay on the Tanda-hosted page.


        The redirect back to your site is not confirmation of payment. Confirm
        the outcome with a webhook or [Get
        transaction](/api-reference/endpoint/get-transaction).
      operationId: create-checkout-session
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                amount:
                  type: integer
                  description: Amount to charge in KES.
                  example: 1500
                chargeCurrency:
                  type: string
                  description: ISO 4217 currency code. Tanda supports `KES`.
                  enum:
                    - KES
                  example: KES
                walletCurrency:
                  type: string
                  description: Wallet to credit. Use `KES`.
                  enum:
                    - KES
                  example: KES
                externalReference:
                  type: string
                  description: >-
                    Your unique ID for this transaction. Must be unique per
                    attempt; reuse returns `409 DUPLICATE_EXTERNAL_REFERENCE`.
                  example: order_10045
                method:
                  type: string
                  description: >-
                    Restricts checkout to one method. Omit to let the customer
                    choose.
                  enum:
                    - momo
                    - bank
                customerId:
                  type: string
                  description: >-
                    Your own ID for the customer. Returned on the transaction so
                    you can match it.
                  example: customer_123
                prefillData:
                  type: object
                  properties:
                    firstName:
                      type: string
                    lastName:
                      type: string
                    email:
                      type: string
                    accountName:
                      type: string
                    phoneNumber:
                      type: string
                      description: E.164 with the `+`, e.g. `+254712345678`.
                  description: >-
                    Customer details to prefill. The customer can't edit
                    prefilled values during payment.
                successRedirectUrl:
                  type: string
                  description: Where to send the customer after a successful payment.
                  format: uri
                failureRedirectUrl:
                  type: string
                  description: Where to send the customer after a failed payment.
                  format: uri
                cancelRedirectUrl:
                  type: string
                  description: Where to send the customer if they cancel.
                  format: uri
              required:
                - amount
                - chargeCurrency
                - walletCurrency
                - externalReference
            example:
              amount: 1500
              chargeCurrency: KES
              walletCurrency: KES
              externalReference: order_10045
              customerId: customer_123
              prefillData:
                firstName: Brian
                lastName: Otieno
                email: brian@example.com
                phoneNumber: '+254712345678'
              successRedirectUrl: https://merchant.co.ke/checkout/success
              failureRedirectUrl: https://merchant.co.ke/checkout/failed
              cancelRedirectUrl: https://merchant.co.ke/checkout/cancelled
      responses:
        '200':
          description: Session created.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    type: object
                    properties:
                      transactionId:
                        type: string
                        description: >-
                          Tanda transaction ID for this payment. Use it with Get
                          transaction to confirm the outcome.
                      paymentSdkLink:
                        type: string
                        description: >-
                          Hosted checkout URL. Redirect the customer here; don't
                          build this URL yourself.
              example:
                success: true
                message: Transaction created successfully
                data:
                  transactionId: aB3dE5fG7hJ9kL1mN2pQ
                  paymentSdkLink: >-
                    https://gateway.tandapay.io/sdk/transaction/aB3dE5fG7hJ9kL1mN2pQ
        '401':
          description: Missing, invalid or expired bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                message: Unauthorized
        '409':
          description: '`externalReference` already used.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                success: false
                message: Duplicate external reference
                errorCode: DUPLICATE_EXTERNAL_REFERENCE
components:
  schemas:
    Error:
      type: object
      properties:
        success:
          type: boolean
          example: false
        message:
          type: string
          description: Human-readable; may change.
        errorCode:
          type: string
          description: Stable code to branch on.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Token from Generate bearer token.

````

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