Introduction
API Endpoint:
https://{Request from us}/merchant
Welcome to the SonicPay API! You can use our API to access SonicPay API endpoints to start sending bills and create order.
Our API is send by FORM-DATA , JSON will be returned in all responses from API , including errors . The API will accept multipart/form-data.
Sandbox Mode
API Endpoint:
https://{Request from us}/merchant
The SonicPay Sandbox mirrors the features found on the real production server , while some of the features do not apply to the Sandbox.
You should test your integrations and know they will behave the same on the production server as they do in Sandbox environment.
API Flow
NORMAL COMPLETION FLOW
- Customer visits your site.
- Customer choose product/fee and make payment .
- Your site create a order with id fee product info.
- Curl auth api to get a new auth token .
- Curl deposit_bank_list api to get bank id .
- Curl generate_orders api with order params , SonicPay will return url as response.
- Your site redirects the customer to the SonicPay url.
- The Customer makes payment via payment option of choice.
- SonicPay sends a server-side update to your site upon payment failure or success refer to your callback url.
API Currency
Example Request:
<?php
$username = "SonicPay-test"; //Merchant username
$send = array('username' => $username );
$apiurl = "https://{Request from us}/merchant/currency";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response:
{
"status": true,
"rate": [
{
"currency": "MYR",
"min": 420.0000,
"max": 42000.0000
},
{
"currency": "SGD",
"min": 134.0000,
"max": 13400.0000
}
]
}
Use this api feature you will get currency list data and minimum , maximum amount that SonicPay accept.
API Auth
Example Request:
<?php
$username = "SonicPay-test"; //Merchant username
$api_key = "EPSOWM0eewwrwer0OfUo"; //API key get from panel settings page
$send = array('username' => $username , 'api_key' => $api_key);
$apiurl = "https://{Request from us}/merchant/auth";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response:
{
"status": true,
"auth": "t5IF5r2fXit1FnhjBVQv"
}
Example Response (Failed):
{
"status": false,
"message": "Params incorrect"
}
Your Auth token for SonicPay generate_orders api by providing your Api_key and username in request.
You can get Api_keys from your account settings page.
API Generate orders
Example Request:
<?php
$username = "john"; //Customer Username
$auth = "t5IF5r2fXit1FnhjBVQv"; //Get from auth api
$amount = 100; //Price amount
$currency = "THB"; //Currency code
$orderid = "Example_123"; //Merchant order ID
$email = "[email protected]"; //Customer Email
$phone_number = "601012456789"; //Customer Phone number
$redirect_url = "https://www.google.com"; //Redirect Url
$customer_bank_holder_name = "tang"; //Customer Bank Holder Name
$customer_bank_account = "1234"; //Customer Bank Account
$bank_id = "105"; //Bank Id
$pay_method = "thaiqr"; //Either 1 option : "thaiqr" , "truemoney"
$callback_url = "https://abc.com/deposit/callback"; //callback link url (optional)
$send = array(
'username' => $username,
'auth' => $auth,
'amount' => $amount,
'currency' => $currency,
'orderid' => $orderid,
'email' => $email,
'phone_number' => $phone_number,
'redirect_url' => $redirect_url,
'customer_bank_holder_name' => $customer_bank_holder_name,
'customer_bank_account' => $customer_bank_account,
'bank_id' => $bank_id,
'pay_method' => $pay_method
'callback_url' => $callback_url
);
$apiurl = "https://{Request from us}/merchant/generate_orders";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response:
{
"status": true,
"p_url": "https://xxxxx.com/checkout/order-pay/92/?pay_for_order=true&key=1234",
"payment_id": "123456_1_123"
}
Example Response (Failed):
//when email incorrect
{
"status": false,
"message": "email incorrect."
}
Example Response (Failed):
//when params missing
{
"status": false,
"message": "Params missing."
}
Example Response (Failed):
//When order id incorrect or exist
{
"status": false,
"message": "Order ID Exist."
}
Example Response (Failed):
//when amount empty or out of range
{
"status": false,
"message": "Invalid Amount."
}
Example Response (Failed):
//when auth expire or wrong
{
"status": false,
"message": "Params incorrect."
}
To generate a order , you would need to create a order on your side and get a Auth token #2 before generate.
After that you will send order info and auth token together as params to generate orders api , to get payment url.
API Callback Url
Example Response (Generate Orders) - Completed:
{
"order_id": "20073",
"amount": 300.0000,
"currency": "THB",
"order_status":"completed",
"status": true,
"charge": "9.0000",
"token":"cb2a91e02770eda1c42d7485f9048913",
"name":"john doe",
"type":"deposit",
}
Example Response(Generate Orders) - fail:
{
"order_id": "Example_123",
"amount": 25.0000,
"currency": "THB",
"order_status":"fail",
"status": true,
"token":"aZ3423432CWWSDFssdf",
"charge":"5.00",
"type":"deposit",
}
Example Response(Withdraw) - completed:
{
"order_id": "Testpayout008",
"amount": 1,
"currency": "THB",
"order_status":"completed",
"status": true,
"charge": "5.00",
"token":"5bf30f18349ce1211fdb0c7aff4d439b",
"name":"John Doe",
"type":"withdrawal",
"remarks":"Success",
}
Example Response(Withdraw) - fail:
{
"order_id": "Testpayout008",
"amount": 1,
"currency": "THB",
"order_status":"fail",
"status": true,
"charge": "0",
"token":"7fd1297bfc1bd843e9627d09afce0893",
"name":"SUK THAWAR",
"type":"withdrawal",
"remarks":"Account Holder Name Mismatch (MR SUK THA != SUK THAWAR)",
}
Example Response(Withdraw) - rejected:
{
"order_id": "Testpayout008",
"amount": 1,
"currency": "THB",
"order_status":"rejected",
"status": true,
"charge": "0",
"token":"7fd1297bfc1bd843e9627d09afce0893",
"name":"SUK THAWAR",
"type":"withdrawal",
"remarks":"Account Holder Name Mismatch (MR SUK THA != SUK THAWAR)",
}
After customer make payment . SonicPay will make a POST request with JSON data to callback_url that set in your account settings page.
Note: Token will need check by MD5 "Secret_key" + "Order_id"
API Withdraw orders
Example Request:
<?php
$auth = "SonicPay-test"; //Get from auth api
$amount = 100; //Price amount
$currency = "THB"; //Currency code
$orderid = "Example_123"; //Merchant withdraw order ID
$bank_id = "12"; //Get from withdraw bank list api
$bank_branch = "Kentucky"; //Optional
$holder_name = "John Doe"; //Insert the receiver holder name must same as receiver bank account.
$account_no = "12332343432"; //Receiver Bank Account no
$callback_url = "https://abc.com/withdraw/callback"; //callback link url (optional)
$send = array(
'auth' => $auth,
'amount' => $amount,
'currency' => $currency,
'orderid' => $orderid,
'bank_id' => $bank_id,
'bank_branch' => $bank_branch,
'holder_name' => $holder_name,
'account_no' => $account_no,
'callback_url' => $callback_url,
);
$apiurl = "https://{Request from us}/merchant/withdraw_orders";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response(success):
{
"status": true,
"message": "Success",
"payment_id": "015459_330_164",
}
Example Response(fail):
{
"status": false,
"message": "Params incorrect",
}
Example Response(fail):
{
"status": false,
"message": "Params missing.",
}
Example Response(fail):
{
"status": false,
"message": "bank_id invalid.",
}
Example Response(fail):
{
"status": false,
"message": "Balance not enough!",
}
Example Response(fail):
{
"status": false,
"message": "Amount Invalid!",
}
Example Response(fail):
{
"status": false,
"message": "Order id exist!",
}
To withdraw a order , you would need to create a withdraw order on your side and get a Auth token #2 before withdraw .
After that you will send withdraw order info and auth token together as params to withdraw orders api.
Deposit Bank List
Example Request:
<?php
$username = "SonicPay-test"; //Merchant username
$currency = "THB"; //Optional
$send = array(
'username' => $username,
'currency' => $currency
);
$apiurl = "https://{Request from us}/wallet/bank_list";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response:
{
"status": true,
"data": [
{
"currency": "THB",
"bank_name": "Siam Commercial Bank",
"id": "1"
},
{
"currency": "THB",
"bank_name": "Siam Commercial Bank",
"id": "2"
}
]
}
Curl deposit bank list api to get bank details for deposit orders .
Withdraw Bank List
Example Request:
<?php
$username = "SonicPay-test"; //Merchant username
$currency = "THB"; //Optional
$send = array(
'username' => $username,
'currency' => $currency
);
$apiurl = "https://{Request from us}/wallet/withdraw_bank_list";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response:
{
"status": true,
"data": [
{
"currency": "THB",
"bank_name": "Siam Commercial Bank",
"id": "1"
},
{
"currency": "THB",
"bank_name": "Siam Commercial Bank",
"id": "2"
}
]
}
Curl withdraw bank list api to get bank details for withdraw orders .
API Check Status
Example Request:
<?php
$username = "john"; //Merchant Username
$id = "Example_123"; //Merchant order ID
$send = array(
'username' => $username,
'id' => $id
);
$apiurl = "https://{Request from us}/merchant/check_status";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response - Completed:
{
"status": true,
"order_status": "completed",
"order_datetime": "2021-11-18 15:00:00",
"amount": 300.0000,
"currency": "THB",
}
Example Response - Fail:
{
"status": true,
"order_status": "fail",
"order_datetime": "2021-11-19 13:30:00",
"amount": 25.0000,
"currency": "THB",
}
Example Response - Pending:
{
"status": true,
"order_status": "pending",
"order_datetime": "2021-11-20 20:00:00",
"amount": 100.0000,
"currency": "THB",
}
Your order status for SonicPay check_status api by providing username and id in request.
API Check Withdraw Status
Example Request:
<?php
$username = "john"; //Merchant Username
$id = "Example_123"; //Merchant Withdraw order ID
$send = array(
'username' => $username,
'id' => $id
);
$apiurl = "https://{Request from us}/merchant/check_withdraw_status";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response - Completed:
{
"status": true,
"order_status": "completed",
"order_datetime": "2021-11-18 15:00:00",
"amount": 300.0000,
"currency": "THB",
}
Example Response - Fail:
{
"status": true,
"order_status": "fail",
"order_datetime": "2021-11-19 13:30:00",
"amount": 25.0000,
"currency": "THB",
}
Example Response - Proccess:
{
"status": true,
"order_status": "proccess",
"order_datetime": "2021-11-20 20:00:00",
"amount": 100.0000,
"currency": "THB",
}
Example Response - Rejected:
{
"status": true,
"order_status": "rejected",
"order_datetime": "2021-11-20 20:00:00",
"amount": 100.0000,
"currency": "THB",
}
Your withdraw status for SonicPay check_withdraw_status api by providing username and id in request.
API Balance
Example Request:
<?php
$auth = "skcblasjkcb"; //get from api auth
$currency = "THB";
$send = array(
'auth' => $auth,
'currency' => $currency
);
$apiurl = "https://{Request from us}/wallet/get_balance";
$curl = curl_init($apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example Response:
{
"status": true,
"balance": "0.00"
}
Allows users to check the current balance of their wallet. It returns the balance in the specified currency, providing an up-to-date and accurate reflection of the wallet's available funds.