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,82 @@
1
+ const express = require('express');
2
+ const bodyParser = require('body-parser');
3
+ const QuickPos = require('./app');
4
+
5
+ const app = express();
6
+ app.use(bodyParser.urlencoded({ extended: true }));
7
+ app.use(bodyParser.json());
8
+
9
+ const quickPos = new QuickPos({
10
+ providers: {
11
+ paycom: {
12
+ merchantId: 'your-merchant-id',
13
+ secretKey: 'your-secret-key'
14
+ }
15
+ },
16
+ });
17
+
18
+ app.use(quickPos.middleware());
19
+
20
+ // Payment form
21
+ app.get('/', (req, res) => {
22
+ res.send(`
23
+ <h1>Paycom Payment Example (Uzbekistan)</h1>
24
+ <form action="/payment/paycom" method="post">
25
+ <input type="text" name="amount" placeholder="Amount (UZS)" required>
26
+ <input type="text" name="orderId" placeholder="Order ID" required>
27
+ <button type="submit">Pay with Paycom</button>
28
+ </form>
29
+ `);
30
+ });
31
+
32
+ // Create payment
33
+ app.post('/payment/:provider', async (req, res) => {
34
+ const { provider } = req.params;
35
+
36
+ if (!req.quickPos[provider]) {
37
+ return res.status(400).json({ error: 'Invalid payment provider' });
38
+ }
39
+
40
+ try {
41
+ const result = await req.quickPos[provider].createPayment({
42
+ amount: req.body.amount,
43
+ orderId: req.body.orderId,
44
+ callback_link: `http://localhost:3000/payment-callback/${provider}`
45
+ });
46
+
47
+ if (result.status === 'success') {
48
+ res.json({
49
+ success: true,
50
+ redirectUrl: result.data.url,
51
+ orderId: result.data.orderId
52
+ });
53
+ } else {
54
+ res.status(400).json(result);
55
+ }
56
+ } catch (error) {
57
+ res.status(500).json({ error: error.message });
58
+ }
59
+ });
60
+
61
+ // Payment callback - Paycom uses JSON-RPC 2.0 protocol
62
+ app.post('/payment-callback/:provider', async (req, res) => {
63
+ try {
64
+ const result = await quickPos.providers.paycom.handleCallback(req.body);
65
+ res.json(result);
66
+ } catch (error) {
67
+ res.json({
68
+ jsonrpc: '2.0',
69
+ id: req.body.id,
70
+ error: {
71
+ code: -32400,
72
+ message: error.message
73
+ }
74
+ });
75
+ }
76
+ });
77
+
78
+ const PORT = process.env.PORT || 3000;
79
+ app.listen(PORT, () => {
80
+ console.log(`Server is running on port ${PORT}`);
81
+ console.log(`Open http://localhost:${PORT} to test`);
82
+ });
@@ -10,7 +10,7 @@ app.use(bodyParser.json());
10
10
  const quickPos = new QuickPos({
11
11
  providers: {
12
12
  paydisini: {
13
- apiKey: 'YOUR_API_KEY', // Gerçek API anahtarınızla değiştirin
13
+ apiKey: '', // Gerçek API anahtarınızla değiştirin
14
14
  debug: true // Geliştirme modunda hata ayıklama için
15
15
  }
16
16
  }
@@ -0,0 +1,87 @@
1
+ const express = require('express');
2
+ const bodyParser = require('body-parser');
3
+ const QuickPos = require('./app');
4
+
5
+ const app = express();
6
+ app.use(bodyParser.urlencoded({ extended: true }));
7
+ app.use(bodyParser.json());
8
+
9
+ const quickPos = new QuickPos({
10
+ providers: {
11
+ payid19: {
12
+ apiKey: 'your-api-key',
13
+ secretKey: 'your-secret-key'
14
+ }
15
+ },
16
+ });
17
+
18
+ app.use(quickPos.middleware());
19
+
20
+ // Payment form
21
+ app.get('/', (req, res) => {
22
+ res.send(`
23
+ <h1>PayID19 Payment Example</h1>
24
+ <form action="/payment/payid19" method="post">
25
+ <input type="text" name="amount" placeholder="Amount (IDR)" required>
26
+ <input type="email" name="email" placeholder="Email" required>
27
+ <input type="text" name="name" placeholder="Customer Name" required>
28
+ <input type="text" name="phone" placeholder="Phone" required>
29
+ <input type="text" name="orderId" placeholder="Order ID" required>
30
+ <select name="paymentMethod">
31
+ <option value="all">All Methods</option>
32
+ <option value="va">Virtual Account</option>
33
+ <option value="qris">QRIS</option>
34
+ <option value="ewallet">E-Wallet</option>
35
+ </select>
36
+ <button type="submit">Pay with PayID19</button>
37
+ </form>
38
+ `);
39
+ });
40
+
41
+ // Create payment
42
+ app.post('/payment/:provider', async (req, res) => {
43
+ const { provider } = req.params;
44
+
45
+ if (!req.quickPos[provider]) {
46
+ return res.status(400).json({ error: 'Invalid payment provider' });
47
+ }
48
+
49
+ try {
50
+ const result = await req.quickPos[provider].createPayment({
51
+ amount: req.body.amount,
52
+ customerName: req.body.name,
53
+ customerEmail: req.body.email,
54
+ customerPhone: req.body.phone,
55
+ orderId: req.body.orderId,
56
+ paymentMethod: req.body.paymentMethod || 'all',
57
+ callback_link: `http://localhost:3000/payment-callback/${provider}`,
58
+ description: 'Test Product'
59
+ });
60
+
61
+ if (result.status === 'success') {
62
+ res.json({
63
+ success: true,
64
+ redirectUrl: result.data.url,
65
+ paymentId: result.data.paymentId,
66
+ qrCode: result.data.qrCode,
67
+ expiredAt: result.data.expiredAt
68
+ });
69
+ } else {
70
+ res.status(400).json(result);
71
+ }
72
+ } catch (error) {
73
+ res.status(500).json({ error: error.message });
74
+ }
75
+ });
76
+
77
+ // Payment callback
78
+ app.post('/payment-callback/:provider', quickPos.handleCallback('payid19'), (req, res) => {
79
+ console.log('Payment result:', req.paymentResult);
80
+ res.json({ success: true, data: req.paymentResult });
81
+ });
82
+
83
+ const PORT = process.env.PORT || 3000;
84
+ app.listen(PORT, () => {
85
+ console.log(`Server is running on port ${PORT}`);
86
+ console.log(`Open http://localhost:${PORT} to test`);
87
+ });
@@ -0,0 +1,29 @@
1
+ const PayKunClient = require('../lib/paykun');
2
+
3
+ const client = new PayKunClient({
4
+ merchantId: 'YOUR_MERCHANT_ID',
5
+ accessToken: 'YOUR_ACCESS_TOKEN',
6
+ encryptionKey: 'YOUR_ENCRYPTION_KEY',
7
+ sandbox: true
8
+ });
9
+
10
+ async function example() {
11
+ try {
12
+ const payment = await client.createPayment({
13
+ amount: 1000,
14
+ orderId: 'TEST-001',
15
+ currency: 'INR',
16
+ callback_link: 'https://yoursite.com/callback',
17
+ name: 'Rajesh Kumar',
18
+ email: 'rajesh@example.com',
19
+ phone: '9876543210'
20
+ });
21
+
22
+ console.log('Payment URL:', payment.data.url);
23
+ console.log('Transaction ID:', payment.data.transactionId);
24
+ } catch (error) {
25
+ console.error('Error:', error.message);
26
+ }
27
+ }
28
+
29
+ example();
@@ -0,0 +1,202 @@
1
+ const PayMeService = require('./lib/payme');
2
+ const express = require('express');
3
+ const bodyParser = require('body-parser');
4
+ const app = express();
5
+
6
+ // Body parser middleware
7
+ app.use(bodyParser.json());
8
+ app.use(bodyParser.urlencoded({ extended: true }));
9
+
10
+ // Tüm istekleri loglama
11
+ app.use((req, res, next) => {
12
+ console.log(`[${new Date().toISOString()}] Gelen istek: ${req.method} ${req.url}`);
13
+ if (Object.keys(req.query).length > 0) {
14
+ console.log('Query:', JSON.stringify(req.query));
15
+ }
16
+ if (req.body && Object.keys(req.body).length > 0) {
17
+ console.log('Body:', JSON.stringify(req.body));
18
+ }
19
+ next();
20
+ });
21
+
22
+ // PayMe konfigürasyonu - kendi API anahtarınızı kullanmalısınız
23
+ const paymeConfig = {
24
+ sellerPaymeId: 'MPLDEMO-MPLDEMO-MPLDEMO-1234567', // Demo seller ID, kendi anahtarınızla değiştirin
25
+ sandbox: true, // Sandbox ortamı için true, canlı ortam için false
26
+ debug: true // Debug modu açık (geliştirme sırasında)
27
+ };
28
+
29
+ // PayMe servisini başlat
30
+ const payme = new PayMeService(paymeConfig);
31
+
32
+ // Ödeme oluşturma örneği
33
+ async function createPaymentExample() {
34
+ try {
35
+ console.log('Yeni ödeme isteği oluşturuluyor...');
36
+
37
+ const paymentResult = await payme.createPayment({
38
+ name: 'Premium Üyelik - 1 Ay',
39
+ amount: 100.50, // 100.50 birim
40
+ currency: 'ILS', // Para birimi (ILS = İsrail Şekeli)
41
+ orderId: 'siparis-' + Date.now(),
42
+ installments: '1', // Tek çekim
43
+ sendNotification: true, // E-posta ve SMS bildirimleri gönder
44
+ email: 'musteri@ornek.com',
45
+ phone: '+905321234567',
46
+ buyerName: 'İsim Soyisim',
47
+ callbackUrl: 'https://test.quickpanel.net/webhook/payme', // Webhook URL
48
+ returnUrl: 'https://test.quickpanel.net/success', // Başarılı ödeme dönüş sayfası
49
+ saleType: 'sale', // Satış tipi (sale, auth vb.)
50
+ paymentMethod: 'credit-card', // Ödeme yöntemi
51
+ language: 'he', // Ödeme sayfası dili - 'he' (İbranice) veya 'en' (İngilizce) kullanın
52
+ generateQr: true // QR kod oluştur
53
+ });
54
+
55
+ console.log('Ödeme bağlantısı oluşturuldu:');
56
+ console.log(JSON.stringify(paymentResult, null, 2));
57
+
58
+ return paymentResult;
59
+ } catch (error) {
60
+ console.error('Ödeme oluşturma hatası:', error.message);
61
+ return { status: 'error', message: error.message };
62
+ }
63
+ }
64
+
65
+ // Webhook endpoint
66
+ app.post('/webhook/payme', async (req, res) => {
67
+ console.log('🔔 PayMe webhook çağrısı alındı!');
68
+
69
+ try {
70
+ // Callback işleme
71
+ const result = await payme.handleCallback(req.body);
72
+ console.log('✅ Ödeme durumu:', result);
73
+
74
+ if (result.status === 'success') {
75
+ console.log(`✅ Başarılı Ödeme: Sipariş ${result.orderId} için ${result.amount} ${result.currency} ödeme alındı`);
76
+
77
+ // Burada başarılı ödeme işlemleri yapılabilir
78
+ // - Veritabanı güncelleme
79
+ // - Sipariş durumu değiştirme
80
+ // - Kullanıcı hesabını aktifleştirme vb.
81
+ } else {
82
+ console.log(`❌ Başarısız Ödeme: Sipariş ${result.orderId} - Sebep: ${result.reason}`);
83
+ }
84
+
85
+ // PayMe'ye başarılı yanıt gönder (HTTP 200)
86
+ res.status(200).end();
87
+ } catch (error) {
88
+ console.error('⚠️ Webhook işleme hatası:', error.message);
89
+ // Webhook işleme hatası durumunda bile 200 OK dönmek önemli
90
+ // (böylece PayMe tekrar deneme yapmayı bırakır)
91
+ res.status(200).end();
92
+ }
93
+ });
94
+
95
+ // Başarılı ödeme dönüş sayfası
96
+ app.get('/success', (req, res) => {
97
+ res.send(`
98
+ <html>
99
+ <head>
100
+ <title>Ödeme Başarılı</title>
101
+ <style>
102
+ body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
103
+ .success { color: green; font-size: 24px; margin-bottom: 20px; }
104
+ </style>
105
+ </head>
106
+ <body>
107
+ <div class="success">Ödemeniz başarıyla tamamlandı!</div>
108
+ <p>Teşekkür ederiz. Siparişiniz işleme alındı.</p>
109
+ <pre>${JSON.stringify(req.query, null, 2)}</pre>
110
+ </body>
111
+ </html>
112
+ `);
113
+ });
114
+
115
+ // Ana sayfa
116
+ app.get('/', (req, res) => {
117
+ res.send(`
118
+ <html>
119
+ <head>
120
+ <title>PayMe Ödeme Testi</title>
121
+ <style>
122
+ body { font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin: 0 auto; }
123
+ button { padding: 10px 15px; background: #0066ff; color: white; border: none; border-radius: 4px; cursor: pointer; }
124
+ .container { margin-top: 20px; }
125
+ pre { background: #f4f4f4; padding: 10px; border-radius: 4px; overflow: auto; }
126
+ .error { color: red; }
127
+ </style>
128
+ </head>
129
+ <body>
130
+ <h1>PayMe Ödeme Testi</h1>
131
+ <p>PayMe ${paymeConfig.sandbox ? 'Sandbox' : 'Canlı'} API ile ödeme bağlantısı oluşturma testi.</p>
132
+ <button onclick="createPayment()">Yeni Ödeme Oluştur</button>
133
+
134
+ <div class="container" id="result">
135
+ <p>Bu test için aşağıdaki bilgileri kullanıyoruz:</p>
136
+ <pre>Seller ID: ${paymeConfig.sellerPaymeId}
137
+ Ortam: ${paymeConfig.sandbox ? 'Sandbox (test)' : 'Production (canlı)'}</pre>
138
+ </div>
139
+
140
+ <script>
141
+ function createPayment() {
142
+ document.getElementById('result').innerHTML = '<p>Ödeme oluşturuluyor...</p>';
143
+
144
+ fetch('/create-payment')
145
+ .then(response => response.json())
146
+ .then(data => {
147
+ if (data.status === 'success') {
148
+ let html = \`
149
+ <h3>Ödeme Bağlantısı Oluşturuldu</h3>
150
+ <p>Ödeme ID: \${data.data.id}</p>
151
+ <p>PayMe Kodu: \${data.data.paymeCode}</p>
152
+ <p>Ödeme URL: <a href="\${data.data.url}" target="_blank">\${data.data.url}</a></p>
153
+ \`;
154
+
155
+ if (data.data.qr) {
156
+ html += \`<p>QR Kod:</p><img src="\${data.data.qr}" width="200" />\`;
157
+ }
158
+
159
+ document.getElementById('result').innerHTML = html;
160
+ } else {
161
+ document.getElementById('result').innerHTML = '<p class="error">Hata: ' + data.message + '</p>';
162
+ }
163
+ })
164
+ .catch(error => {
165
+ document.getElementById('result').innerHTML = '<p class="error">Hata: ' + error + '</p>';
166
+ });
167
+ }
168
+ </script>
169
+ </body>
170
+ </html>
171
+ `);
172
+ });
173
+
174
+ // API endpoint - yeni ödeme oluşturma
175
+ app.get('/create-payment', async (req, res) => {
176
+ try {
177
+ const result = await createPaymentExample();
178
+ res.json(result);
179
+ } catch (error) {
180
+ res.status(400).json({ status: 'error', message: error.message });
181
+ }
182
+ });
183
+
184
+ // Test sunucusunu başlat
185
+ const PORT = 81;
186
+ app.listen(PORT, () => {
187
+ console.log(`🚀 Test sunucusu başlatıldı: http://localhost:${PORT}`);
188
+ console.log(`🔔 Webhook URL: http://localhost:${PORT}/webhook/payme`);
189
+ console.log('⚠️ PayMe Entegrasyon Ayarları:');
190
+ console.log(` - Seller ID: ${paymeConfig.sellerPaymeId}`);
191
+ console.log(` - Ortam: ${paymeConfig.sandbox ? 'Sandbox (Test)' : 'Production (Canlı)'}`);
192
+ console.log(` - API Base URL: ${payme.baseUrl}`);
193
+
194
+ console.log('⚠️ Not: Gerçek ortamda, webhook URL\'inizi PayMe panelinde ayarlayın');
195
+ console.log('⚠️ Ayrıca, example-payme.js dosyasındaki Seller ID\'yi kendi ID\'nizle değiştirmeyi unutmayın');
196
+ });
197
+
198
+ // Sunucuyu kapatmak için CTRL+C
199
+ process.on('SIGINT', () => {
200
+ console.log('Test sunucusu kapatılıyor...');
201
+ process.exit(0);
202
+ });
@@ -0,0 +1,201 @@
1
+ const PaymentwallService = require('./lib/paymentwall');
2
+ const express = require('express');
3
+ const bodyParser = require('body-parser');
4
+ const app = express();
5
+
6
+ // Body parser kullanarak webhook'dan gelen verileri işleyebilmek için
7
+ app.use(bodyParser.json());
8
+ app.use(bodyParser.urlencoded({ extended: true }));
9
+
10
+ // Tüm istekleri loglama
11
+ app.use((req, res, next) => {
12
+ console.log(`[${new Date().toISOString()}] Gelen istek: ${req.method} ${req.url}`);
13
+ console.log('Headers:', JSON.stringify(req.headers));
14
+ if (Object.keys(req.query).length > 0) {
15
+ console.log('Query:', JSON.stringify(req.query));
16
+ }
17
+ if (req.body && Object.keys(req.body).length > 0) {
18
+ console.log('Body:', JSON.stringify(req.body));
19
+ }
20
+ next();
21
+ });
22
+
23
+ // Paymentwall konfigürasyonu
24
+ const paymentwallConfig = {
25
+ appKey: '',
26
+ secretKey: '',
27
+ testMode: true
28
+ };
29
+
30
+ // Paymentwall servisini başlat
31
+ const paymentwall = new PaymentwallService(paymentwallConfig);
32
+
33
+ // Tek seferlik ödeme örneği
34
+ async function createOneTimePayment() {
35
+ try {
36
+ const paymentResult = await paymentwall.createPayment({
37
+ name: 'Premium Paket - Tek Seferlik',
38
+ amount: 199.99,
39
+ currency: 'TRY',
40
+ email: 'musteri@ornek.com',
41
+ productId: 'urun-123',
42
+ orderId: 'siparis-' + Date.now(),
43
+ userId: 'kullanici-123',
44
+ widgetCode: 'p1_1',
45
+ generateQr: true,
46
+ // Webhook URL'ini Paymentwall panelindeki ayar ile aynı olmalı
47
+ pingback_url: 'https://test.quickpanel.net/webhook',
48
+ success_url: 'https://test.quickpanel.net/webhook/success',
49
+ customParams: {
50
+ description: 'Tek seferlik premium paket ödemesi'
51
+ }
52
+ });
53
+
54
+ console.log('Tek seferlik ödeme bağlantısı oluşturuldu:');
55
+ console.log(paymentResult);
56
+ console.log('\nWebhook test sunucusu başlatıldı: http://localhost:80');
57
+ console.log('Webhook URL\'inizi Paymentwall panelinde şu şekilde ayarlayın:');
58
+ console.log('1. https://test.quickpanel.net/webhook');
59
+ console.log('2. IP adresine izin vermeyi unutmayın');
60
+
61
+ return paymentResult;
62
+ } catch (error) {
63
+ console.error('Ödeme oluşturma hatası:', error.message);
64
+ }
65
+ }
66
+
67
+ // Webhook endpoint - hem GET hem POST destekler
68
+ app.all('/webhook', (req, res) => {
69
+ console.log('🔔 Webhook çağrısı alındı!');
70
+
71
+ // GET ve POST isteklerini birleştir
72
+ const callbackData = req.method === 'POST' ? req.body : req.query;
73
+ const clientIp = req.headers['x-forwarded-for'] || req.ip || req.connection.remoteAddress;
74
+
75
+ console.log(`📌 Webhook türü: ${req.method}`);
76
+ console.log(`📌 IP Adresi: ${clientIp}`);
77
+ console.log('📌 Callback Verileri:', callbackData);
78
+
79
+ // Test için manuel doğrulama
80
+ if (Object.keys(callbackData).length === 0) {
81
+ console.log('⚠️ Callback verisi boş, test cevabı dönülüyor');
82
+ return res.status(200).send('OK TEST');
83
+ }
84
+
85
+ paymentwall.handleCallback(callbackData, clientIp)
86
+ .then(result => {
87
+ console.log('✅ Ödeme durumu:', result);
88
+
89
+ if (result.status === 'success') {
90
+ console.log(`✅ Başarılı Ödeme: Sipariş ${result.orderId} için ${result.amount} ${result.currency} ödeme alındı`);
91
+ } else if (result.status === 'failed') {
92
+ console.log(`❌ Başarısız Ödeme: Sipariş ${result.orderId} - Sebep: ${result.reason}`);
93
+ } else {
94
+ console.log(`ℹ️ Diğer Durum: ${result.type} - Sipariş: ${result.orderId}`);
95
+ }
96
+
97
+ // Paymentwall'a başarılı yanıt gönder - bu çok önemli!
98
+ res.status(200).send('OK');
99
+ })
100
+ .catch(error => {
101
+ console.error('⚠️ Webhook işleme hatası:', error.message);
102
+
103
+ // Hata olsa bile 200 OK dönmek önemli
104
+ res.status(200).send('OK');
105
+ });
106
+ });
107
+
108
+ // Başarılı ödeme dönüş sayfası
109
+ app.get('/webhook/success', (req, res) => {
110
+ console.log('✅ Başarı sayfasına yönlendirildi:', req.query);
111
+
112
+ res.send(`
113
+ <html>
114
+ <head>
115
+ <title>Ödeme Başarılı</title>
116
+ <style>
117
+ body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
118
+ .success { color: green; font-size: 24px; margin-bottom: 20px; }
119
+ </style>
120
+ </head>
121
+ <body>
122
+ <div class="success">Ödemeniz başarıyla tamamlandı!</div>
123
+ <p>Teşekkür ederiz. Siparişiniz işleme alındı.</p>
124
+ <p>Sipariş detayları webhook üzerinden işleniyor...</p>
125
+ <pre>${JSON.stringify(req.query, null, 2)}</pre>
126
+ </body>
127
+ </html>
128
+ `);
129
+ });
130
+
131
+ // Basit bir test sayfası
132
+ app.get('/', (req, res) => {
133
+ res.send(`
134
+ <html>
135
+ <head>
136
+ <title>Paymentwall Test</title>
137
+ <style>
138
+ body { font-family: Arial, sans-serif; padding: 20px; }
139
+ button { padding: 10px; margin: 10px 0; background: #0066ff; color: white; border: none; border-radius: 4px; cursor: pointer; }
140
+ </style>
141
+ </head>
142
+ <body>
143
+ <h1>Paymentwall Test</h1>
144
+ <p>Webhook URL: <code>/webhook</code></p>
145
+ <button onclick="testWebhook()">Test Webhook</button>
146
+ <script>
147
+ function testWebhook() {
148
+ fetch('/webhook-test')
149
+ .then(response => response.text())
150
+ .then(data => alert('Test sonucu: ' + data))
151
+ .catch(error => alert('Hata: ' + error));
152
+ }
153
+ </script>
154
+ </body>
155
+ </html>
156
+ `);
157
+ });
158
+
159
+ // Manuel webhook testi için endpoint
160
+ app.get('/webhook-test', (req, res) => {
161
+ const testData = {
162
+ type: 1,
163
+ uid: 'kullanici-123',
164
+ ref: 'test-' + Date.now(),
165
+ is_test: 1,
166
+ order_id: 'siparis-test',
167
+ amount: '199.99',
168
+ currency: 'TRY',
169
+ test_mode: 1
170
+ };
171
+
172
+ console.log('🧪 Manuel webhook test çağrısı yapılıyor...');
173
+
174
+ paymentwall.handleCallback(testData, '127.0.0.1')
175
+ .then(result => {
176
+ console.log('🧪 Test sonucu:', result);
177
+ res.status(200).send('Test başarılı: ' + JSON.stringify(result));
178
+ })
179
+ .catch(error => {
180
+ console.error('🧪 Test hatası:', error.message);
181
+ res.status(500).send('Test hatası: ' + error.message);
182
+ });
183
+ });
184
+
185
+ // Test sunucusunu başlat
186
+ const PORT = 80;
187
+ app.listen(PORT, () => {
188
+ console.log(`🚀 Test sunucusu başlatıldı: http://localhost:${PORT}`);
189
+ console.log(`🔔 Webhook URL: http://localhost:${PORT}/webhook`);
190
+ console.log(`⚠️ Önemli: Gerçek ortamda, webhook URL'inizi Paymentwall panelinde`);
191
+ console.log(` https://test.quickpanel.net/webhook olarak ayarlayın`);
192
+
193
+ // Ödeme örneğini başlat
194
+ createOneTimePayment();
195
+ });
196
+
197
+ // Sunucuyu kapatmak için CTRL+C
198
+ process.on('SIGINT', () => {
199
+ console.log('Test sunucusu kapatılıyor...');
200
+ process.exit(0);
201
+ });