# Payout

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /api/payment-gateway/v2/direct-payment/merchant/payout:
    post:
      summary: Payout
      deprecated: false
      description: >+
        The ABA PayWay Funds Route API provides a seamless solution for
        splitting and distributing payments to third parties, sellers, service
        providers, or your ABA bank accounts.

      tags:
        - Payout
      parameters:
        - name: Content-Type
          in: header
          description: ''
          required: true
          example: application/json
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                merchant_id:
                  type: string
                  description: A unique merchant key which provided by ABA Bank.
                  maxLength: 255
                tran_id:
                  type: string
                  description: Unique transaction id
                  maxLength: 20
                beneficiaries:
                  type: string
                  description: >-
                    Payout instruction contains information of the beneficiary.


                    **PHP Sample Code**

                    ```php

                    function opensslEncryption($source, $publicKey)

                    {
                        //Assumes 1024 bit key and encrypts in chunks.
                        $maxlength = 117;
                        $output = '';
                        while ($source) {
                            $input = substr($source, 0, $maxlength);
                            $source = substr($source, $maxlength);
                            openssl_public_encrypt($input, $encrypted, $publicKey);
                            $output .= $encrypted;
                        }
                        return base64_encode($output);
                    }

                    // You can use mixed MID and Account in beneficiary, make
                    sure all of them has the same currency as transaction
                    currency.

                    $beneficiaries_info = json_encode([
                        ['account' => '200030000', 'amount' => 100],
                        ['account' => '012538302', 'amount' => 200],
                    ]);

                    $rsaPublicKey = 'USE YOUR RSA PUBLIC KEY PROVIDED BY ABA';


                    $beneficiaries = opensslEncryption($beneficiaries_info,
                    $rsaPublicKey);

                    ```
                  maxLength: 1000
                amount:
                  type: number
                  description: >-
                    Total payout amount (sum of all beneficiary amount).

                    - `KHR` : The amount must be greater than or equal to 100KHR

                    - `USD` : The amount must be greater than or equal to
                    0.01USD
                  format: float
                currency:
                  type: string
                  description: Transaction currency. Either `KHR` or `USD`.
                  title: ''
                  maxLength: 3
                  minLength: 3
                custom_fields:
                  type: string
                  description: >-
                    An additional field information as JSON string. This
                    information will be associate with the payment transaction.


                    **PHP Sample Code**


                    ```php

                    $custom_fields = json_encode([
                       "Invoice_ID" => "INV-1234",
                       "Province" => "Phnom Penh"
                    ]);

                    ```
                  maxLength: 255
                hash:
                  type: string
                  description: >-
                    Hash hmac sha512 encryption of concatenates values
                    `merchant_id`, `tran_id`, `beneficiaries`, `amount`,
                    `custom_fields` and `currency` with `public_key`.


                    **Here is an example code in PHP**


                    ```php

                    // public key provided by ABA Bank

                    $api_key = "API KEY PROVIDED BY ABA BANK";


                    // Prepare the data to be hashed

                    $b4Hash = $merchant_id . $tran_id . $beneficiaries . $amount
                    . $custom_fields . $currency;


                    // Generate the HMAC hash using SHA-512 

                    $hash = hash_hmac('sha512', $b4Hash, $api_key);

                    ```
                  title: ''
                  maxLength: 512
              required:
                - merchant_id
                - tran_id
                - beneficiaries
                - amount
                - currency
                - hash
              x-apidog-orders:
                - merchant_id
                - tran_id
                - beneficiaries
                - amount
                - currency
                - custom_fields
                - hash
            example:
              merchant_id: EC0001
              tran_id: A17259584044451
              beneficiaries: ElKjECTZK7ym...NX0Dt2dz...
              amount: 3.44
              currency: USD
              custom_fields: >-
                {"timestamp":"2024-08-23
                10:35:55.437","traceId":"63f9645fa3bd8678907ed4c038357385"}
              hash: 3c70c551a...d1092f6e22228a7686c51bc1162a...
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  transaction_id:
                    type: string
                    description: Unique transaction id pass from merchant
                  transaction_date:
                    type: string
                    description: The approved date and time of the transaction
                  external_reference:
                    type: string
                    description: >-
                      This is a unique reference booking entry number from core
                      banking system.
                  apv:
                    type: string
                    description: A random 6 digit number generated by payment gateway.
                  transaction_amount:
                    type: number
                    description: Total transaction amount
                    format: double
                  transaction_currency:
                    type: string
                    description: Transaction currencies
                  beneficiaries:
                    type: array
                    items:
                      type: object
                      properties:
                        payout_id:
                          type: string
                          description: A unique id generated by payment gateway.
                        name:
                          type: string
                          description: Beneficiary name
                        mid_acccount:
                          type: string
                          description: >-
                            Indentifier of the beneficiary, it can be either MID
                            represent a merchant or ABA account #.
                        amount:
                          type: number
                          description: Payout amount
                          format: double
                        currency:
                          type: string
                          description: Payout currency. Follow the transaction currency
                      description: Beneficiary object
                      x-apidog-orders:
                        - payout_id
                        - name
                        - mid_acccount
                        - amount
                        - currency
                    description: Array of beneficiary
                  status:
                    type: object
                    properties:
                      code:
                        type: string
                        title: ''
                        description: >-
                          - `0` : Success

                          - `4` : Duplicated Transaction ID

                          - `11` : Something went wrong. Try again or contact
                          the merchant for help

                          - `24` : Can not decrypt data

                          - `25` : Allow maximum 10 beneficiaries per requests

                          - `26` : Invalid Merchant Profile

                          - `36` : Payout account or amount is invalid

                          - `37` : Payout accounts are not in whitelist

                          - `44` : Purchase amount has reached transaction limit

                          - `48` : Something went wrong with requested
                          parameters. Please try again or contact the merchant
                          for help

                          - `70` : Total purchase amount has reached daily
                          limit. Please use difference account

                          - `79` : Payment Rejected!

                          - `80` : Custom fields invalid

                          - `81` : The total amount must be greater than 0.
                          Please double check and try again.

                          - `82` : Invalid transaction currency. We only support
                          USD or KHR. Please double check and try again.

                          - `83` : Transaction is duplicated.

                          - `84` : Unable to access the merchant's account
                          details. Please verify that your settlement account is
                          still active.

                          - `85` : Transaction currency does not match the
                          merchant's currency. Please review your details.

                          - `86` : Unable to debit the merchant's account.

                          - `87` : Unable to retrieve the beneficiary's account
                          details.

                          - `88` : Unable to retrieve the beneficiary's MID
                          details.

                          - `89` : Unable to retrieve the beneficiary's account
                          details.

                          - `90` : The currencies for the merchant and
                          beneficiary do not align. Please review your details.

                          - `91` : Unable to credit the beneficiary's account.

                          - `92` : The total payout amount does not match the
                          total transaction amount. Please review your details.

                          - `93` : Insufficient balance.

                          - `400` : Bad request

                          - `LAM01 ` : Total purchase amount has reached daily
                          limit. Please use difference account

                          - `LAM02 ` : Total purchase amount has reached monthly
                          limit. Please use difference account
                      message:
                        type: string
                        title: ''
                        description: >-
                          The message that associate with the code. Please above
                          code for the details.
                      tran_id:
                        type: string
                        title: ''
                        description: Unique transaction id pass from merchant
                      trace_id:
                        type: string
                        description: >-
                          A unique id generated by payment gateway, we can use
                          this number to trace issue when there is an error.
                    x-apidog-orders:
                      - code
                      - message
                      - tran_id
                      - trace_id
                x-apidog-orders:
                  - transaction_id
                  - transaction_date
                  - external_reference
                  - apv
                  - transaction_amount
                  - transaction_currency
                  - beneficiaries
                  - status
              examples:
                '1':
                  summary: Success
                  value:
                    transaction_id: '172595840773178'
                    transaction_date: '2024-09-10T15:53:27.2157019+07:00'
                    external_reference: 100FT30147412155
                    apv: '328097'
                    transaction_amount: 3.44
                    transaction_currency: USD
                    beneficiaries:
                      - payout_id: '172595842687056'
                        name: ''
                        mid_acccount: '200030000'
                        amount: 1.72
                        currency: USD
                      - payout_id: '172595842679750'
                        name: ''
                        mid_acccount: '012538302'
                        amount: 1.72
                        currency: USD
                    status:
                      code: '0'
                      message: Success!
                      tran_id: '172595840773178'
                      trace_id: e728bf3e95e32e3c97286fc9f8aef82d
                '2':
                  summary: Exception
                  value:
                    status:
                      code: '83'
                      message: Transaction is duplicated
                      tran_id: '172595840773178'
                      trace_id: e728bf3e95e32e3c97286fc9f8aef82d
          headers: {}
          x-apidog-name: OK
      security: []
      x-apidog-folder: Payout
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/831852/apis/api-14530816-run
components:
  schemas: {}
  securitySchemes: {}
servers:
  - url: https://checkout-sandbox.payway.com.kh/
    description: StillZeroBug
security: []

```
