Welcome to the AffanPay API documentation
You can now start developing code to communicate with AffanPay. This documentation provides detailed explanations on how to use each API endpoint effectively. All AffanPay APIs return responses in JSON format, including error messages.
DISCLAIMER:
AffanPay shall not be held responsible for any loss of funds due to improper or incorrect use of the API
API endpoint:
https://app.affanpay.my/api
POST Token https://app.affanpay.my/api/token
Use this API to retrieve a token. You’ll need to include this token in the header of every request to access other endpoints.
Request header
Accept: application/json
Parameter
Description
email
(Required) your registered email address in AffanPay
password
(Required) the password used to log in to the AffanPay account
Example Code
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://app.affanpay.my/api/token',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"email": "[contact@affanpay.my]",
"password": "[p@55w0rd]"
}',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response
{
"name": "AffanPay Sdn Bhd",
"email": "contact@affanpay.my",
"token": "9|dlCGdUN8a2TQqNLXG7ljWQP3dLLMB55Yg2AL47toffd0b525"
}
POST Create Bill https://app.affanpay.my/api/v1/bill
This API is used to create a bill. The generated bill can be directly used to initiate and receive payment collections.
Authorization
Token : generated from Token API
Request header
Accept: application/json
Parameter
Type
Description
category
string
(Optional) Category ID for the bill. This can be obtained in the Category section after logging into your account.
name
string
(Required) The name or title of the bill.
description
string
(Optional) A short description of the bill (maximum 200 characters).
html
string
(Optional) HTML content for the bill’s description. Must contain valid HTML tags.
amount
decimal
(Required) The total amount for the bill. Accepts up to 2 decimal places. Minimum value is 5.00.
fee_charge_payer
boolean
(Optional) Indicates whether the payer will bear the transaction fee. Value true/false
redirect_url
string
(Optional) URL to redirect the customer after payment completion.
callback_url
string
(Optional) Endpoint to receive asynchronous payment status updates (webhook).
external_ref
string
(Required) External reference or unique identifier for the bill in your system.
customer_name
string
(Required) Full name of the customer. Maximum 60 characters.
customer_email
(Required) Customer’s email address. Maximum 50 characters.
customer_phone
string
(Optional) Customer’s phone number. Maximum 20 characters.
source
(Optional) Source identifier for the bill creation. Maximum 40 characters.
expiry_date
string
(Optional) Expiry date of the bill. Must be today or later. Format: YYYY-MM-DD HH:MM:SS.
Example Code
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://app.affanpay.my/api/v1/bill',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"name": "",
"amount": "",
"customer_name": "",
"customer_email": ""
}',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer [token generated from Token API]'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response
{
"success": true,
"id": "pujsSUNLeIYo",
"url": "https://app.affanpay.my/pujsSUNLeIYo"
}
GET Requery Payment https://app.affanpay.my/api/v1/requery?query=value
AffanPay sends a payment status callback to your system for every transaction, whether successful or not. However, in some cases, the callback may fail or not be received as intended. This API allows you to query the latest status of a payment transaction directly from AffanPay’s system.
Authorization
Token : generated from Token API
Request header
Accept: application/json
Query param
To customise the request, you can append query parameters to the endpoint URL. Two types of parameters are supported but only one can be used at a time.
Parameter
Description
bill_id
The unique identifier of the bill used to retrieve its details and related payment records.
e.g: bill_id=wxUyT47ko3v
payment_ref
The reference number of the payment used to retrieve its transaction details.
e.g: payment_ref=AP01384088585413050521
Example Code
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://app.affanpay.my/api/v1/requery?bill_id=wxUyT47ko3v',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer [token generated from Token API]'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response
{
"data": {
"id": "wxUyT47ko3v",
"name": "Multi open amount",
"payments": [
{
"payment_ref": "AP01384263015313050521",
"status_code": 4,
"status": "No Action",
"nett_amount": " 0.00",
"payment_method": null
},
{
"payment_ref": "AP01384355115313050521",
"status_code": 3,
"status": "Failed",
"nett_amount": " 0.00",
"payment_method": "fpx"
},
{
"payment_ref": "AP01384088585413050521",
"status_code": 1,
"status": "Success",
"nett_amount": " 31.20",
"payment_method": "fpx"
}
]
}
}