Quick Start
Get up and running with Moneybag in 5 minutes
Quick Start
Get your first payment integration working in just 5 minutes with this quick start guide.
Prerequisites
Before you begin, make sure you have:
- A Moneybag sandbox account (Sign up here)
- Your API key from the dashboard
- A development environment with HTTPS support
Step 1: Get Your API Key
- Log into your Sandbox Dashboard
- Navigate to Developer Settings → API Keys
- Copy your sandbox API key
Security Tip
Never expose your API key in client-side code. Always make API calls from your server.
Step 2: Create Your First Checkout
Here's the simplest way to create a payment checkout:
Using cURL
curl -X POST https://sandbox.api.moneybag.com.bd/api/v2/payments/checkout \
-H "X-Merchant-API-Key: YOUR_SANDBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"order_id": "TEST_001",
"order_amount": 100.00,
"currency": "BDT",
"order_description": "Test Payment",
"success_url": "https://yoursite.com/success",
"cancel_url": "https://yoursite.com/cancel",
"fail_url": "https://yoursite.com/fail",
"customer": {
"name": "Test Customer",
"email": "test@example.com",
"phone": "+8801700000000"
}
}'
Using JavaScript (Node.js)
const axios = require('axios');
async function createCheckout() {
try {
const response = await axios.post(
'https://sandbox.api.moneybag.com.bd/api/v2/payments/checkout',
{
order_id: 'TEST_001',
order_amount: 100.00,
currency: 'BDT',
order_description: 'Test Payment',
success_url: 'https://yoursite.com/success',
cancel_url: 'https://yoursite.com/cancel',
fail_url: 'https://yoursite.com/fail',
customer: {
name: 'Test Customer',
email: 'test@example.com',
phone: '+8801700000000'
}
},
{
headers: {
'X-Merchant-API-Key': 'YOUR_SANDBOX_API_KEY',
'Content-Type': 'application/json'
}
}
);
console.log('Payment URL:', response.data.data.payment_url);
// Redirect customer to payment_url
} catch (error) {
console.error('Error:', error.response.data);
}
}
createCheckout();
Using PHP
<?php
$curl = curl_init();
$data = [
'order_id' => 'TEST_001',
'order_amount' => 100.00,
'currency' => 'BDT',
'order_description' => 'Test Payment',
'success_url' => 'https://yoursite.com/success',
'cancel_url' => 'https://yoursite.com/cancel',
'fail_url' => 'https://yoursite.com/fail',
'customer' => [
'name' => 'Test Customer',
'email' => 'test@example.com',
'phone' => '+8801700000000'
]
];
curl_setopt_array($curl, [
CURLOPT_URL => 'https://sandbox.api.moneybag.com.bd/api/v2/payments/checkout',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
'X-Merchant-API-Key: YOUR_SANDBOX_API_KEY',
'Content-Type: application/json'
]
]);
$response = curl_exec($curl);
$result = json_decode($response, true);
if ($result['success']) {
// Redirect to payment URL
header('Location: ' . $result['data']['payment_url']);
exit;
}
?>
Using Python
import requests
import json
def create_checkout():
url = 'https://sandbox.api.moneybag.com.bd/api/v2/payments/checkout'
headers = {
'X-Merchant-API-Key': 'YOUR_SANDBOX_API_KEY',
'Content-Type': 'application/json'
}
data = {
'order_id': 'TEST_001',
'order_amount': 100.00,
'currency': 'BDT',
'order_description': 'Test Payment',
'success_url': 'https://yoursite.com/success',
'cancel_url': 'https://yoursite.com/cancel',
'fail_url': 'https://yoursite.com/fail',
'customer': {
'name': 'Test Customer',
'email': 'test@example.com',
'phone': '+8801700000000'
}
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if result['success']:
print(f"Payment URL: {result['data']['payment_url']}")
# Redirect customer to payment_url
else:
print(f"Error: {result['message']}")
create_checkout()
Step 3: Handle the Response
A successful response will look like this:
{
"success": true,
"message": "Checkout session created successfully",
"data": {
"payment_url": "https://sandbox.pay.moneybag.com.bd/checkout/abc123xyz",
"transaction_id": "TXN_1234567890",
"expires_at": "2024-12-18T11:00:00Z"
}
}
Redirect your customer to the payment_url
to complete the payment.
Step 4: Verify the Payment
After the customer completes the payment, they'll be redirected to your success URL with a transaction ID. Verify the payment status:
curl -X GET "https://sandbox.api.moneybag.com.bd/api/v2/payments/verify/TXN_1234567890" \
-H "X-Merchant-API-Key: YOUR_SANDBOX_API_KEY"
Response:
{
"success": true,
"data": {
"transaction_id": "TXN_1234567890",
"order_id": "TEST_001",
"amount": 100.00,
"currency": "BDT",
"status": "SUCCESS",
"payment_method": "bkash",
"paid_at": "2024-12-18T10:45:30Z"
}
}
Step 5: Test Your Integration
Use these test cards in sandbox:
Card Number | Result |
---|---|
4111 1111 1111 1111 | Success |
4000 0000 0000 0002 | Declined |
4000 0000 0000 3220 | 3D Secure Required |
For mobile banking tests:
- bKash: 01700000001 (PIN: 12345, OTP: 123456)
- Nagad: 01800000001 (PIN: 12345, OTP: 123456)
Complete Integration Example
Here's a minimal Express.js server with Moneybag integration:
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
const MONEYBAG_API_KEY = 'YOUR_SANDBOX_API_KEY';
const MONEYBAG_BASE_URL = 'https://sandbox.api.moneybag.com.bd/api/v2';
// Create payment
app.post('/create-payment', async (req, res) => {
try {
const response = await axios.post(
`${MONEYBAG_BASE_URL}/payments/checkout`,
{
order_id: `ORDER_${Date.now()}`,
order_amount: req.body.amount,
currency: 'BDT',
order_description: 'Purchase',
success_url: 'http://localhost:3000/payment/success',
cancel_url: 'http://localhost:3000/payment/cancel',
fail_url: 'http://localhost:3000/payment/fail',
customer: req.body.customer
},
{
headers: {
'X-Merchant-API-Key': MONEYBAG_API_KEY
}
}
);
res.json({ payment_url: response.data.data.payment_url });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Payment success callback
app.get('/payment/success', async (req, res) => {
const { transaction_id } = req.query;
try {
const response = await axios.get(
`${MONEYBAG_BASE_URL}/payments/verify/${transaction_id}`,
{
headers: {
'X-Merchant-API-Key': MONEYBAG_API_KEY
}
}
);
if (response.data.success && response.data.data.status === 'SUCCESS') {
res.send('Payment successful! Transaction: ' + transaction_id);
} else {
res.send('Payment verification failed');
}
} catch (error) {
res.status(500).send('Error verifying payment');
}
});
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});
What's Next?
Now that you have a basic integration working:
- Set up Authentication - Learn about API authentication and security
- Explore Sandbox Testing - Test different payment scenarios
- Implement Webhooks - Handle real-time payment notifications
- View Full API Reference - Explore all available endpoints
Need Help?
- Check our FAQ
- Read the Troubleshooting Guide
- Contact support@moneybag.com.bd