Moneybag

Checkout API

Create payment sessions for customer orders

Checkout API

The Checkout endpoint initiates a payment session for a customer order and returns a checkout URL where the customer can complete the payment.


Endpoint Details

Endpoint: POST /payments/checkout

Base URLs:

  • Sandbox: https://sandbox.api.moneybag.com.bd/api/v2
  • Production: https://api.moneybag.com.bd/api/v2

Authentication

All requests require authentication via API key in the header:

X-Merchant-API-Key: <your_merchant_api_key>

Request

Headers

HeaderValueRequired
X-Merchant-API-KeyYour merchant API keyYes
Content-Typeapplication/jsonYes

Request Body

{
  "order_id": "order123321",
  "currency": "BDT",
  "order_amount": "1280.00",
  "order_description": "Online purchase of electronics",
  "success_url": "https://yourdomain.com/payment/success",
  "cancel_url": "https://yourdomain.com/payment/cancel",
  "fail_url": "https://yourdomain.com/payment/fail",
  "ipn_url": "https://yourdomain.com/payment/ipn",
  "customer": {
    "name": "John Doe",
    "email": "john.doe@example.com",
    "address": "123 Main Street",
    "city": "Dhaka",
    "postcode": "1000",
    "country": "Bangladesh",
    "phone": "+8801700000000"
  },
  "order_items": [
    {
      "sku": "PROD001",
      "net_amount": "1300.00"
    }
  ],
  "shipping": {
    "name": "John Doe",
    "address": "123 Main Street",
    "city": "Dhaka",
    "postcode": "1000",
    "country": "Bangladesh"
  },
  "metadata": {
    "source": "web",
    "session_id": "SESSION12345",
    "user_agent": "Mozilla/5.0",
    "ip_address": "192.168.1.1",
    "platform": "web"
  },
  "payment_info": {
    "is_recurring": false,
    "installments": 0,
    "currency_conversion": false,
    "allowed_payment_methods": ["card", "mobile_banking"],
    "requires_emi": false
  }
}

Request Parameters

Root Level Fields

FieldTypeRequiredDescriptionConstraints
order_idstringYesUnique transaction ID to identify your orderMax 30 chars
currencystringYesThree-letter currency codeMust match ^[A-Z]{3}$
order_amountdecimalYesTransaction amountBetween 10.00 and 500000.00 BDT
order_descriptionstringNoDescription of the order
success_urlstringYesCallback URL after successful paymentMax 255 chars, must be HTTPS
cancel_urlstringYesCallback URL if user cancelsMax 255 chars, must be HTTPS
fail_urlstringYesCallback URL if payment failsMax 255 chars, must be HTTPS
ipn_urlstringNoInstant Payment Notification URLMust be HTTPS
customerobjectYesCustomer informationSee Customer Object
shippingobjectNoShipping informationSee Shipping Object
order_itemsarrayNoList of items in the orderSee OrderItem Object
payment_infoobjectNoPayment-related informationSee PaymentInfo Object
metadataobjectNoAdditional order-specific data

Customer Object

FieldTypeRequiredDescription
namestringYesCustomer full name
emailstringYesCustomer email address
addressstringYesCustomer address
citystringYesCustomer city
postcodestringYesCustomer postal code
countrystringYesCustomer country
phonestringYesCustomer phone number

Shipping Object

FieldTypeRequiredDescription
namestringYesRecipient's full name
addressstringYesShipping address
citystringYesShipping city
statestringNoShipping state/province
postcodestringYesShipping postal code
countrystringYesShipping country
metadataobjectNoAdditional shipping data

OrderItem Object

FieldTypeRequiredDescription
skustringNoProduct SKU
product_namestringNoProduct name
product_categorystringNoProduct category
quantityintegerNoProduct quantity
unit_pricedecimalNoUnit price of the product
vatdecimalNoVAT amount
convenience_feedecimalNoConvenience fee
discount_amountdecimalNoDiscount amount
net_amountdecimalNoNet amount after calculations
metadataobjectNoAdditional product data

PaymentInfo Object

FieldTypeRequiredDescription
is_recurringbooleanNoWhether this is a recurring payment
installmentsintegerNoNumber of installments if applicable
currency_conversionbooleanNoWhether currency conversion is applied
allowed_payment_methodsarrayYesList of allowed payment methods
requires_emibooleanNoWhether EMI is required

Response

Success Response

HTTP Status: 200 OK

{
  "success": true,
  "data": {
    "checkout_url": "https://payment.moneybag.com.bd/moneybag-landing?sessionId=ps1234567890",
    "session_id": "ps1234567890",
    "expires_at": "2025-05-19T15:00:00Z"
  },
  "message": "Checkout session created"
}

