๐ What You Need
From your app: Amount, Order ID, API Key, API Secret
From RMA: Everything else is handled automatically!
From RMA: Everything else is handled automatically!
The API automatically gets beneficiary ID, bank code, currency, and all other settings from your client configuration. You just need to provide the payment details!
๐งช Test the API
Response will appear here...
๐ป Integration Examples
JavaScript/Fetch
const createPayment = async (paymentData) => { try { const response = await fetch('http://127.0.0.1:8000/api/payment/create', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify({ api_key: 'your_api_key_here', api_secret: 'your_api_secret_here', amount: 100.00, order_id: 'ORDER-2024-001', customer_email: 'customer@example.com', // optional description: 'Payment description' // optional }) }); const result = await response.json(); if (result.success) { // Payment created successfully console.log('Transaction ID:', result.data.transaction_id); console.log('Payment URL:', result.data.payment_url); // Redirect customer to payment URL window.location.href = result.data.payment_url; } else { console.error('Payment failed:', result.message); } } catch (error) { console.error('Error:', error); } };
PHP/cURL
<?php function createPayment($apiKey, $apiSecret, $amount, $orderId, $customerEmail = null, $description = null) { $url = 'http://127.0.0.1:8000/api/payment/create'; $data = [ 'api_key' => $apiKey, 'api_secret' => $apiSecret, 'amount' => $amount, 'order_id' => $orderId ]; if ($customerEmail) $data['customer_email'] = $customerEmail; if ($description) $data['description'] = $description; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Accept: application/json' ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $result = json_decode($response, true); if ($httpCode === 200 && $result['success']) { // Payment created successfully echo "Transaction ID: " . $result['data']['transaction_id'] . "\n"; echo "Payment URL: " . $result['data']['payment_url'] . "\n"; // Redirect customer to payment URL header('Location: ' . $result['data']['payment_url']); exit; } else { echo "Payment failed: " . $result['message'] . "\n"; } } // Usage createPayment( 'your_api_key_here', 'your_api_secret_here', 100.00, 'ORDER-2024-001', 'customer@example.com', 'Payment description' ); ?>
Python/Requests
import requests import json def create_payment(api_key, api_secret, amount, order_id, customer_email=None, description=None): url = 'http://127.0.0.1:8000/api/payment/create' data = { 'api_key': api_key, 'api_secret': api_secret, 'amount': amount, 'order_id': order_id } if customer_email: data['customer_email'] = customer_email if description: data['description'] = description headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } try: response = requests.post(url, json=data, headers=headers) result = response.json() if response.status_code == 200 and result['success']: print(f"Transaction ID: {result['data']['transaction_id']}") print(f"Payment URL: {result['data']['payment_url']}") return result['data'] else: print(f"Payment failed: {result['message']}") return None except requests.exceptions.RequestException as e: print(f"Error: {e}") return None # Usage payment = create_payment( 'your_api_key_here', 'your_api_secret_here', 100.00, 'ORDER-2024-001', 'customer@example.com', 'Payment description' )
๐ค Response Format
Success Response
{ "success": true, "message": "Payment created successfully", "data": { "transaction_id": "TXN_1703123456_123", "order_id": "ORDER-2024-001", "amount": 100.00, "currency": "BTN", "payment_url": "http://127.0.0.1:8000/payment/TXN_1703123456_123", "status": "initiated", "beneficiary": "Test Company Ltd", "bank_name": "Bank of Bhutan", "created_at": "2024-12-21T06:30:56.000000Z" } }
Error Response
{ "success": false, "message": "Invalid API credentials", "errors": { "api_key": ["The api key field is required."] } }