Create Payment Method - Afriex Business API
Afriex SDK
TypeScript
const paymentMethod = await afriex.paymentMethods.create({
channel: "BANK_ACCOUNT",
customerId: "customer-id",
accountName: "John Doe",
accountNumber: "1234567890",
countryCode: "NG",
institution: {
institutionCode: "044",
institutionName: "Access Bank",
},
});
curl --request POST \
--url https://sandbox.api.afriex.com/api/v1/payment-method \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"customerId": "69528240ba52c13b669fb239",
"type": "WITHDRAW",
"channel": "BANK_ACCOUNT",
"accountName": "John Doe",
"accountNumber": "0123456789",
"countryCode": "NG",
"institution": {
"institutionCode": "058",
"institutionName": "GTBank"
}
}
'```
```python
import requests
url = "https://sandbox.api.afriex.com/api/v1/payment-method"
payload = {
"customerId": "69528240ba52c13b669fb239",
"type": "WITHDRAW",
"channel": "BANK_ACCOUNT",
"accountName": "John Doe",
"accountNumber": "0123456789",
"countryCode": "NG",
"institution": {
"institutionCode": "058",
"institutionName": "GTBank"
}
}
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',
channel: 'BANK_ACCOUNT',
accountName: 'John Doe',
accountNumber: '0123456789',
countryCode: 'NG',
institution: {institutionCode: '058', institutionName: 'GTBank'}
})
};
fetch('https://sandbox.api.afriex.com/api/v1/payment-method', 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/payment-method",
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',
'channel' => 'BANK_ACCOUNT',
'accountName' => 'John Doe',
'accountNumber' => '0123456789',
'countryCode' => 'NG',
'institution' => [
'institutionCode' => '058',
'institutionName' => 'GTBank'
]
]),
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/payment-method"
payload := strings.NewReader("{\n \"customerId\": \"69528240ba52c13b669fb239\",\n \"type\": \"WITHDRAW\",\n \"channel\": \"BANK_ACCOUNT\",\n \"accountName\": \"John Doe\",\n \"accountNumber\": \"0123456789\",\n \"countryCode\": \"NG\",\n \"institution\": {\n \"institutionCode\": \"058\",\n \"institutionName\": \"GTBank\"\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/payment-method")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"69528240ba52c13b669fb239\",\n \"type\": \"WITHDRAW\",\n \"channel\": \"BANK_ACCOUNT\",\n \"accountName\": \"John Doe\",\n \"accountNumber\": \"0123456789\",\n \"countryCode\": \"NG\",\n \"institution\": {\n \"institutionCode\": \"058\",\n \"institutionName\": \"GTBank\"\n }\n}")
.asString();
require 'uri'
require 'net/http'
url = URI("https://sandbox.api.afriex.com/api/v1/payment-method")
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 \"channel\": \"BANK_ACCOUNT\",\n \"accountName\": \"John Doe\",\n \"accountNumber\": \"0123456789\",\n \"countryCode\": \"NG\",\n \"institution\": {\n \"institutionCode\": \"058\",\n \"institutionName\": \"GTBank\"\n }\n}"
response = http.request(request)
puts response.read_body
Response
201
{
"data": {
"paymentMethodId": "69d6002579101baa20f63816",
"channel": "BANK_ACCOUNT",
"customerId": "69d60024ab82306f11b03325",
"institution": {
"institutionCode": "000013",
"institutionName": "GTBank"
},
"accountName": "John Doe",
"accountNumber": "0123456789",
"countryCode": "NG"
}
}
Create a New Payment Method
Create a new payment method for a customer. Supported channels include bank accounts, mobile money, SWIFT, UPI, Interac, and WeChat.
Note
Fields without values are not included in the response. This includes fields with empty strings, null values, and undefined values.
accountName Character Rules
For every channel except WE_CHAT and ALIPAY, the account holder’s name must use only English letters (A-Z / a-z), spaces, and the characters hyphen (-), apostrophe ('), and period (.). Names in other scripts (e.g. Arabic, Cyrillic), or containing digits or other symbols, are rejected. For WE_CHAT and ALIPAY payouts, submit the beneficiary’s local-script name (e.g. Chinese characters) as it appears on their wallet.