The following examples demonstrate how to integrate with the FundPay API for common operations. Each example is available in multiple programming languages to help you integrate quickly with your preferred technology stack.
All examples include proper signature generation and authentication as required by the API.
This example shows how to create a new deposit with Promptpay payment method.
// Example for creating a deposit with Promptpay
const crypto = require('crypto');
const axios = require('axios');
// Your merchant credentials
const merchantId = 'MERCHANT_DEV_20250522_ABCDEFGHIJKLMN';
const apiKey = 'YOUR_API_KEY'; // x-api-key header value
const secretKey = 'YOUR_MERCHANT_SECRET_KEY'; // For signature generation
// Prepare deposit data
const depositData = {
merchant_id: merchantId,
amount: 1000,
currency: 'THB',
reference: 'ORD' + Math.floor(1000000 + Math.random() * 9000000),
payment_method: 'promptpay',
frontend_return_url: 'https://example.com/return',
backend_return_url: 'https://example.com/webhook',
timestamp: new Date().toISOString()
};
// Generate signature
function generateSignature(data, secretKey) {
const sortedKeys = Object.keys(data).sort();
const values = {};
for (const key of sortedKeys) {
values[key] = String(data[key]);
}
const queryString = new URLSearchParams(values).toString();
const hmac = crypto.createHmac('sha256', secretKey);
hmac.update(queryString);
return hmac.digest('hex');
}
// Add signature to request data
depositData.signature = generateSignature(depositData, secretKey);
// Make API request
async function createDeposit() {
try {
const response = await axios.post(
'https://api-dev.fundpay.app/api/v1/deposit',
depositData,
{
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey
}
}
);
console.log('Deposit created:', response.data);
// Redirect user to payment page if successful
if (response.data.code === 200 && response.data.data.payment_url) {
window.location.href = response.data.data.payment_url;
}
} catch (error) {
console.error('Error creating deposit:', error.response?.data || error.message);
}
}
createDeposit();
These examples are for demonstration purposes only. In production environments: