quickpos 1.0.910 → 1.0.912

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/PROVIDERS-DETAILS.md +1544 -0
  2. package/examples/example-2checkout.js +78 -0
  3. package/examples/example-bitpay.js +83 -0
  4. package/examples/example-cardcom.js +80 -0
  5. package/examples/example-cashfree.js +109 -0
  6. package/examples/example-checkout.js +85 -0
  7. package/examples/example-coingate.js +101 -0
  8. package/examples/example-coinpayments.js +89 -0
  9. package/examples/example-doku.js +27 -0
  10. package/examples/example-epay.js +64 -0
  11. package/examples/example-epoint.js +91 -0
  12. package/examples/example-freekassa.js +26 -0
  13. package/examples/example-heleket.js +139 -0
  14. package/examples/example-konnect.js +227 -0
  15. package/examples/example-midtrans.js +80 -0
  16. package/examples/example-noonpayments.js +297 -0
  17. package/examples/example-nowpayments.js +289 -0
  18. package/examples/example-omise.js +27 -0
  19. package/examples/example-paycom.js +82 -0
  20. package/{example-paydisini.js → examples/example-paydisini.js} +1 -1
  21. package/examples/example-payid19.js +87 -0
  22. package/examples/example-paykun.js +29 -0
  23. package/examples/example-payme.js +202 -0
  24. package/examples/example-paymentwall.js +201 -0
  25. package/examples/example-paynet.js +104 -0
  26. package/examples/example-paynettr.js +18 -0
  27. package/examples/example-payoneer.js +74 -0
  28. package/examples/example-payop.js +351 -0
  29. package/examples/example-paypal.js +200 -0
  30. package/examples/example-payriff.js +89 -0
  31. package/examples/example-paysend.js +81 -0
  32. package/examples/example-payspace.js +103 -0
  33. package/examples/example-payssion.js +27 -0
  34. package/examples/example-paytabs.js +28 -0
  35. package/examples/example-paytm.js +78 -0
  36. package/examples/example-payuindia.js +108 -0
  37. package/examples/example-payulatam.js +75 -0
  38. package/examples/example-phonepe.js +27 -0
  39. package/examples/example-picpay.js +27 -0
  40. package/examples/example-plisio.js +84 -0
  41. package/examples/example-portwallet.js +90 -0
  42. package/examples/example-primepayments.js +250 -0
  43. package/examples/example-razorpay.js +30 -0
  44. package/examples/example-senangpay.js +28 -0
  45. package/examples/example-shurjopay.js +94 -0
  46. package/examples/example-toyyibpay.js +80 -0
  47. package/examples/example-tripay.js +89 -0
  48. package/examples/example-unitpay.js +26 -0
  49. package/examples/example-urway.js +28 -0
  50. package/examples/example-volet.js +80 -0
  51. package/examples/example-xendit.js +28 -0
  52. package/examples/example-yallapay.js +253 -0
  53. package/examples/example-yookassa.js +27 -0
  54. package/examples/example-youcanpay.js +28 -0
  55. package/examples/example-zarinpal.js +98 -0
  56. package/{example.js → examples/example.js} +1 -1
  57. package/lib/2checkout.js +165 -0
  58. package/lib/amazonpay.js +161 -0
  59. package/lib/bitpay.js +122 -0
  60. package/lib/cardcom.js +193 -0
  61. package/lib/cashfree.js +184 -0
  62. package/lib/checkout.js +248 -0
  63. package/lib/coinbase.js +150 -0
  64. package/lib/coingate.js +137 -0
  65. package/lib/coinpayments.js +245 -0
  66. package/lib/doku.js +173 -0
  67. package/lib/epay.js +175 -0
  68. package/lib/epoint.js +162 -0
  69. package/lib/freekassa.js +128 -0
  70. package/lib/heleket.js +67 -1
  71. package/lib/instamojo.js +158 -0
  72. package/lib/konnect.js +211 -0
  73. package/lib/midtrans.js +227 -0
  74. package/lib/noonpayments.js +650 -0
  75. package/lib/nowpayments.js +311 -0
  76. package/lib/omise.js +150 -0
  77. package/lib/paddle.js +180 -0
  78. package/lib/paycom.js +216 -0
  79. package/lib/payid19.js +211 -0
  80. package/lib/paykun.js +144 -0
  81. package/lib/payme.js +302 -0
  82. package/lib/paymentwall.js +205 -0
  83. package/lib/paynet.js +186 -0
  84. package/lib/paynettr.js +165 -0
  85. package/lib/payoneer.js +128 -0
  86. package/lib/payop.js +256 -0
  87. package/lib/paypal.js +542 -0
  88. package/lib/payriff.js +148 -0
  89. package/lib/paysend.js +189 -0
  90. package/lib/payspace.js +168 -0
  91. package/lib/payssion.js +177 -0
  92. package/lib/paytabs.js +145 -0
  93. package/lib/paytm.js +253 -0
  94. package/lib/payuindia.js +162 -0
  95. package/lib/payulatam.js +179 -0
  96. package/lib/perfectmoney.js +143 -0
  97. package/lib/phonepe.js +174 -0
  98. package/lib/picpay.js +119 -0
  99. package/lib/plisio.js +234 -0
  100. package/lib/portwallet.js +152 -0
  101. package/lib/primepayments.js +256 -0
  102. package/lib/razorpay.js +205 -0
  103. package/lib/senangpay.js +130 -0
  104. package/lib/shurjopay.js +159 -0
  105. package/lib/toyyibpay.js +151 -0
  106. package/lib/tripay.js +220 -0
  107. package/lib/unitpay.js +223 -0
  108. package/lib/urway.js +182 -0
  109. package/lib/volet.js +147 -0
  110. package/lib/xendit.js +206 -0
  111. package/lib/yallapay.js +279 -0
  112. package/lib/yookassa.js +193 -0
  113. package/lib/youcanpay.js +124 -0
  114. package/lib/zarinpal.js +157 -0
  115. package/package.json +138 -64
  116. package/readme.md +348 -105
  117. package/test.js +492 -0
  118. package/example-heleket.js +0 -83
  119. package/lib/vallet.js +0 -22
  120. /package/{example-anypay.js → examples/example-anypay.js} +0 -0
  121. /package/{example-bufpay.js → examples/example-bufpay.js} +0 -0
  122. /package/{example-cryptomus.js → examples/example-cryptomus.js} +0 -0
  123. /package/{example-esnekpos.js → examples/example-esnekpos.js} +0 -0
  124. /package/{example-fedapay.js → examples/example-fedapay.js} +0 -0
  125. /package/{example-iyzico.js → examples/example-iyzico.js} +0 -0
  126. /package/{example-papara.js → examples/example-papara.js} +0 -0
  127. /package/{example-payeer.js → examples/example-payeer.js} +0 -0
  128. /package/{example-paymaya.js → examples/example-paymaya.js} +0 -0
  129. /package/{example-shopier.js → examples/example-shopier.js} +0 -0
  130. /package/{ipaymu.js → examples/ipaymu.js} +0 -0
  131. /package/{oderopay.js → examples/oderopay.js} +0 -0
