Create Transaction - Afriex Business API
Afriex SDK
TypeScript
const transaction = await afriex.transactions.create({
customerId: "customer-id",
sourceAmount: "10",
destinationAmount: "5000",
sourceCurrency: "USD",
destinationCurrency: "NGN",
destinationId: "payment-method-id",
meta: {
idempotencyKey: "unique-key-123",
reference: "order-456",
narration: "Payment for services",
},
});
curl --request POST \
--url https://sandbox.api.afriex.com/api/v1/transaction \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"customerId": "69528240ba52c13b669fb239",
"type": "WITHDRAW",
"destinationAmount": 5000,
"sourceCurrency": "USD",
"destinationCurrency": "NGN",
"destinationId": "690df3281c11eea59108fcaf",
"meta": {
"reference": "ref-withdraw-001",
"idempotencyKey": "idem-withdraw-001"
}
}
'
import requests
url = "https://sandbox.api.afriex.com/api/v1/transaction"
payload = {
"customerId": "69528240ba52c13b669fb239",
"type": "WITHDRAW",
"destinationAmount": 5000,
"sourceCurrency": "USD",
"destinationCurrency": "NGN",
"destinationId": "690df3281c11eea59108fcaf",
"meta": {
"reference": "ref-withdraw-001",
"idempotencyKey": "idem-withdraw-001"
}
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customerId: '69528240ba52c13b669fb239',
type: 'WITHDRAW',
destinationAmount: 5000,
sourceCurrency: 'USD',
destinationCurrency: 'NGN',
destinationId: '690df3281c11eea59108fcaf',
meta: {reference: 'ref-withdraw-001', idempotencyKey: 'idem-withdraw-001'}
})
};
fetch('https://sandbox.api.afriex.com/api/v1/transaction', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://sandbox.api.afriex.com/api/v1/transaction",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customerId' => '69528240ba52c13b669fb239',
'type' => 'WITHDRAW',
'destinationAmount' => 5000,
'sourceCurrency' => 'USD',
'destinationCurrency' => 'NGN',
'destinationId' => '690df3281c11eea59108fcaf',
'meta' => [
'reference' => 'ref-withdraw-001',
'idempotencyKey' => 'idem-withdraw-001'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sandbox.api.afriex.com/api/v1/transaction"
payload := strings.NewReader("{\n \"customerId\": \"69528240ba52c13b669fb239\",\n \"type\": \"WITHDRAW\",\n \"destinationAmount\": 5000,\n \"sourceCurrency\": \"USD\",\n \"destinationCurrency\": \"NGN\",\n \"destinationId\": \"690df3281c11eea59108fcaf\",\n \"meta\": {\n \"reference\": \"ref-withdraw-001\",\n \"idempotencyKey\": \"idem-withdraw-001\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
HttpResponse<String> response = Unirest.post("https://sandbox.api.afriex.com/api/v1/transaction")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"69528240ba52c13b669fb239\",\n \"type\": \"WITHDRAW\",\n \"destinationAmount\": 5000,\n \"sourceCurrency\": \"USD\",\n \"destinationCurrency\": \"NGN\",\n \"destinationId\": \"690df3281c11eea59108fcaf\",\n \"meta\": {\n \"reference\": \"ref-withdraw-001\",\n \"idempotencyKey\": \"idem-withdraw-001\"\n }\n}")
.asString();
require 'uri'
require 'net/http'
url = URI("https://sandbox.api.afriex.com/api/v1/transaction")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customerId\": \"69528240ba52c13b669fb239\",\n \"type\": \"WITHDRAW\",\n \"destinationAmount\": 5000,\n \"sourceCurrency\": \"USD\",\n \"destinationCurrency\": \"NGN\",\n \"destinationId\": \"690df3281c11eea59108fcaf\",\n \"meta\": {\n \"reference\": \"ref-withdraw-001\",\n \"idempotencyKey\": \"idem-withdraw-001\"\n }\n}"
response = http.request(request)
puts response.read_body
Response Example
{
"data": {
"status": "PENDING",
"type": "WITHDRAW",
"channel": "BANK_ACCOUNT",
"sourceAmount": "3.28847",
"sourceCurrency": "USD",
"destinationAmount": "5000",
"destinationCurrency": "NGN",
"destinationId": "690df3281c11eea59108fcaf",
"customerId": "69528240ba52c13b669fb239",
"transactionId": "69d60071ab82306f11b03393",
"meta": {
"reference": "ref-withdraw-001",
"idempotencyKey": "idem-withdraw-001"
},
"createdAt": "2026-04-08T07:14:57.444Z",
"updatedAt": "2026-04-08T07:14:57.444Z"
}
}
Description
Create a new transaction to process a payment for a customer. Use type: WITHDRAW to send funds to a destination payment method (requires destinationId), type: DEPOSIT to pull funds from a source payment method (requires sourceId), or type: SWAP to convert funds between currencies within the Afriex wallet. A SWAP requires sourceCurrency, destinationCurrency, meta, and exactly one of sourceAmount or destinationAmount: the API computes the other side at the live exchange rate. Providing both amounts is rejected.
Testing in sandbox? Sandbox transactions settle automatically within ~1-2 minutes and send the TRANSACTION.UPDATED webhook. Set meta.reference to a value containing fail to test a FAILED outcome, or any other value for SUCCESS. To exercise OTP-required deposits, add SIMULATE_OTP to meta.reference and complete with Authorize Transaction. See Testing transaction outcomes in sandbox.
Authorizations
- x-api-key: string, required header
Static business API key issued from the dashboard. A business can provision multiple API keys, each scoped to a configurable set of permissions (e.g. read transactions, create deposits, etc). Permissions may be revoked by deleting the key.
Headers
- x-api-version: string, required API version in ISO 8601 format.
Body
- Withdraw
- Deposit
- Swap