-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-payment-link.js
More file actions
79 lines (69 loc) · 2.34 KB
/
Copy pathtest-payment-link.js
File metadata and controls
79 lines (69 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const axios = require('axios');
const baseURL = 'http://localhost:4000/api/v1';
async function createPaymentLink() {
try {
console.log('Creating payment link...');
const response = await axios.post(`${baseURL}/payment-links`, {
merchantId: 'test-merchant-123',
userId: 'test-user-456',
amount: '100.50',
currency: 'USD',
token: 'USDT',
selectedCurrency: 'USD',
paymentType: 'card',
description: 'Test payment link'
});
console.log('Payment link created successfully:');
console.log('ID:', response.data.data.id);
console.log('Link URL:', response.data.data.linkUrl);
console.log('Amount:', response.data.data.amount);
console.log('Currency:', response.data.data.currency);
return response.data.data.id;
} catch (error) {
console.error('Error creating payment link:');
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', error.response.data);
} else {
console.error('Error:', error.message);
}
return null;
}
}
async function accessPaymentLink(id) {
try {
console.log(`\nAccessing payment link ${id}...`);
const response = await axios.post(`${baseURL}/payment-links/${id}/access`, {
payerInfo: {
payername: 'John Doe',
payeraddress: '123 Test Street',
payercity: 'Test City',
payerstate: 'Test State',
payercountry: 'US',
payerphone: '1234567890'
}
});
console.log('Payment link accessed successfully:');
console.log('Response:', JSON.stringify(response.data, null, 2));
} catch (error) {
console.error('Error accessing payment link:');
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', error.response.data);
} else {
console.error('Error:', error.message);
}
}
}
async function main() {
// First create a payment link
const paymentLinkId = await createPaymentLink();
if (paymentLinkId) {
// Then try to access it
await accessPaymentLink(paymentLinkId);
}
// Also try to access the specific ID you mentioned
console.log('\n--- Testing specific ID ---');
await accessPaymentLink('697ecadd88e5e54e39285e80');
}
main().catch(console.error);