@@ -0,0 +1,104 @@
1
+ const express = require('express');
2
+ const bodyParser = require('body-parser');
3
+ const PayNetClient = require('../lib/paynet');
4
+
5
+ const app = express();
6
+ app.use(bodyParser.json());
7
+ app.use(bodyParser.urlencoded({ extended: true }));
8
+
9
+ // PayNet yapılandırması
10
+ const paynetClient = new PayNetClient({
11
+ merchantId: 'YOUR_MERCHANT_ID',
12
+ secretKey: 'YOUR_SECRET_KEY'
13
+ });
14
+
15
+ // Ödeme oluşturma
16
+ app.get('/create-payment', async (req, res) => {
17
+ try {
18
+ const payment = await paynetClient.createPayment({
19
+ amount: 100.00,
20
+ currency: 'MDL',
21
+ orderId: `ORDER-${Date.now()}`,
22
+ name: 'Ion Popescu',
23
+ description: 'Test payment',
24
+ language: 'ro',
25
+ email: 'customer@example.com',
26
+ phone: '+37369123456',
27
+ callback_link: 'http://localhost:3000/callback',
28
+ successUrl: 'http://localhost:3000/success',
29
+ failUrl: 'http://localhost:3000/fail',
30
+ callbackUrl: 'http://localhost:3000/callback'
31
+ });
32
+
33
+ console.log('Payment created:', payment);
34
+
35
+ // Kullanıcıyı ödeme sayfasına yönlendir
36
+ res.redirect(payment.data.url);
37
+ } catch (error) {
38
+ console.error('Error:', error.message);
39
+ res.status(500).json({ error: error.message });
40
+ }
41
+ });
42
+
43
+ // Callback endpoint
44
+ app.post('/callback', async (req, res) => {
45
+ try {
46
+ console.log('Callback received:', req.body);
47
+
48
+ const result = await paynetClient.handleCallback(req.body);
49
+
50
+ console.log('Payment result:', result);
51
+
52
+ if (result.status === 'success') {
53
+ // Ödeme başarılı
54
+ console.log('Plata a fost efectuată cu succes!');
55
+ console.log('Order ID:', result.orderId);
56
+ console.log('Transaction ID:', result.transactionId);
57
+ console.log('Amount:', result.amount, result.currency);
58
+ }
59
+
60
+ res.status(200).send('OK');
61
+ } catch (error) {
62
+ console.error('Callback error:', error.message);
63
+ res.status(400).send('ERROR');
64
+ }
65
+ });
66
+
67
+ // Ödeme durumu sorgulama
68
+ app.get('/payment-status/:paymentId', async (req, res) => {
69
+ try {
70
+ const status = await paynetClient.getPaymentStatus(req.params.paymentId);
71
+ res.json(status);
72
+ } catch (error) {
73
+ res.status(500).json({ error: error.message });
74
+ }
75
+ });
76
+
77
+ // İade işlemi
78
+ app.post('/refund/:paymentId', async (req, res) => {
79
+ try {
80
+ const refund = await paynetClient.refundPayment(req.params.paymentId, {
81
+ amount: req.body.amount,
82
+ reason: req.body.reason || 'Solicitarea clientului'
83
+ });
84
+ res.json(refund);
85
+ } catch (error) {
86
+ res.status(500).json({ error: error.message });
87
+ }
88
+ });
89
+
90
+ // Başarı sayfası
91
+ app.get('/success', (req, res) => {
92
+ res.send('<h1>Plată efectuată cu succes!</h1><p>Vă mulțumim pentru plată.</p>');
93
+ });
94
+
95
+ // Hata sayfası
96
+ app.get('/fail', (req, res) => {
97
+ res.send('<h1>Plată eșuată</h1><p>Plata nu a putut fi procesată.</p>');
98
+ });
99
+
100
+ const PORT = 3000;
101
+ app.listen(PORT, () => {
102
+ console.log(`Server running on http://localhost:${PORT}`);
103
+ console.log(`Create payment: http://localhost:${PORT}/create-payment`);
104
+ });
@@ -0,0 +1,18 @@
1
+ const PayNetTRClient = require("../lib/paynettr");
2
+
3
+ const client = new PayNetTRClient({
4
+ merchantId: "YOUR_MERCHANT_ID",
5
+ secretKey: "YOUR_SECRET_KEY"
6
+ });
7
+
8
+ async function example() {
9
+ const payment = await client.createPayment({
10
+ amount: 100.00,
11
+ orderId: "TEST-001",
12
+ callback_link: "https://yoursite.com/callback",
13
+ name: "Test Payment"
14
+ });
15
+ console.log("Payment URL:", payment.data.url);
16
+ }
17
+
18
+ example();
@@ -0,0 +1,74 @@
1
+ const express = require('express');
2
+ const bodyParser = require('body-parser');
3
+ const PayoneerClient = require('../lib/payoneer');
4
+
5
+ const app = express();
6
+ app.use(bodyParser.json());
7
+ app.use(bodyParser.urlencoded({ extended: true }));
8
+
9
+ // Payoneer yapılandırması
10
+ const payoneerClient = new PayoneerClient({
11
+ programId: 'YOUR_PROGRAM_ID',
12
+ username: 'YOUR_USERNAME',
13
+ password: 'YOUR_PASSWORD',
14
+ sandbox: true
15
+ });
16
+
17
+ // Ödeme oluşturma
18
+ app.get('/create-payment', async (req, res) => {
19
+ try {
20
+ const payment = await payoneerClient.createPayment({
21
+ amount: 100.00,
22
+ currency: 'USD',
23
+ orderId: `ORDER-${Date.now()}`,
24
+ payeeId: 'customer@example.com',
25
+ email: 'customer@example.com',
26
+ firstName: 'John',
27
+ lastName: 'Doe',
28
+ description: 'Freelance payment'
29
+ });
30
+
31
+ console.log('Payment created:', payment);
32
+ res.json(payment);
33
+ } catch (error) {
34
+ console.error('Error:', error.message);
35
+ res.status(500).json({ error: error.message });
36
+ }
37
+ });
38
+
39
+ // Ödeme durumu sorgulama
40
+ app.get('/payment-status/:paymentId', async (req, res) => {
41
+ try {
42
+ const status = await payoneerClient.getPaymentStatus(req.params.paymentId);
43
+ console.log('Payment status:', status);
44
+ res.json(status);
45
+ } catch (error) {
46
+ res.status(500).json({ error: error.message });
47
+ }
48
+ });
49
+
50
+ // Ödemeyi iptal et
51
+ app.post('/cancel-payment/:paymentId', async (req, res) => {
52
+ try {
53
+ const result = await payoneerClient.cancelPayment(req.params.paymentId);
54
+ res.json(result);
55
+ } catch (error) {
56
+ res.status(500).json({ error: error.message });
57
+ }
58
+ });
59
+
60
+ // Alıcı bilgilerini sorgula
61
+ app.get('/payee/:payeeId', async (req, res) => {
62
+ try {
63
+ const payee = await payoneerClient.getPayeeDetails(req.params.payeeId);
64
+ res.json(payee);
65
+ } catch (error) {
66
+ res.status(500).json({ error: error.message });
67
+ }
68
+ });
69
+
70
+ const PORT = 3000;
71
+ app.listen(PORT, () => {
72
+ console.log(`Server running on http://localhost:${PORT}`);
73
+ console.log(`Create payment: http://localhost:${PORT}/create-payment`);
74
+ });
@@ -0,0 +1,351 @@
1
+ /**
2
+ * Payop API Example Usage
3
+ * This file demonstrates how to use the Payop API based on official documentation
4
+ * https://github.com/Payop/payop-api-doc
5
+ */
6
+
7
+ // Import the Payop library
8
+ const Payop = require('./lib/payop');
9
+ const crypto = require('crypto');
10
+
11
+ // Initialize the client with your credentials
12
+ const payop = new Payop({
13
+ publicKey: 'application-xxx', // Replace with your actual public key
14
+ secretKey: 'your-secret-key', // Replace with your actual secret key
15
+ environment: 'production' // Use 'sandbox' for testing
16
+ });
17
+
18
+ // Helper function to generate signature according to Payop documentation
19
+ function generateSignature(amount, currency, orderId, secretKey) {
20
+ const data = [amount, currency, orderId, secretKey].join(':');
21
+ return crypto.createHash('sha256').update(data).digest('hex');
22
+ }
23
+
24
+ // Example 1: Create an invoice
25
+ async function createInvoice() {
26
+ try {
27
+ console.log('Creating invoice...');
28
+
29
+ // Generate a unique order ID
30
+ const orderId = `order-${Date.now()}`;
31
+ const amount = "100.00";
32
+ const currency = "USD";
33
+
34
+ // Generate signature for the invoice
35
+ const signature = generateSignature(amount, currency, orderId, payop.config.secretKey);
36
+
37
+ const invoice = await payop.createInvoice({
38
+ order: orderId,
39
+ amount: amount,
40
+ currency: currency,
41
+ description: "Test payment",
42
+ customer: {
43
+ email: "test.user@example.com",
44
+ name: "John Doe"
45
+ },
46
+ resultUrl: "https://your-site.com/success?invoiceId={{invoiceId}}&txid={{txid}}",
47
+ failPath: "https://your-site.com/fail?invoiceId={{invoiceId}}"
48
+ });
49
+
50
+ console.log('Invoice created:');
51
+ console.log('Invoice ID:', invoice.data);
52
+ console.log('Redirect URL:', `https://checkout.payop.com/en/payment/invoice-preprocessing/${invoice.data}`);
53
+
54
+ return invoice.data; // Return invoice ID for further operations
55
+ } catch (error) {
56
+ console.error('Failed to create invoice:', error.message);
57
+ }
58
+ }
59
+
60
+ // Example 2: Get available payment methods
61
+ async function getPaymentMethods(applicationId) {
62
+ try {
63
+ console.log(`Getting available payment methods for application ${applicationId}...`);
64
+ const result = await payop.getPaymentMethods(applicationId);
65
+
66
+ console.log('Available payment methods:');
67
+ if (result.data && Array.isArray(result.data)) {
68
+ result.data.forEach(method => {
69
+ console.log(`- ${method.title} (ID: ${method.identifier})`);
70
+ console.log(` Supported currencies: ${method.currencies.join(', ')}`);
71
+ console.log(` Countries: ${method.countries.join(', ')}`);
72
+ console.log(' Required fields:');
73
+ if (method.config && method.config.fields) {
74
+ method.config.fields.forEach(field => {
75
+ console.log(` ${field.name} (${field.type})${field.required ? ' - Required' : ''}`);
76
+ });
77
+ }
78
+ console.log('---');
79
+ });
80
+ }
81
+
82
+ return result;
83
+ } catch (error) {
84
+ console.error('Failed to get payment methods:', error.message);
85
+ }
86
+ }
87
+
88
+ // Example 3: Create a checkout transaction
89
+ async function createCheckout(invoiceId, paymentMethodId) {
90
+ try {
91
+ console.log(`Creating checkout for invoice ${invoiceId} with payment method ${paymentMethodId}...`);
92
+
93
+ const result = await fetch("https://api.payop.com/v1/checkout/create", {
94
+ method: "POST",
95
+ headers: {
96
+ "Content-Type": "application/json",
97
+ "Authorization": `Bearer ${payop.config.publicKey}`
98
+ },
99
+ body: JSON.stringify({
100
+ invoiceIdentifier: invoiceId,
101
+ customer: {
102
+ email: "test.user@example.com",
103
+ name: "John Doe",
104
+ ip: "192.168.1.1",
105
+ extraFields: {
106
+ // These fields depend on the selected payment method
107
+ // This is an example for a bank transfer
108
+ date_of_birth: "01.01.1990",
109
+ bank_code: "DEUTDEFF",
110
+ bank_type: "SEPA",
111
+ bank_country: "DE"
112
+ }
113
+ },
114
+ paymentMethod: paymentMethodId,
115
+ checkStatusUrl: `https://your-site.com/check-status/{{txid}}`
116
+ })
117
+ });
118
+
119
+ const checkout = await result.json();
120
+
121
+ if (checkout.data && checkout.data.isSuccess) {
122
+ console.log('Checkout created successfully!');
123
+ console.log('Transaction ID:', checkout.data.txid);
124
+ } else {
125
+ console.error('Failed to create checkout:', checkout.data?.message || 'Unknown error');
126
+ }
127
+
128
+ return checkout;
129
+ } catch (error) {
130
+ console.error('Failed to create checkout:', error.message);
131
+ }
132
+ }
133
+
134
+ // Example 4: Check invoice status
135
+ async function checkInvoiceStatus(invoiceId) {
136
+ try {
137
+ console.log(`Checking status of invoice ${invoiceId}...`);
138
+
139
+ const result = await fetch(`https://api.payop.com/v1/checkout/check-invoice-status/${invoiceId}`, {
140
+ method: "GET",
141
+ headers: {
142
+ "Content-Type": "application/json",
143
+ "Authorization": `Bearer ${payop.config.publicKey}`
144
+ }
145
+ });
146
+
147
+ const status = await result.json();
148
+
149
+ if (status.data) {
150
+ console.log('Invoice status:', status.data.status);
151
+
152
+ if (status.data.status === 'success') {
153
+ console.log('Payment successful!');
154
+ } else if (status.data.status === 'fail') {
155
+ console.log('Payment failed!');
156
+ } else if (status.data.status === 'pending') {
157
+ console.log('Payment is pending. Additional action may be required.');
158
+
159
+ // Check if a form needs to be submitted (e.g., 3D Secure)
160
+ if (status.data.form) {
161
+ console.log('Form information:');
162
+ console.log('Method:', status.data.form.method);
163
+ console.log('URL:', status.data.form.url);
164
+ console.log('Form fields:', status.data.form.fields);
165
+ }
166
+ }
167
+ } else {
168
+ console.error('Failed to check invoice status:', status.message || 'Unknown error');
169
+ }
170
+
171
+ return status;
172
+ } catch (error) {
173
+ console.error('Failed to check invoice status:', error.message);
174
+ }
175
+ }
176
+
177
+ // Example 5: Get transaction details
178
+ async function getTransactionDetails(transactionId) {
179
+ try {
180
+ console.log(`Getting details for transaction ${transactionId}...`);
181
+
182
+ const result = await fetch(`https://api.payop.com/v2/transactions/${transactionId}`, {
183
+ method: "GET",
184
+ headers: {
185
+ "Content-Type": "application/json",
186
+ "Authorization": `Bearer ${payop.config.publicKey}`
187
+ }
188
+ });
189
+
190
+ const transaction = await result.json();
191
+
192
+ if (transaction.data) {
193
+ console.log('Transaction details:');
194
+ console.log('ID:', transaction.data.identifier);
195
+ console.log('Amount:', transaction.data.amount, transaction.data.currency);
196
+ console.log('State:', getTransactionStateText(transaction.data.state));
197
+ console.log('Created at:', new Date(transaction.data.createdAt * 1000).toLocaleString());
198
+ console.log('Order ID:', transaction.data.orderId);
199
+
200
+ if (transaction.data.error) {
201
+ console.log('Error:', transaction.data.error);
202
+ }
203
+ } else {
204
+ console.error('Failed to get transaction details:', transaction.message || 'Unknown error');
205
+ }
206
+
207
+ return transaction;
208
+ } catch (error) {
209
+ console.error('Failed to get transaction details:', error.message);
210
+ }
211
+ }
212
+
213
+ // Example 6: Handle IPN (Instant Payment Notification)
214
+ function handleIPN(request, response) {
215
+ try {
216
+ console.log('Received IPN notification');
217
+
218
+ // In a real application, this would be the request body sent by Payop
219
+ const notificationData = request.body;
220
+
221
+ console.log('IPN Data:', JSON.stringify(notificationData, null, 2));
222
+
223
+ // Extract important information from the IPN
224
+ if (notificationData.invoice && notificationData.transaction) {
225
+ const invoiceId = notificationData.invoice.id;
226
+ const invoiceStatus = notificationData.invoice.status;
227
+ const transactionId = notificationData.transaction.id;
228
+ const transactionState = notificationData.transaction.state;
229
+ const orderId = notificationData.transaction.order?.id;
230
+
231
+ console.log(`Order ${orderId}, Invoice ${invoiceId}, Transaction ${transactionId}`);
232
+ console.log(`Invoice status: ${invoiceStatus}, Transaction state: ${getTransactionStateText(transactionState)}`);
233
+
234
+ // Handle transaction state
235
+ if (transactionState === 2) { // Accepted/Success
236
+ // Update your database - mark order as paid
237
+ console.log('Payment successful! Update your database and fulfill the order.');
238
+ } else if (transactionState === 3 || transactionState === 5) { // Failed
239
+ // Update your database - mark order as failed
240
+ console.log('Payment failed! Update your database and notify customer if needed.');
241
+
242
+ if (notificationData.transaction.error) {
243
+ console.log('Error message:', notificationData.transaction.error.message);
244
+ }
245
+ } else if (transactionState === 4) { // Pending
246
+ // Payment is still being processed
247
+ console.log('Payment is pending. Waiting for final status.');
248
+ }
249
+
250
+ // Always respond with 200 OK to acknowledge receipt of the IPN
251
+ response.status(200).send('OK');
252
+ } else {
253
+ console.error('Invalid IPN data structure');
254
+ response.status(400).send('Invalid IPN data');
255
+ }
256
+ } catch (error) {
257
+ console.error('Error processing IPN:', error.message);
258
+ response.status(500).send('Internal server error');
259
+ }
260
+ }
261
+
262
+ // Helper function to translate transaction state codes to text
263
+ function getTransactionStateText(state) {
264
+ const states = {
265
+ 1: 'New - No actions taken',
266
+ 2: 'Accepted - Paid successfully',
267
+ 3: 'Failed - Not paid (technical reasons)',
268
+ 4: 'Pending - Awaiting payment',
269
+ 5: 'Failed - Not paid (financial reasons)',
270
+ 9: 'Pre-approved - Submitted through bank, awaiting funds',
271
+ 15: 'Timeout - Timed out due to lack of confirmation'
272
+ };
273
+
274
+ return states[state] || `Unknown state (${state})`;
275
+ }
276
+
277
+ // Example 7: Simulate an IPN for testing
278
+ function simulateIPN() {
279
+ console.log('Simulating an IPN...');
280
+
281
+ // Create a mock request and response object
282
+ const mockRequest = {
283
+ body: {
284
+ "invoice": {
285
+ "id": "d024f697-ba2d-456f-910e-4d7fdfd338dd",
286
+ "status": 1,
287
+ "txid": "dca59ca5-be19-470d-9494-9b76944e0241",
288
+ "metadata": {
289
+ "orderId": "test-123",
290
+ "amount": 100,
291
+ "customerId": 15487
292
+ }
293
+ },
294
+ "transaction": {
295
+ "id": "dca59ca5-be19-470d-9494-9b76944e0241",
296
+ "state": 2,
297
+ "order": {
298
+ "id": "test-123"
299
+ },
300
+ "error": {
301
+ "message": "",
302
+ "code": ""
303
+ }
304
+ }
305
+ }
306
+ };
307
+
308
+ const mockResponse = {
309
+ status: (code) => {
310
+ console.log(`Response status: ${code}`);
311
+ return {
312
+ send: (message) => {
313
+ console.log(`Response body: ${message}`);
314
+ }
315
+ };
316
+ }
317
+ };
318
+
319
+ // Process the simulated IPN
320
+ handleIPN(mockRequest, mockResponse);
321
+ }
322
+
323
+ // Run examples
324
+ async function runExamples() {
325
+ try {
326
+ console.log('=== Payop API Integration Examples ===\n');
327
+
328
+ // Example 1: Create an invoice
329
+ console.log('\n--- Example 1: Create Invoice ---');
330
+ const invoiceId = await createInvoice();
331
+
332
+ // In a real application, you would redirect the user to:
333
+ // https://checkout.payop.com/en/payment/invoice-preprocessing/{invoiceId}
334
+
335
+ // Example 2: Get available payment methods
336
+ // Note: This requires a valid application ID and bearer token
337
+ // console.log('\n--- Example 2: Get Payment Methods ---');
338
+ // await getPaymentMethods('your-application-id');
339
+
340
+ // Example 7: Simulate an IPN for testing
341
+ console.log('\n--- Example 7: Simulate IPN ---');
342
+ simulateIPN();
343
+
344
+ console.log('\n=== End of Examples ===');
345
+ } catch (error) {
346
+ console.error('Error running examples:', error);
347
+ }
348
+ }
349
+
350
+ // Run all examples
351
+ runExamples();