Response Fields

FieldTypeDescription
checkout_urlstringURL to redirect customer for payment
session_idstringUnique session ID for the payment
expires_atdatetimeExpiry date/time of the session (ISO format)

Error Response

HTTP Status: 400/401/403/500

{
  "success": false,
  "error": {
    "code": "INVALID_REQUEST",
    "message": "The order_amount must be between 10.00 and 500000.00",
    "field": "order_amount"
  }
}

Code Examples

cURL

curl -X POST \
  "https://sandbox.api.moneybag.com.bd/api/v2/payments/checkout" \
  -H "Content-Type: application/json" \
  -H "X-Merchant-API-Key: <your_merchant_api_key>" \
  -d '{
    "order_id": "order123321",
    "currency": "BDT",
    "order_amount": "1280.00",
    "order_description": "Online purchase of electronics",
    "success_url": "https://yourdomain.com/payment/success",
    "cancel_url": "https://yourdomain.com/payment/cancel",
    "fail_url": "https://yourdomain.com/payment/fail",
    "customer": {
      "name": "John Doe",
      "email": "john.doe@example.com",
      "phone": "+8801700000000"
    }
  }'

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: 'order123321',
        currency: 'BDT',
        order_amount: '1280.00',
        order_description: 'Online purchase of electronics',
        success_url: 'https://yourdomain.com/payment/success',
        cancel_url: 'https://yourdomain.com/payment/cancel',
        fail_url: 'https://yourdomain.com/payment/fail',
        customer: {
          name: 'John Doe',
          email: 'john.doe@example.com',
          phone: '+8801700000000'
        }
      },
      {
        headers: {
          'X-Merchant-API-Key': 'your_merchant_api_key',
          'Content-Type': 'application/json'
        }
      }
    );
    
    console.log('Checkout URL:', response.data.data.checkout_url);
    // Redirect customer to checkout_url
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

Python

import requests

def create_checkout():
    url = 'https://sandbox.api.moneybag.com.bd/api/v2/payments/checkout'
    
    headers = {
        'X-Merchant-API-Key': 'your_merchant_api_key',
        'Content-Type': 'application/json'
    }
    
    data = {
        'order_id': 'order123321',
        'currency': 'BDT',
        'order_amount': '1280.00',
        'order_description': 'Online purchase of electronics',
        'success_url': 'https://yourdomain.com/payment/success',
        'cancel_url': 'https://yourdomain.com/payment/cancel',
        'fail_url': 'https://yourdomain.com/payment/fail',
        'customer': {
            'name': 'John Doe',
            'email': 'john.doe@example.com',
            'phone': '+8801700000000'
        }
    }
    
    response = requests.post(url, headers=headers, json=data)
    result = response.json()
    
    if result['success']:
        print(f"Checkout URL: {result['data']['checkout_url']}")
        # Redirect customer to checkout_url
    else:
        print(f"Error: {result['error']['message']}")

PHP

<?php
$curl = curl_init();

$data = [
    'order_id' => 'order123321',
    'currency' => 'BDT',
    'order_amount' => '1280.00',
    'order_description' => 'Online purchase of electronics',
    'success_url' => 'https://yourdomain.com/payment/success',
    'cancel_url' => 'https://yourdomain.com/payment/cancel',
    'fail_url' => 'https://yourdomain.com/payment/fail',
    'customer' => [
        'name' => 'John Doe',
        'email' => 'john.doe@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_merchant_api_key',
        'Content-Type: application/json'
    ]
]);

$response = curl_exec($curl);
$result = json_decode($response, true);

if ($result['success']) {
    // Redirect to checkout URL
    header('Location: ' . $result['data']['checkout_url']);
    exit;
}
?>

Try in Playground


Integration Flow

  1. Collect Order Details: Gather order and customer information on your site
  2. Call Checkout API: Send POST request with required data
  3. Get Payment URL: Receive checkout_url in response
  4. Redirect Customer: Send customer to checkout_url
  5. Handle Callback: Process success/fail/cancel callbacks
  6. Verify Payment: Use Verify API to confirm payment

Testing

Use our Sandbox Environment to test your integration:

  • Test cards for different scenarios
  • Mobile banking test accounts
  • Amount-based testing triggers
  • Webhook testing tools

Common Issues

Invalid Amount Error

  • Ensure amount is between 10.00 and 500000.00 BDT
  • Use string format with exactly 2 decimal places

Missing Customer Data

  • All customer fields are required
  • Phone must include country code

URL Validation Failed

  • Use HTTPS for all callback URLs
  • Ensure URLs are publicly accessible