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

# Create a transaction



## OpenAPI

````yaml post /transactions
openapi: 3.0.0
info:
  title: Customer API
  version: v1
servers:
  - url: https://sandbox-api.fedapay.com/v1
  - url: https://api.fedapay.com/v1
security: []
paths:
  /transactions:
    post:
      summary: Create a transaction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                description:
                  type: string
                  description: Description of the transaction.
                amount:
                  type: integer
                  description: Amount of the transaction.
                currency:
                  type: object
                  description: Currency information.
                  properties:
                    iso:
                      type: string
                      description: The ISO code of the currency (e.g., XOF).
                callback_url:
                  type: string
                  format: uri
                  description: URL to receive transaction updates.
                custom_metadata:
                  type: object
                  additionalProperties: true
                  description: Additional metadata related to the transaction.
                customer:
                  type: object
                  description: Customer associated with the transaction.
                  properties:
                    id:
                      type: integer
                      description: Customer ID if already exists
                    email:
                      type: string
                      format: email
                      description: Customer's email address.
                    firstname:
                      type: string
                      description: Customer's last name.
                    lastname:
                      type: string
                      description: Customer's last name.
                    phone_number:
                      type: object
                      description: Customer's phone number.
                      properties:
                        number:
                          type: integer
                          description: Phone number without national prefix.
                        country:
                          type: string
                          description: Country code.
              required:
                - description
                - amount
                - currency
      responses:
        '201':
          description: Transaction created successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                    description: Transaction ID.
                  reference:
                    type: string
                    description: Transaction reference.
                  amount:
                    type: integer
                    description: Transaction amount.
                  description:
                    type: string
                    description: Transaction description.
                  callback_url:
                    type: string
                    description: Transaction callback URL.
                  status:
                    type: string
                    description: >-
                      Transaction status (e.g., 'pending', 'approved',
                      'canceled').
                  created_at:
                    type: string
                    format: date-time
                    description: Date and time of transaction creation.
                  updated_at:
                    type: string
                    format: date-time
                    description: Date and time of last transaction update.
        '400':
          description: Invalid request body.
        '401':
          description: Unauthorized. Provide a valid secret key.
        '422':
          description: Validation error.
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          label: NodeJs
          source: |-
            const { FedaPay, Transaction } = require('fedapay');
            FedaPay.setApiKey('YOUR_SECRET_API_KEY');
            FedaPay.setEnvironment('sandbox');
            const transaction = await Transaction.create({
              description: 'Payment for order #1234',
              amount: 1000,
              currency: { iso: 'XOF' },
              callback_url: 'https://example.com/callback',
              mode: 'mtn_open',
              customer: { id: 1 }
            });
        - lang: PHP
          source: |-
            \FedaPay\Fedapay::setApiKey('YOUR_API_KEY');
            \FedaPay\Fedapay::setEnvironment('sandbox');
            $transaction = \FedaPay\Transaction::create([
              'description' => 'Payment for order #1234',
              'amount' => 1000,
              'currency' => ['iso' => 'XOF'],
              'callback_url' => 'https://example.com/callback',
              'mode' => 'mtn_open',
              'customer' => ['id' => 1]
            ]);
        - lang: Ruby
          source: |-
            require 'fedapay'

            FedaPay.api_key = 'YOUR_SECRET_API_KEY'
            FedaPay.environment = 'sandbox'

            transaction = FedaPay::Transaction.create(
              amount: 1000,
              currency: { iso: 'XOF' },
              customer: { id: 1 },
              description: 'Payment for order #1234',
              callback_url: 'https://example.com/callback',
              mode: 'mtn_open'
            )

            puts "Transaction successfully created : #{transaction.inspect}"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````