GoPay Merchant Gateway API
Integrate instant checkouts, wallet-to-wallet settlements, automated customer payouts, and cryptographic webhook verification in Pakistan.
HTTPS with TLS 1.3 encryption required.
UTF-8 encoded JSON bodies and responses.
Private server-to-server secret token.
Authentication & API Security
Zero-exposure server-side secret tokens
All GoPay API requests must be authenticated using your website's private Secret Key. Pass your secret key in the HTTP request headers using either the standard Bearer authorization header or the custom X-API-SECRET header.
Authorization: Bearer sk_live_YOUR_SECRET_KEY X-API-SECRET: sk_live_YOUR_SECRET_KEY Content-Type: application/json Accept: application/json
To protect the Pakistani payments ecosystem, API credentials (sk_live_...) are strictly generated only for approved eCommerce websites reviewed by GoPay administration. Apply via your Merchant Portal under Websites & Gateways. Each key can be scoped to Both (Deposit & Withdrawal), Deposit Only (payments), or Withdrawal Only (payouts) in your API Credentials dashboard.
API Endpoints Directory
10 Operational Methods| # | Method | Endpoint | Function | Auth Required |
|---|---|---|---|---|
| 1 | POST | /v1/gateway/payments | Create checkout payment session | Secret Key |
| 2 | GET | /v1/gateway/payments/{token} | Check payment order status & receipt | Secret Key |
| 3 | GET | /checkout/{payment_token} | Hosted browser checkout page for customers | Public Web |
| 4 | POST | /v1/gateway/check-user | Verify user existence on GoPay | Secret Key |
| 5 | POST | /v1/gateway/pay-to-user | Instant withdrawable payout to user wallet | Secret Key |
| 6 | POST | /v1/gateway/account-link/initiate | Initiate Account Linking session & get hosted authorize URL | Secret Key |
| 7 | GET | /account-link/{token} | Customer web authorization panel (User verifies MPIN) | GoPay Web Panel |
| 8 | POST | /v1/gateway/linked-account/deposit | Direct deposit / payment from linked account with MPIN | Secret Key |
| 9 | POST | /v1/gateway/linked-account/withdraw | Direct withdrawal / payout into customer's linked GoPay account | Secret Key |
| 10 | GET | /v1/gateway/linked-account/{link_token} | Inspect linked account status (zero-balance privacy) | Secret Key |
Create Payment Session
POST https://gopay.com.pk/api/v1/gateway/payments
When your customer proceeds to payment, make a server-to-server POST request with order information. GoPay returns a secure checkout_url and a unique payment_token.
JSON Body Parameters
| Field | Type | Requirement | Description |
|---|---|---|---|
| order_id | string | Required | Your store's unique order reference (e.g. ORD-98421). Strictly idempotent. |
| amount | numeric | Required | Order amount in PKR (minimum: 1.00). |
| currency | string | Optional | Currency code (default: PKR). |
| web_user | string | Optional | Your platform's username / account handle for the purchasing user (also accepted as customer.username or customer.web_user). If omitted, GoPay displays Anonymous by default. |
| customer | object | Optional | Customer details: {"name": "...", "email": "...", "phone": "...", "username": "..."}. |
| callback_url | url | Optional | Browser redirect destination after customer completes or cancels payment. |
| webhook_url | url | Optional | Custom server IPN webhook endpoint override for this specific order. |
| metadata | object | Optional | Arbitrary key-value store returned in webhooks and status queries. |
curl -X POST https://gopay.com.pk/api/v1/gateway/payments \
-H "Authorization: Bearer «redac...e_…»" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"order_id": "ORD-98421",
"amount": 1500.00,
"currency": "PKR",
"web_user": "hamza_akram",
"customer": {
"name": "Hamza Ali",
"email": "hamza@example.com",
"phone": "03001234567"
},
"callback_url": "https://yourwebsite.com/checkout/success",
"metadata": { "cart_id": "1042" }
}'
{
"success": true,
"payment_token": "pay_9f8e7d6c5b4a3210...",
"checkout_url": "https://gopay.com.pk/checkout/pay_9f8e7d6c5b4a3210...",
"order_id": "ORD-98421",
"amount": 1500.00,
"fee_amount": 30.00,
"net_amount": 1470.00,
"currency": "PKR",
"web_user": "hamza_akram",
"status": "pending",
"expires_at": "2026-11-02T18:30:00Z"
}
Hosted Checkout & 6-Digit MPIN Authorization
GET https://gopay.com.pk/checkout/{payment_token}
Direct your customer to the returned checkout_url in their browser, mobile webview, or iframe.
Registered GoPay customers pay instantly using their combined balances. Payment confirmation strictly requires the customer to enter their 6-digit security MPIN.
Customers who don't have an active GoPay account can pay via integrated mobile wallets (EasyPaisa, JazzCash) or bank transfer IBAN directly on the checkout screen.
callback_url:https://yourwebsite.com/checkout/success?order_id=ORD-98421&status=paid&token=pay_9f8e7d6c5b4a3210...
Instant Payment Notification (IPN Webhook)
HMAC-SHA256 Cryptographic Signature Verification
To prevent fraud and front-channel manipulation, never fulfill orders solely based on the browser redirect. Always configure and verify incoming server-to-server webhook events delivered with the X-GoPay-Signature HTTP header.
t is the UNIX timestamp and v1 is the hex-encoded HMAC-SHA256 signature calculated over {timestamp}.{raw_json_body} using your website's Webhook Secret.
<?php
$payload = file_get_contents('php://input');
$sigHeader = $_SERVER['HTTP_X_GOPAY_SIGNATURE'] ?? '';
$webhookSecret = 'whsec_YOUR_WEBHOOK_SECRET'; // From Merchant Dashboard
// Parse header: t={timestamp},v1={hash}
parse_str(str_replace(',', '&', $sigHeader), $sigParts);
$timestamp = $sigParts['t'] ?? '';
$receivedHash = $sigParts['v1'] ?? '';
// Check timestamp replay (within 5 minutes)
if (abs(time() - (int)$timestamp) > 300) {
http_response_code(400);
exit("Timestamp expired or clock skew.");
}
// Compute expected HMAC-SHA256
$expectedHash = hash_hmac('sha256', "{$timestamp}.{$payload}", $webhookSecret);
if (hash_equals($expectedHash, $receivedHash)) {
$event = json_decode($payload, true);
if ($event['event'] === 'payment.completed') {
$orderId = $event['data']['order_id'];
$amount = $event['data']['amount'];
// TODO: Mark order as PAID in your database and fulfill goods!
}
http_response_code(200);
echo json_encode(['received' => true]);
} else {
http_response_code(400);
echo "Invalid cryptographic signature";
}
Query Payment Status API
GET https://gopay.com.pk/api/v1/gateway/payments/{payment_token}
Check the latest status of any transaction programmatically using its payment_token.
curl -X GET https://gopay.com.pk/api/v1/gateway/payments/pay_9f8e7d6c5b4a3210... \ -H "Authorization: Bearer sk_live_YOUR_SECRET_KEY" \ -H "Accept: application/json"
{
"success": true,
"order_id": "ORD-98421",
"payment_token": "pay_9f8e7d6c5b4a3210...",
"amount": 1500.00,
"fee_amount": 30.00,
"net_amount": 1470.00,
"currency": "PKR",
"web_user": "hamza_akram",
"status": "paid",
"payment_method": "gopay_wallet",
"paid_at": "2026-11-02T14:15:30Z"
}
Check User Existence & Status API
POST https://gopay.com.pk/api/v1/gateway/check-userVerify whether a customer is registered and verified on GoPay before rendering 1-click checkout buttons. Query by phone number, email, or username. Customer financial balances are strictly never disclosed.
curl -X POST https://gopay.com.pk/api/v1/gateway/check-user \
-H "Authorization: Bearer sk_live_YOUR_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"phone": "03001234567"
}'
{
"success": true,
"exists": true,
"user": {
"name": "Hamza Ali",
"username": "hamza_ali",
"phone": "0300****567",
"email": "h***@example.com",
"status": "active",
"is_active": true,
"is_verified": true,
"joined_at": "2026-04-12T10:00:00Z"
}
}
Send Payment to User Wallet (Pay to User API)
POST https://gopay.com.pk/api/v1/gateway/pay-to-userAutomate payouts, affiliate commissions, instant prize disbursements, or customer refunds directly from your Merchant Balance into any user's GoPay wallet.
Under GoPay's financial rails, normal user-to-user transfers are non-withdrawable. However, funds disbursed directly from a verified Merchant account are credited into the user's Main Balance and are fully withdrawable by the recipient via EasyPaisa, JazzCash, or Pakistani Bank Accounts.
Pay to User Parameters
| Parameter | Type | Requirement | Description |
|---|---|---|---|
| recipient | string | Required | Customer's phone number (03001234567), email address, or username. |
| amount | numeric | Required | Payout amount in PKR (minimum: 1.00). |
| reference_id | string | Optional | Your internal payout reference ID (e.g. PAYOUT-REF-9921). |
| note | string | Optional | Memo displayed on customer transaction ledger statement. |
curl -X POST https://gopay.com.pk/api/v1/gateway/pay-to-user \
-H "Authorization: Bearer sk_live_YOUR_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"recipient": "03001234567",
"amount": 2500.00,
"reference_id": "PAYOUT-REF-9921",
"note": "Affiliate Commission Settlement"
}'
{
"success": true,
"trx_id": "MPAY_A9F32BC17DE4",
"amount": 2500.00,
"currency": "PKR",
"recipient": {
"name": "Hamza Ali",
"username": "hamza_ali",
"phone": "0300****567"
},
"merchant_remaining_balance": 7500.00,
"status": "completed",
"message": "Funds successfully paid to user. User can withdraw these funds."
}
Account Link & Direct Payments
OAuth-Style Authorization, Direct MPIN Deposits & Instant WithdrawalsAccount Linking allows approved partner websites (e-commerce platforms, games, or apps) to establish a persistent, authorized connection with a customer's GoPay wallet. Once linked, customers enjoy seamless financial interactions:
Users purchase or deposit on your platform simply by typing their 6-digit MPIN. No redirect to checkout pages or QR code scanning required.
If your merchant account enables withdrawals, you can disburse cashouts or refunds straight into the user's withdrawable GoPay balance instantly.
/v1/gateway/account-link/initiate
Call this endpoint from your backend to generate a temporary 30-minute linking session and receive an authorize_url to redirect your customer to.
| Field | Type | Status | Description |
|---|---|---|---|
| client_user_id | string | Optional | Your platform's unique customer ID or username (e.g. player_9921). |
| callback_url | url | Recommended | The URL where GoPay redirects the customer after they authorize or decline the request. |
| scopes | array | Optional | Array of permissions requested. Defaults to ["deposit", "withdraw"] (filtered by your API key's approved scope). |
| webhook_url | url | Optional | Custom webhook endpoint to receive account_link.authorized and account_link.revoked events. |
curl -X POST https://gopay.com.pk/api/v1/gateway/account-link/initiate \
-H "Authorization: Bearer sk_live_your_secret_key" \
-H "Content-Type: application/json" \
-d '{
"client_user_id": "player_8829",
"callback_url": "https://yourwebsite.com/gopay/callback",
"scopes": ["deposit", "withdraw"]
}'
{
"success": true,
"session_token": "als_8f9e0a1b2c3d4e5f60718293a4b5c6d7e8f9a0b1c2d3e4f5",
"authorize_url": "https://gopay.com.pk/account-link/als_8f9e0a1b2c3d4e5f60718293a4b5c6d7e8f9a0b1c2d3e4f5",
"scopes": ["deposit", "withdraw"],
"client_user_id": "player_8829",
"status": "pending",
"expires_at": "2026-11-17T16:00:00.000000Z"
}
User Panel Authorization Screen
Redirect your customer's browser to the authorize_url. The customer is presented with the GoPay authorization screen:
- Customer reviews your verified website name, URL, and the requested permissions (Direct Deposit & Direct Withdrawal).
- Customer authenticates and inputs their 6-digit Security MPIN.
- Upon confirmation, GoPay stores the link and redirects back to your
callback_urlwith query parameters:
Store the link_token securely in your database associated with this customer. You will use this token for subsequent direct deposits and withdrawals.
/v1/gateway/linked-account/deposit
When the user initiates a deposit or purchase on your website, prompt them to enter their 6-digit MPIN and call this endpoint. GoPay validates the MPIN, performs an atomic wallet deduction, credits your merchant balance, and returns an instant receipt.
| Field | Type | Status | Description |
|---|---|---|---|
| link_token | string | Required | The customer's active link_token (gplink_...). |
| amount | numeric | Required | Transaction amount in PKR (minimum: 1.00). |
| mpin | string | Required | Customer's 6-digit Security MPIN entered on your site. |
| order_id | string | Optional | Your internal unique order ID for idempotency and tracking. |
| wallet_type | string | Optional | Funding wallet: split (default: Deposit wallet first, then Main), deposit, or withdrawable. |
curl -X POST https://gopay.com.pk/api/v1/gateway/linked-account/deposit \
-H "Authorization: Bearer sk_live_your_secret_key" \
-H "Content-Type: application/json" \
-d '{
"link_token": "gplink_99a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6",
"amount": 1000.00,
"mpin": "123456",
"order_id": "ORD-GAME-4402",
"note": "Coins Top-Up"
}'
{
"success": true,
"trx_id": "GP_LINK_7A9B3C2D1E4F",
"order_id": "ORD-GAME-4402",
"amount": 1000.00,
"fee_amount": 20.00,
"net_amount": 980.00,
"currency": "PKR",
"status": "completed",
"payment_method": "linked_account",
"customer": {
"name": "Kamran Ali",
"phone": "0300****567"
},
"created_at": "2026-11-17T15:45:00.000000Z",
"message": "Direct deposit from linked account completed successfully via PIN verification."
}
/v1/gateway/linked-account/withdraw
Pay out funds (cashouts, winnings, commissions) directly into the customer's GoPay account from your available merchant balance. Funds land in the customer's Main Balance and are withdrawable.
curl -X POST https://gopay.com.pk/api/v1/gateway/linked-account/withdraw \
-H "Authorization: Bearer sk_live_your_secret_key" \
-H "Content-Type: application/json" \
-d '{
"link_token": "gplink_99a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6",
"amount": 2500.00,
"reference_id": "WD-TOURNEY-8891",
"note": "Tournament Winner Prize"
}'
{
"success": true,
"trx_id": "MPAY_3E4F5A6B7C8D",
"amount": 2500.00,
"currency": "PKR",
"reference_id": "WD-TOURNEY-8891",
"recipient": {
"name": "Kamran Ali",
"phone": "0300****567"
},
"merchant_remaining_balance": 12500.00,
"status": "completed",
"message": "Funds successfully withdrawn to user GoPay account. User can withdraw or transfer these funds."
}
/v1/gateway/linked-account/{link_token}
Inspect active permissions, linkage timestamps, and verification status. In adherence with our banking-grade privacy policy, customer balance figures are strictly hidden. Pass ?check_amount=1000 to verify whether the customer can fund a purchase without disclosing their exact balance.
curl -X GET "https://gopay.com.pk/api/v1/gateway/linked-account/gplink_99a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6?check_amount=1000" \ -H "Authorization: Bearer sk_live_your_secret_key"
{
"success": true,
"link_token": "gplink_99a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6",
"status": "active",
"is_active": true,
"allow_deposit": true,
"allow_withdraw": true,
"has_sufficient_balance": true,
"customer": {
"name": "Kamran Ali",
"phone": "0300****567",
"email": "k***@example.com",
"is_active": true
},
"linked_at": "2026-11-17T15:30:00.000000Z",
"last_used_at": "2026-11-17T15:45:00.000000Z"
}
/v1/gateway/linked-account/revoke
If a user requests unlinking inside your app's account settings, call this endpoint with their link_token to immediately terminate the link.
curl -X POST https://gopay.com.pk/api/v1/gateway/linked-account/revoke \
-H "Authorization: Bearer sk_live_your_secret_key" \
-H "Content-Type: application/json" \
-d '{
"link_token": "gplink_99a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6"
}'
{
"success": true,
"status": "revoked",
"message": "Linked account access has been revoked successfully."
}
Standard HTTP Status Codes
RFC 7231 Compliant| Code | Status | Meaning & Solution |
|---|---|---|
| 200 / 201 | OK / Created | The request was successfully processed and the resource created. |
| 401 | Unauthorized | Missing or invalid Secret Key header, or website application has not yet been approved. |
| 403 | Forbidden | Insufficient operational scope — e.g. calling /payments with a Withdrawal-only key or calling /pay-to-user with a Deposit-only key. |
| 404 | Not Found | Recipient customer or payment token could not be found in the network. |
| 409 | Conflict | Order ID has already been finalized or paid (strict idempotency lock). |
| 422 | Unprocessable Entity | Validation failure (missing required parameters or insufficient merchant balance). |
Ready to integrate GoPay into your business?
Follow this 4-step checklist to go live with payment processing.
Sign up in seconds with your store details and business email.
Submit your domain in the portal for standard compliance verification.
Retrieve your private Secret Key and Webhook Signing Secret.
Deploy checkout and receive real-time settlements into your wallet.