1const axios = require('axios');
2
3const API_BASE = 'https://coinpay.ir/api/v1';
4const API_TOKEN = 'YOUR_MERCHANT_API_TOKEN';
5
6async function createPayment(amount, clientRefId, options = {}) {
7 try {
8 const response = await axios.post(`${API_BASE}/coin-pay/payment`, {
9 amount: amount,
10 client_ref_id: clientRefId,
11 payer_identity: options.payerIdentity,
12 name: options.name,
13 description: options.description,
14 national_code: options.nationalCode,
15 redirect_url: options.redirectUrl,
16 webhook_callback: options.webhookCallback,
17 }, {
18 headers: {
19 'Content-Type': 'application/json',
20 'Authorization': `Bearer ${API_TOKEN}`,
21 },
22 });
23
24 return response.data;
25 } catch (error) {
26 return { status: false, error: error.response?.data || error.message };
27 }
28}
29
30async function checkPayment(transactionId) {
31 try {
32 const response = await axios.get(`${API_BASE}/coin-pay`, {
33 params: { transaction_id: transactionId },
34 headers: {
35 'Content-Type': 'application/json',
36 'Authorization': `Bearer ${API_TOKEN}`,
37 },
38 });
39
40 return response.data;
41 } catch (error) {
42 return { status: false, error: error.response?.data || error.message };
43 }
44}
45
46module.exports = { createPayment, checkPayment };