Code Examples

Node.js

Installation

npm install axios

Create Virtual Account

const axios = require('axios');

const escaApi = axios.create({
  baseURL: 'https://api.esca.finance/v1',
  headers: {
    'X-Api-Key': process.env.ESCA_API_KEY,
    'Content-Type': 'application/json'
  }
});

async function createVirtualAccount(currency, email) {
  const response = await escaApi.post('/virtual-account', {
    currency,
    email
  }, {
    headers: {
      'X-Idempotency-Key': crypto.randomUUID()
    }
  });

  return response.data;
}

// Usage
const account = await createVirtualAccount('NGN', 'customer@example.com');
console.log('Created account:', account.data[0].accountNumber);

Initiate Transfer

async function initiateTransfer(params) {
  const { accountId, amount, destinationBankCode, destinationAccountNumber, destinationAccountName, description } = params;

  const response = await escaApi.post('/virtual-account/transfer', {
    currency: 'NGN',
    accountId,
    amount,
    destinationBankCode,
    destinationAccountNumber,
    destinationAccountName,
    description
  }, {
    headers: {
      'X-Idempotency-Key': crypto.randomUUID()
    }
  });

  return response.data;
}

// Usage
const transfer = await initiateTransfer({
  accountId: 12345,
  amount: 10000,
  destinationBankCode: '000007',
  destinationAccountNumber: '0123456789',
  destinationAccountName: 'JOHN DOE',
  description: 'Payment for services'
});

console.log('Transfer UUID:', transfer.data.uuid);

Python

Installation

pip install requests

Create Virtual Account

import requests
import uuid
import os

class EscaAPI:
    def __init__(self, api_key):
        self.base_url = 'https://api.esca.finance/v1'
        self.api_key = api_key

    def _headers(self, idempotency_key=None):
        headers = {
            'X-Api-Key': self.api_key,
            'Content-Type': 'application/json'
        }
        if idempotency_key:
            headers['X-Idempotency-Key'] = idempotency_key
        return headers

    def create_virtual_account(self, currency, email):
        response = requests.post(
            f'{self.base_url}/virtual-account',
            json={'currency': currency, 'email': email},
            headers=self._headers(str(uuid.uuid4()))
        )
        response.raise_for_status()
        return response.json()

    def initiate_transfer(self, account_id, amount, destination_bank_code,
                         destination_account_number, destination_account_name, description=''):
        response = requests.post(
            f'{self.base_url}/virtual-account/transfer',
            json={
                'currency': 'NGN',
                'accountId': account_id,
                'amount': amount,
                'destinationBankCode': destination_bank_code,
                'destinationAccountNumber': destination_account_number,
                'destinationAccountName': destination_account_name,
                'description': description
            },
            headers=self._headers(str(uuid.uuid4()))
        )
        response.raise_for_status()
        return response.json()

# Usage
api = EscaAPI(os.environ['ESCA_API_KEY'])

# Create account
account = api.create_virtual_account('NGN', 'customer@example.com')
print(f"Created account: {account['data'][0]['accountNumber']}")

# Initiate transfer
transfer = api.initiate_transfer(
    account_id=12345,
    amount=10000,
    destination_bank_code='000007',
    destination_account_number='0123456789',
    destination_account_name='JOHN DOE',
    description='Payment for services'
)
print(f"Transfer UUID: {transfer['data']['uuid']}")

PHP

<?php

class EscaAPI {
    private $baseUrl = 'https://api.esca.finance/v1';
    private $apiKey;

    public function __construct($apiKey) {
        $this->apiKey = $apiKey;
    }

    private function request($method, $endpoint, $data = null, $idempotencyKey = null) {
        $ch = curl_init();

        $headers = [
            'X-Api-Key: ' . $this->apiKey,
            'Content-Type: application/json'
        ];

        if ($idempotencyKey) {
            $headers[] = 'X-Idempotency-Key: ' . $idempotencyKey;
        }

        curl_setopt_array($ch, [
            CURLOPT_URL => $this->baseUrl . $endpoint,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_HTTPHEADER => $headers
        ]);

        if ($data) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        }

        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return json_decode($response, true);
    }

    public function createVirtualAccount($currency, $email) {
        return $this->request('POST', '/virtual-account', [
            'currency' => $currency,
            'email' => $email
        ], $this->generateUUID());
    }

    public function initiateTransfer($params) {
        return $this->request('POST', '/virtual-account/transfer', [
            'currency' => 'NGN',
            'accountId' => $params['accountId'],
            'amount' => $params['amount'],
            'destinationBankCode' => $params['destinationBankCode'],
            'destinationAccountNumber' => $params['destinationAccountNumber'],
            'destinationAccountName' => $params['destinationAccountName'],
            'description' => $params['description'] ?? ''
        ], $this->generateUUID());
    }

    private function generateUUID() {
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
            mt_rand(0, 0xffff), mt_rand(0, 0xffff),
            mt_rand(0, 0xffff),
            mt_rand(0, 0x0fff) | 0x4000,
            mt_rand(0, 0x3fff) | 0x8000,
            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
        );
    }
}

// Usage
$api = new EscaAPI($_ENV['ESCA_API_KEY']);

$account = $api->createVirtualAccount('NGN', 'customer@example.com');
echo "Created account: " . $account['data'][0]['accountNumber'] . "\n";

$transfer = $api->initiateTransfer([
    'accountId' => 12345,
    'amount' => 10000,
    'destinationBankCode' => '000007',
    'destinationAccountNumber' => '0123456789',
    'destinationAccountName' => 'JOHN DOE',
    'description' => 'Payment for services'
]);
echo "Transfer UUID: " . $transfer['data']['uuid'] . "\n";