API Reference
Complete API documentation for Moneybag payment integration
API Reference
Welcome to the Moneybag API documentation. Our RESTful API provides a simple and secure way to integrate payment processing into your application.
Base URLs
All API requests should be made to one of the following base URLs:
- Sandbox Environment:
https://sandbox.api.moneybag.com.bd/api/v2
- Production Environment:
https://api.moneybag.com.bd/api/v2
Start with Sandbox
Always test your integration in the sandbox environment before going live. The sandbox provides test credentials and simulated responses.
Redirect URLs and Transaction Status
After a transaction is completed, Moneybag redirects the customer to one of the merchant's specified URLs based on the transaction outcome. Moneybag appends query parameters to these URLs with the transaction details.
Redirect URL Format
https://yourdomain.com/payment/{status}?transaction_id={transaction_id}&status={STATUS}
Example redirect URLs:
# Successful payment
https://example.com/payment/success?transaction_id=txn691765dba92741829f72de6eacec8a76&status=SUCCESS
# Failed payment
https://example.com/payment/fail?transaction_id=txn691765dba92741829f72de6eacec8a76&status=FAILED
# Cancelled payment
https://example.com/payment/cancel?transaction_id=txn691765dba92741829f72de6eacec8a76&status=CANCELLED
Redirect URL Types
Redirect URL | Transaction Status | Description |
---|---|---|
success_url | SUCCESS | Customer is redirected here when payment is completed successfully |
fail_url | FAILED | Customer is redirected here when payment fails (e.g., insufficient funds, declined card) |
cancel_url | CANCELLED | Customer is redirected here when they manually cancel the payment process |
Query Parameters
Moneybag appends the following query parameters to your redirect URLs:
Parameter | Type | Description |
---|---|---|
transaction_id | string | Unique transaction identifier (e.g., txn691765dba92741829f72de6eacec8a76 ) |
status | string | Transaction status (SUCCESS , FAILED , or CANCELLED ) |
Important Security Notes
• These URLs must be provided in the initial checkout request
• Always verify the actual payment status using the /payments/verify/{transaction_id}
endpoint after receiving the redirect
• Do not rely solely on the redirect for payment confirmation - server-side verification is essential for security
• Use the transaction_id
from the query parameters to verify the payment status through the verify API
Authentication
All API requests require authentication using your merchant API key:
X-Merchant-API-Key: your_api_key_here
Learn more about Authentication →
Available Endpoints
Checkout API
Create payment sessions and generate checkout URLs for customers
/payments/checkout
View Documentation →
Verify API
Check payment status and verify transaction details
/payments/verify/{id}
View Documentation →
Integration Flow
Understanding the complete payment flow helps you implement a robust integration:
Key Steps
- Create Checkout Session - Initialize payment with customer and order details
- Redirect Customer - Send customer to Moneybag's secure payment page
- Process Payment - Customer completes payment with their preferred method
- Receive Notification - Get real-time webhook for payment status
- Verify Payment - Confirm payment details before fulfilling order
- Complete Order - Deliver goods/services after successful verification
API Playground
Test our API endpoints interactively with real responses:
The playground allows you to:
- Test endpoints with your sandbox credentials
- See real-time request and response data
- Export code snippets in multiple languages
- Debug integration issues quickly
Request & Response Format
Request Headers
All API requests should include these headers:
X-Merchant-API-Key: your_api_key
Content-Type: application/json
Accept: application/json
Response Format
All responses follow a consistent JSON structure:
Success Response
{
"success": true,
"message": "Operation completed successfully",
"data": {
// Response data specific to the endpoint
}
}
Error Response
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error message",
"field": "field_name" // Optional, for validation errors
}
}
HTTP Status Codes
Status Code | Description |
---|---|
200 | Success - Request completed successfully |
201 | Created - Resource created successfully |
400 | Bad Request - Invalid request parameters |
401 | Unauthorized - Invalid or missing API key |
403 | Forbidden - Access denied |
404 | Not Found - Resource not found |
422 | Unprocessable Entity - Validation errors |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Server Error - Server error |
503 | Service Unavailable - Temporary unavailability |
Rate Limiting
To ensure fair usage and system stability:
- Sandbox: 100 requests per minute
- Production: 60 requests per minute
Rate limit headers in responses:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1640995200
Handling Rate Limits
async function makeAPICall(data, retries = 3) {
try {
const response = await callAPI(data);
return response;
} catch (error) {
if (error.status === 429 && retries > 0) {
const resetTime = error.headers['X-RateLimit-Reset'];
const waitTime = resetTime - Date.now() / 1000;
await sleep(waitTime * 1000);
return makeAPICall(data, retries - 1);
}
throw error;
}
}
Security Best Practices
API Key Security
- Store keys in environment variables
- Never expose keys in client-side code
- Rotate keys regularly
- Use different keys for different environments
Data Protection
- Always use HTTPS
- Implement webhook signature verification
- Validate all input data
- Log security events
PCI Compliance
- Never store card details
- Use tokenization when possible
- Follow PCI DSS guidelines
- Regular security audits
Error Handling
Implement robust error handling for all API calls:
try {
const response = await moneybagAPI.createCheckout(data);
// Handle success
} catch (error) {
if (error.code === 'INVALID_AMOUNT') {
// Handle specific error
} else if (error.code === 'RATE_LIMIT_EXCEEDED') {
// Implement retry logic
} else {
// Handle generic error
console.error('API Error:', error.message);
}
}
View all Error Codes →
Testing
Sandbox Environment
Use our sandbox for safe testing:
- Test card numbers for different scenarios
- Mobile banking test accounts
- Webhook testing tools
- No real money processed
Learn more about Sandbox Testing →
Test Data
Test Card | Result |
---|---|
4111 1111 1111 1111 | Success |
4000 0000 0000 0002 | Declined |
4000 0000 0000 3220 | 3D Secure |
Support Resources
Next Steps
Ready to start integrating? Here's what to do: