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

# Initialiser une Transaction

> Initier une nouvelle transaction de paiement

# Initialiser une Transaction

Initialisez une nouvelle transaction de paiement.

## Endpoint

```bash theme={null}
POST /api/v1/transaction/init
```

## Headers

| Nom           | Type   | Requis | Description           |
| ------------- | ------ | ------ | --------------------- |
| Authorization | string | Oui    | Bearer YOUR\_API\_KEY |
| Content-Type  | string | Oui    | application/json      |

## Corps de la Requête

```json theme={null}
{
  "externalTransactionId": string,    // Votre référence unique
  "serviceCode": string,              // Code du service
  "amount": number,                   // Montant (200-1,000,000 FCFA)
  "number": string,                   // Numéro de téléphone
  "callBackURL": string,              // URL de notification
  "successUrl": string,               // URL de redirection succès
  "failureUrl": string               // URL de redirection échec
}
```

### Paramètres

| Paramètre             | Type   | Requis | Description                                |
| --------------------- | ------ | ------ | ------------------------------------------ |
| externalTransactionId | string | Oui    | Votre identifiant unique de transaction    |
| serviceCode           | string | Oui    | Code du service de paiement                |
| amount                | number | Oui    | Montant en FCFA (min: 200, max: 1,000,000) |
| number                | string | Oui    | Numéro de téléphone format: ^\[0-9]{9}\$   |
| callBackURL           | string | Oui    | URL pour les notifications webhook         |
| successUrl            | string | Oui    | URL de redirection après succès            |
| failureUrl            | string | Oui    | URL de redirection après échec             |

## Réponse

### Réponse Réussie

```json theme={null}
{
  "message": "Transaction initiated successfully",
  "success": true,
  "transaction": {
    "transactionId": "TID123456789",
    "serviceName": "Orange Money Senegal",
    "serviceCode": "OM_SN_CASHOUT",
    "ApiTransactionId": "OM789012345",
    "transactionType": "CASHOUT",
    "transactionAmount": 1000,
    "transactionFee": 20,
    "number": "771234567",
    "Status": "PENDING",
    "INITIATED_AT": "2024-03-20T10:30:00Z"
  }
}
```

### Réponse d'Erreur

```json theme={null}
{
  "message": ["Description de l'erreur"],
  "success": false
}
```

## Codes d'Erreur

| Code HTTP | Description                               |
| --------- | ----------------------------------------- |
| 400       | Paramètres invalides ou montant incorrect |
| 401       | Clé API invalide                          |
| 403       | API en maintenance                        |
| 409       | ID de transaction externe déjà utilisé    |

## Validations

1. **Montant**

   * Minimum: 200 FCFA
   * Maximum: 1,000,000 FCFA

2. **Numéro de Téléphone**
   * Format: 9 chiffres
   * Sans indicatif pays
   * Uniquement des caractères numériques

## Exemple de Requête

```bash theme={null}
curl -X POST https://api-m.dexchange.sn/api/v1/transaction/init \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "externalTransactionId": "INV-001",
    "serviceCode": "OM_SN_CASHOUT",
    "amount": 1000,
    "number": "771234567",
    "callBackURL": "https://your-domain.com/callback",
    "successUrl": "https://your-domain.com/success",
    "failureUrl": "https://your-domain.com/failure"
  }'
```

## Webhook de Notification

Lorsque le statut de la transaction change, un webhook est envoyé à l'URL spécifiée dans `callBackURL`:

```json theme={null}
{
  "id": "TID123456789",
  "externalTransactionId": "INV-001",
  "transactionType": "CASHOUT",
  "AMOUNT": 1000,
  "FEE": 20,
  "PHONE_NUMBER": "771234567",
  "STATUS": "SUCCESS",
  "CUSTOM_DATA": "{}",
  "COMPLETED_AT": "2024-03-20T10:35:00Z",
  "BALANCE": 50000,
  "PREVIOUS_BALANCE": 51020,
  "CURRENT_BALANCE": 50000
}
```


## OpenAPI

````yaml POST /api/v1/transaction/init
openapi: 3.0.1
info:
  title: DEXCHANGE-API
  description: >-
    Unifiez tous vos paiements mobiles à travers une seule API puissante.
    DEXCHANGE-API est une passerelle de paiement qui regroupe plusieurs wallets
    (Orange Money, Wave, Free Money, Wizall) sur une seule API, simplifiant
    l'intégration des paiements mobiles en Afrique de l'Ouest.
  version: 1.0.0
  contact:
    name: DEXCHANGE Support
    email: team@dexchange.sn
    url: https://docs-api.dexchange.sn
  license:
    name: MIT
servers:
  - url: https://api-m.dexchange.sn
    description: Production Server
security:
  - bearerAuth: []
tags:
  - name: Transactions
    description: Operations for managing payment transactions
  - name: Merchant
    description: Merchant-specific payment operations
  - name: Services
    description: Service and balance information
  - name: Billing
    description: Bill payment and prepaid top-up operations
paths:
  /api/v1/transaction/init:
    post:
      tags:
        - Transactions
      summary: Initialiser une transaction
      description: Initier une nouvelle transaction de paiement
      operationId: initTransaction
      requestBody:
        description: Détails de la transaction
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TransactionInitRequest'
        required: true
      responses:
        '201':
          description: Transaction initiée avec succès
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionInitResponse'
        '400':
          description: Paramètres invalides
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    TransactionInitRequest:
      type: object
      properties:
        externalTransactionId:
          type: string
          description: Votre identifiant unique de transaction
        serviceCode:
          type: string
          description: Code du service de paiement
        amount:
          type: number
          description: 'Montant en FCFA (min: 200, max: 1,000,000)'
          minimum: 200
          maximum: 1000000
        number:
          type: string
          description: Numéro de téléphone
          pattern: ^[0-9]{9}$
        callBackURL:
          type: string
          format: uri
          description: URL pour les notifications webhook
        successUrl:
          type: string
          format: uri
          description: URL de redirection après succès
        failureUrl:
          type: string
          format: uri
          description: URL de redirection après échec
      required:
        - externalTransactionId
        - serviceCode
        - amount
        - number
        - callBackURL
        - successUrl
        - failureUrl
    TransactionInitResponse:
      type: object
      properties:
        message:
          type: string
        transaction:
          $ref: '#/components/schemas/TransactionDetails'
      required:
        - message
        - transaction
    Error:
      type: object
      properties:
        message:
          type: array
          items:
            type: string
        success:
          type: boolean
      required:
        - message
        - success
    TransactionDetails:
      type: object
      properties:
        success:
          type: boolean
        transactionId:
          type: string
        externalTransactionId:
          type: string
        transactionType:
          type: string
        amount:
          type: number
        transactionFee:
          type: number
        number:
          type: string
        callBackURL:
          type: string
        successUrl:
          type: string
        failureUrl:
          type: string
        status:
          type: string
        cashout_url:
          type: string
        webhook:
          type: string
      required:
        - success
        - transactionId
        - externalTransactionId
        - transactionType
        - amount
        - transactionFee
        - number
        - callBackURL
        - successUrl
        - failureUrl
        - status
        - cashout_url
        - webhook
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Entrez votre clé API comme: Bearer <API_KEY>'

````