SmartPay API Documentation
SmartPay এর Developer Friendly API দিয়ে আপনি খুব সহজেই আপনার ওয়েবসাইটে (যেমন- PHP, Laravel, Node.js) অটোমেটিক পেমেন্ট সিস্টেম যুক্ত করতে পারবেন।
Base URL: https://yourdomain.com (আপনার বর্তমান ডোমেইন)
২. অথেনটিকেশন (Authentication)
API ব্যবহারের জন্য আপনার ২ টি সিক্রেট কি (Keys) প্রয়োজন হবে। আপনি মার্চেন্ট প্যানেলের Developer Settings থেকে এগুলো পাবেন।
- Public Key (api_key): পেমেন্ট ক্রিয়েট করার সময় ব্যবহার করতে হয়।
- Secret Key (secret_key): ট্রানজেকশন ভেরিফাই করার সময় ব্যবহার করতে হয়। (কখনোই ক্লায়েন্ট সাইডে এটি শেয়ার করবেন না!)
৩. Create Payment (Checkout)
কাস্টমারকে পেমেন্ট পেজে রিডাইরেক্ট করার জন্য এই এন্ডপয়েন্ট ব্যবহার করে একটি চেকআউট সেশন তৈরি করুন।
Request Parameters (JSON)
| Parameter | Type | Required | Description |
|---|---|---|---|
| api_key | String | Yes | আপনার পাবলিক এপিআই কি। |
| amount | Float | Yes | পেমেন্ট এমাউন্ট (টাকা)। |
| order_id | String | Yes | আপনার সিস্টেমের ইউনিক অর্ডার আইডি। |
| success_url | String | Yes | পেমেন্ট সফল হলে রিডাইরেক্ট ইউআরএল। |
| cancel_url | String | Yes | পেমেন্ট ফেইল হলে রিডাইরেক্ট ইউআরএল। |
PHP cURL Example
<?php
$payload = [
"api_key" => "YOUR_PUBLIC_API_KEY",
"amount" => 500.00,
"order_id" => "ORD-12345",
"success_url" => "https://yoursite.com/success.php",
"cancel_url" => "https://yoursite.com/cancel.php",
"customer_name"=> "Rahim Uddin",
"customer_email"=> "rahim@gmail.com"
];
$ch = curl_init("https://pay.bkdcl.edu.bd/api/checkout.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
$response = curl_exec($ch);
$result = json_decode($response, true);
if ($result['status'] === 'success') {
// Redirect to payment gateway
header("Location: " . $result['payment_url']);
exit;
} else {
echo "Error: " . $result['message'];
}
?>
৪. Verify Payment
কাস্টমার আপনার success_url এ ফিরে আসার পর, সিকিউরিটির জন্য পেমেন্টটি আসলেই সফল হয়েছে কিনা তা ভেরিফাই করুন।
PHP cURL Example
<?php
// In your success.php page
$order_id = $_GET['order_id'];
$payload = [
"secret_key" => "YOUR_SECRET_KEY",
"order_id" => $order_id
];
$ch = curl_init("https://pay.bkdcl.edu.bd/api/verify.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
$response = curl_exec($ch);
$result = json_decode($response, true);
if ($result['status'] === 'success' && $result['data']['status'] === 'COMPLETED') {
echo "Payment Verified! Amount: " . $result['data']['amount'];
// Update your database to mark order as paid
} else {
echo "Payment verification failed!";
}
?>