GreenPay is a simple and Secure payment automation tool which is designed to use personal account as a payment gateway so that you can accept payments from your customer through your website where you will find a complete overview on how GreenPay works and how you can integrate GreenPay API in your website
API Introduction
Production API v1
GreenPay Merchant Payment API
JSON REST API
Merchant integration-এ চারটা অংশ: Create Payment → customer-কে Hosted Checkout-এ পাঠানো → Verify Payment দিয়ে নিশ্চিত হওয়া → Webhook-এ স্বয়ংক্রিয় খবর পাওয়া। Android device/SMS ingestion API merchant checkout-এর অংশ নয়, তাই এখানে আলাদা রাখা হয়েছে।
Base URLhttps://pay.greenpay.bd
Authentication এবং Domain Security
প্রতিটি request-এ Brand-এর API key API-KEY header-এ পাঠান। (api_key নামে body/query-তেও নেওয়া হয়, তবে header নিরাপদ।) API key শুধু server-side রাখুন — browser/JavaScript-এ কখনো না।
Domain rule:success_url, cancel_url এবং (থাকলে) webhook_url-এর domain Merchant-এর সক্রিয় approved Brand domain হতে হবে। Server থেকে call করলে source_domain (বা merchant_domain / X-GREENPAY-DOMAIN header) পাঠান; না পাঠালে callback URL-এর domain-ই ধরা হয়। Platform domain: অন্য Merchant-এর Platform domain ব্যবহার করলে domain-মালিকের অনুমোদন (approve) না পাওয়া পর্যন্ত CALLBACK_DOMAIN_NOT_ALLOWED আসবে।
POST
Create Payment
https://pay.greenpay.bd/api/payment/create
নতুন hosted checkout session তৈরি করে। সফল হলে customer-কে payment_url-এ redirect করুন এবং transaction_id নিজের order-এ সংরক্ষণ করুন। Session ১৫ মিনিট valid থাকে।
Field
Required
Type
Rules
amount
Yes
number
0-এর বেশি, সর্বোচ্চ 1,000,000 (টাকা)।
success_url
Yes
URL
Approved domain-এর URL। সফল/অপেক্ষমাণ payment-এ এখানে ফেরে।
cancel_url
Yes
URL
Approved domain-এর URL। বাতিল/ব্যর্থ হলে এখানে ফেরে।
webhook_url
No
URL
Payment-এর খবর server-to-server পাঠানো হয়; approved domain হতে হবে।
source_domain
Recommended
string/URL
যে domain থেকে request (যেমন shop.example.com)। বিকল্প: merchant_domain।
cus_name
No
string
Customer-এর নাম।
cus_email
No
email
Payment সম্পন্ন/reminder ইমেইলের জন্য।
cus_phone
No
string
Customer-এর মোবাইল।
metadata
No
JSON object
Order/product reference। JSON body-তে object হিসেবে পাঠান (string নয়)। Verify ও webhook-এ ফেরত আসে।
Important: Redirect-এর query parameter কেউ হাতে বদলে দিতে পারে। Redirect পাওয়ার পর server থেকে Verify API call করে code = PAYMENT_COMPLETED নিশ্চিত হলে তবেই order confirm করুন। Customer-এর live অবস্থা দেখাতে create response-এর status_url ব্যবহার করা যায়।
POST
Verify Payment
https://pay.greenpay.bd/api/payment/verify
transaction_id দিয়ে payment-এর বর্তমান অবস্থা জানায়। একই Brand-এর (বা একই Merchant-এর) API key দিয়ে পাঠান। transaction পাওয়া গেলে প্রতিটা response-এ একই key-গুলো থাকে; payment সম্পন্ন না হলে বাড়তি তথ্যের মান null।
{
"success": false,
"status": "VERIFICATION_LOCKED",
"code": "VERIFICATION_ATTEMPTS_EXCEEDED",
"message": "আপনার 3টি payment verification attempt শেষ হয়েছে। নিরাপত্তার কারণে এই checkout সাময়িকভাবে ব্লক করা হয়েছে। …",
"data": {
"can_retry": false,
"count_attempt": false,
"reason": null,
"unlock_at": "2026-10-16 19:30:00",
"seconds_until_unlock": 7200
},
"transaction_id": "GP7QKEK1003399"
}
metadata: Verify response-এ metadata একটা JSON string হিসেবে আসে — json_decode($res['metadata'], true) করে ব্যবহার করুন। এতে আপনার পাঠানো মানের সাথে source_domain, api_brand_id, request_source যোগ থাকে।
Payment মেলানোর বাড়তি তথ্য
Key
মানে
method_trx_id
bKash/Nagad/Rocket-এর আসল TrxID। শুধু COMPLETED হলে থাকে, নইলে null।
Merchant decision, terminal lifecycle অথবা verification lock।
Important:status এবং code দুটোই দেখুন। Completed ছাড়া terminal state — Rejected, Cancelled ও Refunded — আর কখনো success হবে না।
Webhook
webhook_url দিলে GreenPay দুইভাবে খবর পাঠায়। দুটোই একই webhook_url-এ আসে, তাই endpoint দুটো format-ই গ্রহণ করবে, দ্রুত HTTP 2xx ফেরত দেবে, এবং একই খবর একাধিকবার এলেও একবারই কাজ করবে (idempotent)।
১) তাৎক্ষণিক checkout খবর — form POST
Customer checkout শেষ করা মাত্র একবার পাঠানো হয় (application/x-www-form-urlencoded), redirect-এর মতোই field:
Payment সম্পন্ন, review, reject, cancel, refund ইত্যাদি প্রতিটা ঘটনায় JSON পাঠানো হয়। ব্যর্থ হলে (2xx না পেলে বা ১৫ সেকেন্ডে উত্তর না এলে) ১, ২, ৪, ৮… মিনিট পরপর আবার চেষ্টা হয়, সর্বোচ্চ ৪৮ ঘণ্টা।
$data = json_decode(file_get_contents('php://input'), true);
if (!is_array($data)) {
$data = $_POST; // তাৎক্ষণিক form POST
}
$trx = $data['transaction_id'] ?? $data['transactionId'] ?? '';
http_response_code(200); // আগে 2xx দিন
if ($trx !== '') {
// webhook-এর মানে ভরসা না করে Verify API দিয়ে নিশ্চিত হোন
$res = greenpay_verify($trx); // উপরের Verify request
if (($res['code'] ?? '') === 'PAYMENT_COMPLETED') {
mark_order_paid($trx, $res['method_trx_id'] ?? null); // আগেই paid হলে কিছু করবেন না
}
}
Production Integration Checklist
Brand ও Merchant package সক্রিয় রাখুন; API key server-side environment variable-এ রাখুন।
Brand domain approved রাখুন; success/cancel/webhook URL একই approved domain-এর হবে।
Create response থেকে payment_url-এ redirect করুন এবং transaction_id order-এ সংরক্ষণ করুন।
Redirect-কে একা payment প্রমাণ ধরবেন না; Verify API বা webhook → Verify দিয়ে PAYMENT_COMPLETED নিশ্চিত করুন।
Webhook duplicate হতে পারে; transaction_id + code দিয়ে একবারই কাজ করুন।
হিসাব মেলাতে method_trx_id (bKash/Nagad TrxID) ও paid_to_number সংরক্ষণ করুন।
Error response-এর data.can_retry অনুসরণ করুন; false হলে একই request আবার পাঠাবেন না।
Integration
You can integrate our payment gateway into your PHP Laravel WordPress WooCommerce sites.
Payment Link (where customers will complete their payment)
Error Response
status
bool
FALSE
message
String
Message associated with the error response
Completing Payment Page task you will be redirected to success or cancel page based on transaction status with the following Query Parameters: yourdomain.com/(success/cancel)?transactionId=******&paymentMethod=***&paymentAmount=**.**&paymentFee=**.**&status=pending or success or failed