This guide outlines the steps for integrating AmarPay into your Node.js application.
AmarPay provides REST APIs for payment processing. Use the Sandbox environment for testing and the Live environment for production.
- Sandbox API Endpoint:
https://sandbox.aamarpay.com/jsonpost.php
- Live API Endpoint: Provided by AmarPay upon going live.
For testing, use:
- Store ID:
aamarpaytest
- Signature Key:
dbb74894e82415a2f7ff0ec3a97e4183
For production, use the Store ID and Signature Key provided by AmarPay.
The following parameters are required for the payment request:
store_id
: Store ID (e.g., aamarpaytest)signature_key
: Signature key (e.g., dbb74894e82415a2f7ff0ec3a97e4183)cus_name
: Client's namecus_email
: Client's email addresscus_phone
: Client's phone numbercus_add1
: Client's primary addresscus_add2
: Client's secondary address (optional)cus_city
: Client's city namecus_country
: Client's country nameamount
: Amount to be paidtran_id
: Unique transaction IDcurrency
: Currency type (e.g., BDT / USD)success_url
: Success page URLfail_url
: Fail page URLcancel_url
: Cancel page URLdesc
: Payment descriptionopt_a
,opt_b
,opt_c
: Optional parameterstype
: Should bejson
to pass JSON data
Request Body
const request = require('request');
const options = {
url: 'https://sandbox.aamarpay.com/jsonpost.php',
method: 'POST',
json: true,
body: {
store_id: "aamarpaytest",
signature_key: "dbb74894e82415a2f7ff0ec3a97e4183",
cus_name: "Fahim Ahammed Firoz",
cus_email: "fahim@ph.com",
cus_phone: "0199999999",
cus_add1: "Dhaka, Bangladesh",
cus_add2: "Dhaka",
cus_city: "Dhaka",
cus_country: "Bangladesh",
amount: "500.00",
tran_id: "TNX-453243",
currency: "BDT",
success_url: "https://example.com/success.php",
fail_url: "https://example.com/fail.php",
cancel_url: "https://example.com/cancel.php",
desc: "Course Fee",
type: "json"
}
};
request(options, function (error, response, body) {
if (error) {
console.error('Error:', error);
} else {
console.log('Response:', body);
}
});
Response Body
{
"result": "true",
"payment_url": "https://sandbox.aamarpay.com/paynow.php?track=AAM1604476085103491"
}
This guide explains how to verify a payment transaction using AmarPay’s API in a Node.js application.
- Sandbox API Endpoint:
https://sandbox.aamarpay.com/api/v1/trxcheck/request.php
- Store ID:
aamarpaytest
- Signature Key:
dbb74894e82415a2f7ff0ec3a97e4183
The Search Transaction API provides detailed information about a specific transaction using the merchant transaction ID.
The following parameters are required for the transaction verification request:
Parameter | Requirement | Type | Description | Example |
---|---|---|---|---|
request_id |
Mandatory | String | Unique identifier for merchant transactions, also known as the merchant transaction ID. | WEP-SMZZ4ZM8EC |
store_id |
Mandatory | String | Merchant ID assigned by AmarPay, serving as your unique identifier. | aamarpaytest |
signature_key |
Mandatory | String | Signature Key issued by AmarPay for unique authentication. | dbb74894e82415a2f7ff0ec3a97e4183 |
type |
Mandatory | String | The value should always be "json" to indicate JSON data format. |
json |
Below is an example of how to make a request to the AmarPay API using Node.js with the axios
library:
const axios = require('axios');
// Base URL for AmarPay API
const AMARPAY_VERIFY_URL = 'https://sandbox.aamarpay.com/api/v1/trxcheck/request.php';
// Credentials
const STORE_ID = 'aamarpaytest';
const SIGNATURE_KEY = 'dbb74894e82415a2f7ff0ec3a97e4183';
// Function to verify transaction
async function verifyTransaction(transactionId) {
try {
const response = await axios.get(AMARPAY_VERIFY_URL, {
params: {
store_id: STORE_ID,
signature_key: SIGNATURE_KEY,
request_id: transactionId,
type: 'json',
},
});
console.log('Verify response:', response.data);
return response.data;
} catch (error) {
console.error('AmarPay verification error:', error);
throw new Error('Payment verification failed');
}
}
// Example usage
verifyTransaction('TNX-453243');
Here’s an example of the response you might receive from the AmarPay API:
{
"pg_txnid": "AAMXXXXXXXXXXXX",
"mer_txnid": "XXXXXXXXXX",
"risk_title": "Not-Available",
"risk_level": null,
"cus_name": "Fahim Ahammed Firoz",
"cus_email": "fahim@ph.com",
"cus_phone": "01999999999",
"cus_add1": "Dhaka",
"cus_add2": "Dhaka",
"cus_city": "Dhaka",
"cus_state": "Dhaka",
"cus_postcode": "1206",
"cus_country": "Bangladesh",
"cus_fax": "",
"ship_name": null,
"ship_add1": null,
"ship_add2": null,
"ship_city": null,
"ship_state": null,
"ship_postcode": null,
"ship_country": null,
"desc": null,
"merchant_id": "XXXXXXX",
"store_id": "XXXXXXX",
"amount": "500.00",
"amount_bdt": "500.00",
"pay_status": "Successful",
"status_code": "2",
"status_title": "Successful Transaction",
"cardnumber": "XXXXXXXXXXXXXXX",
"approval_code": "XXXXXXXXXXX",
"payment_processor": "XXXXXXXXXX",
"bank_trxid": "XXXXXXXXXXXXX",
"payment_type": "XXXXXXXXX",
"error_code": "0000",
"error_title": "Not-Available",
"bin_country": "Not-Available",
"bin_issuer": "Not-Available",
"bin_cardtype": "Not-Available",
"bin_cardcategory": "Not-Available",
"date": "2018-03-17 15:20:55",
"date_processed": "2018-03-17 15:55:35",
"amount_currency": "10.00",
"rec_amount": "9.65",
"processing_ratio": "3.50",
"processing_charge": "0.35",
"ip": "XXXXXXXXXXX",
"currency": "BDT",
"currency_merchant": "BDT",
"convertion_rate": "Not-Available",
"opt_a": "Not-Available",
"opt_b": "Not-Available",
"opt_c": "Not-Available",
"opt_d": "Not-Available",
"verify_status": "PENDING",
"call_type": "Post-Method",
"email_send": "1",
"doc_recived": "NO",
"checkout_status": "Not-Paid-Yet"
}
This guide should help you integrate and verify transactions with AmarPay using Node.js. Adjust the code and parameters as needed for your specific implementation.
In case of a failed transaction, the same data will be sent to your fail_url
. Note that the cancel_url
will not receive any data; it should be a link to your product or home page.
Ensure you replace test credentials with production credentials when moving to live transactions. For more details, refer to the AmarPay API Documentation.