1const axios = require('axios');
2
3async function requestToken(apiKey, amount, callbackUrl, mobile, email, description) {
4 try {
5 const response = await axios.post('https://sandbox.coinpay.ir/api/v1/token', {
6 api_key: apiKey,
7 amount: amount,
8 callback_url: callbackUrl,
9 mobile: mobile,
10 email: email,
11 description: description,
12 }, {
13 headers: { 'Content-Type': 'application/json' },
14 });
15
16 return response.data;
17 } catch (error) {
18 return { success: false, error: error.response?.data || error.message };
19 }
20}
21
22async function verifyPayment(apiKey, token, amount) {
23 try {
24 const response = await axios.post('https://sandbox.coinpay.ir/api/v1/verify', {
25 api_key: apiKey,
26 token: token,
27 amount: amount,
28 }, {
29 headers: { 'Content-Type': 'application/json' },
30 });
31
32 return response.data;
33 } catch (error) {
34 return { success: false, error: error.response?.data || error.message };
35 }
36}
37
38module.exports = { requestToken, verifyPayment };