How to interface with Pakistan Payments API?
How to interface with Pakistan Payments API?
I. Overview of the payments market in Pakistan
As the second largest economy in South Asia, Pakistan has seen rapid growth in digital payments in recent years. According to the State Bank of Pakistan (SBP), the country's mobile wallet users have exceeded 50 million in 2022, and the volume of electronic transactions has increased by 45% year-on-year. for enterprises wishing to enter the Pakistani market, it is crucial to understand the mainstream local payment methods and realise API docking.
Mainstream payment channels include:
- JazzCash (largest mobile wallet)
- EasyPaisa (owned by Telenor)
- HBL Konnect (Habibank Electronic Wallet)
- UnionPay International (UPI) Co-operation Channel in Pakistan
- Local bank card 1Link/PTCL system
II. Preliminary preparatory work
1. Register for a merchant account
Visit the official website of the target payment platform (e.g. JazzCash merchant page) and submit:
- Company Registration Documents
- NTN Tax ID Certificate
- Proof of director's identity
III. API docking technology implementation steps
1. Get API documentation and test environment
After completing merchant registration, payment platforms typically provide the following resources:
- Sandbox test account (for demo trading)
- API documentation (REST/JSON format mainly)
- SDK or code samples (some platforms provide Java/PHP/Python libraries)
Key configuration items:
"`bash
# JazzCash Typical Configuration Example
API_ENDPOINT = "https://sandbox.jazzcash.com.pk/api/v1/payment"
MERCHANT_ID = "YOUR_MERCHANT_ID"
SECURE_HASH_KEY = "xxxxxx" # for signature verification
CALLBACK_URL = "https://yourdomain.com/callback"
“`
2. Interface authentication and security mechanisms
The following security schemes are commonly used in Pakistani payment APIs:
| Security Mechanisms | Descriptions |
|—————-|———————————————————————-|
| OAuth2.0 | EasyPaisa and other platforms require access_token first |
| IP Whitelisting | Requires server IP binding in merchant backend |
| HMAC-SHA256 | JazzCash and others require that request parameters be ordered to generate a signature |
PHP signature generation example:
"`php
$data = [
'amount' => '1000',
'orderId' => 'ORD123456',
'timestamp' => time()
];
ksort($data); // sort by key name
$signature = hash_hmac('sha256', http_build_query($data), $SECURE_HASH_KEY);
“`
—
3.Core interface development practice
(1) Initiate a payment request
Typical HTTP POST request structure:
"`json
// JazzCash Payment Request Example
{
"pp_Version": "1.1",
"pp_TxnType": "MWALLET".
"pp_Language": "EN".
pp_MERCHANTID: MERCHANT_ID,
pp_SubMerchantID: "",
pp_Password: API_PASSWORD,
pp_BankID: "",
pp_ProductID: "",
pp_TxnRefNo": uniqid(),
}
“`
> ✅ *Note: The unit of the amount needs to be converted to rupees (e.g. 100 PKR ≈ $0.36)*.
—
(2) Handling asynchronous callbacks
When the user completes the payment, the platform will POST a notification to your `CALLBACK_URL`. Required:
1️⃣ Verify Signature Legitimacy
Compare the received hash value with the locally calculated checksum value
2️⃣ Power handling
Use of `transaction_id` to avoid duplicate postings
3️⃣ Responds to standard formats
Returns HTTP200 and acknowledgement messages:
"`xml
“`
—
IV. Guidelines for troubleshooting common problems
❌Error Code `403 Forbidden`
→ IP not whitelisted or Headers missing Authorisation
❌ Error Code `500 Invalid Hash`
→ Check whether the parameter order is consistent with the document, the time stamp error needs to be ≤ 5 minutes
💡 *debugging advice*: test the base process with Postman before embedding it in the formal system.
—
Basic alignment can be completed by following the above steps. It is recommended to stay tuned to [State Bank of Pakistan Policy Updates](https://www.sbp.org.pk) to ensure compliance with the PSP/EMI qualification compliance requirements as per the new 2023 regulations.