const axios = require('axios');
const BKASH_API_URL = 'https://api.bkash.com/v1.2.0/payment/request'; const CLIENT_ID = 'your_client_id'; const CLIENT_SECRET = 'your_client_secret';
// Request to generate a token async function getAuthToken() { try { const response = await axios.post('https://api.bkash.com/v1.2.0/oauth/token', { client_id: CLIENT_ID, client_secret: CLIENT_SECRET, grant_type: 'client_credentials', }); return response.data.access_token; } catch (error) { console.error('Error fetching auth token:', error); } }
// Payment request async function createPayment(amount, phoneNumber) { const token = await getAuthToken();
try {
const paymentResponse = await axios.post(BKASH_API_URL, {
amount: amount,
phone_number: phoneNumber,
// other payment details
}, {
headers: {
'Authorization': Bearer ${token}
,
'Content-Type': 'application/json',
},
});
console.log('Payment successful:', paymentResponse.data);
} catch (error) { console.error('Error making payment:', error); } }
createPayment(100, '01701499509');