quickpos 1.0.905 → 1.0.907
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.
- package/app.js +2 -1
- package/example-anypay.js +334 -0
- package/example-cryptomus.js +40 -0
- package/example-esnekpos.js +254 -0
- package/example-fedapay.js +217 -0
- package/example-iyzico.js +103 -0
- package/example-paymaya.js +112 -0
- package/example-shopier.js +1 -1
- package/lib/anypay.js +246 -0
- package/lib/cryptomus.js +2 -2
- package/lib/esnekpos.js +352 -0
- package/lib/fedapay.js +194 -0
- package/lib/iyzico.js +180 -0
- package/lib/paymaya.js +126 -0
- package/package.json +17 -4
- package/readme.md +10 -12
package/app.js
CHANGED
|
@@ -31,7 +31,8 @@ class QuickPos {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
try {
|
|
34
|
-
|
|
34
|
+
let qProviders = ["paymaya"];
|
|
35
|
+
const result = await this.providers[providerName].handleCallback(!qProviders.includes(providerName) ? req.body : req.query);
|
|
35
36
|
req.paymentResult = result;
|
|
36
37
|
next();
|
|
37
38
|
} catch (error) {
|
|
@@ -0,0 +1,334 @@
|
|
|
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
|
+
anypay: {
|
|
12
|
+
merchantId: '16219', // Merchant ID
|
|
13
|
+
secretKey: 'xxx', // Gizli anahtar
|
|
14
|
+
apiId: 'xxxx', // API ID (isteğe bağlı)
|
|
15
|
+
apiKey: 'xxx', // API anahtarı (isteğe bağlı)
|
|
16
|
+
debug: true // Geliştirme aşamasında hata ayıklama için
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app.use(quickPos.middleware());
|
|
22
|
+
|
|
23
|
+
// Ana sayfa - Ödeme formları
|
|
24
|
+
app.get('/', (req, res) => {
|
|
25
|
+
res.send(`
|
|
26
|
+
<h1>AnyPay Ödeme Testi</h1>
|
|
27
|
+
<h2>Form Yöntemi ile Ödeme</h2>
|
|
28
|
+
<form action="/create-payment-form" method="post">
|
|
29
|
+
<div>
|
|
30
|
+
<label>Miktar:</label>
|
|
31
|
+
<input type="text" name="amount" value="10.00" required>
|
|
32
|
+
</div>
|
|
33
|
+
<div>
|
|
34
|
+
<label>Para Birimi:</label>
|
|
35
|
+
<select name="currency" required>
|
|
36
|
+
<option value="RUB">RUB</option>
|
|
37
|
+
<option value="USD">USD</option>
|
|
38
|
+
<option value="EUR">EUR</option>
|
|
39
|
+
<option value="UAH">UAH</option>
|
|
40
|
+
<option value="BYN">BYN</option>
|
|
41
|
+
<option value="KZT">KZT</option>
|
|
42
|
+
</select>
|
|
43
|
+
</div>
|
|
44
|
+
<div>
|
|
45
|
+
<label>Ödeme Yöntemi:</label>
|
|
46
|
+
<select name="method" required>
|
|
47
|
+
<option value="card">Kredi Kartı</option>
|
|
48
|
+
<option value="qiwi">Qiwi</option>
|
|
49
|
+
<option value="payeer">Payeer</option>
|
|
50
|
+
<option value="btc">Bitcoin</option>
|
|
51
|
+
<option value="eth">Ethereum</option>
|
|
52
|
+
<option value="ltc">Litecoin</option>
|
|
53
|
+
</select>
|
|
54
|
+
</div>
|
|
55
|
+
<div>
|
|
56
|
+
<label>Email:</label>
|
|
57
|
+
<input type="email" name="email" value="customer@example.com" required>
|
|
58
|
+
</div>
|
|
59
|
+
<div>
|
|
60
|
+
<label>Açıklama:</label>
|
|
61
|
+
<input type="text" name="desc" value="Test ürünü" required>
|
|
62
|
+
</div>
|
|
63
|
+
<button type="submit">Form ile Ödeme Oluştur</button>
|
|
64
|
+
</form>
|
|
65
|
+
|
|
66
|
+
<hr>
|
|
67
|
+
|
|
68
|
+
<h2>API Yöntemi ile Ödeme (API Key gerektirir)</h2>
|
|
69
|
+
<form action="/create-payment-api" method="post">
|
|
70
|
+
<div>
|
|
71
|
+
<label>Miktar:</label>
|
|
72
|
+
<input type="text" name="amount" value="10.00" required>
|
|
73
|
+
</div>
|
|
74
|
+
<div>
|
|
75
|
+
<label>Para Birimi:</label>
|
|
76
|
+
<select name="currency" required>
|
|
77
|
+
<option value="RUB">RUB</option>
|
|
78
|
+
<option value="USD">USD</option>
|
|
79
|
+
</select>
|
|
80
|
+
</div>
|
|
81
|
+
<div>
|
|
82
|
+
<label>Ödeme Yöntemi:</label>
|
|
83
|
+
<select name="method" required>
|
|
84
|
+
<option value="card">Kredi Kartı</option>
|
|
85
|
+
<option value="qiwi">Qiwi</option>
|
|
86
|
+
</select>
|
|
87
|
+
</div>
|
|
88
|
+
<div>
|
|
89
|
+
<label>Email:</label>
|
|
90
|
+
<input type="email" name="email" value="customer@example.com" required>
|
|
91
|
+
</div>
|
|
92
|
+
<div>
|
|
93
|
+
<label>Açıklama:</label>
|
|
94
|
+
<input type="text" name="desc" value="API Test ürünü" required>
|
|
95
|
+
</div>
|
|
96
|
+
<button type="submit">API ile Ödeme Oluştur</button>
|
|
97
|
+
</form>
|
|
98
|
+
|
|
99
|
+
<hr>
|
|
100
|
+
|
|
101
|
+
<h3>Diğer İşlemler</h3>
|
|
102
|
+
<ul>
|
|
103
|
+
<li><a href="/balance">Bakiye Görüntüle</a></li>
|
|
104
|
+
<li><a href="/rates">Döviz Kurları</a></li>
|
|
105
|
+
<li><a href="/commissions">Komisyon Oranları</a></li>
|
|
106
|
+
<li><a href="/notification-ips">Bildirim IP Adresleri</a></li>
|
|
107
|
+
<li><a href="/payments">Son Ödemeler</a></li>
|
|
108
|
+
</ul>
|
|
109
|
+
`);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Form yöntemiyle ödeme oluşturma
|
|
113
|
+
app.post('/create-payment-form', async (req, res) => {
|
|
114
|
+
try {
|
|
115
|
+
const result = await quickPos.providers['anypay'].createPayment({
|
|
116
|
+
amount: req.body.amount,
|
|
117
|
+
currency: req.body.currency,
|
|
118
|
+
orderId: `ORDER${Date.now()}`,
|
|
119
|
+
desc: req.body.desc,
|
|
120
|
+
method: req.body.method,
|
|
121
|
+
email: req.body.email,
|
|
122
|
+
successUrl: `http://${req.headers.host}/success`,
|
|
123
|
+
failUrl: `http://${req.headers.host}/fail`,
|
|
124
|
+
notificationUrl: `http://${req.headers.host}/webhook/anypay`,
|
|
125
|
+
returnFormHtml: true // Form HTML'ini döndür
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (result.status === 'success') {
|
|
129
|
+
// HTML formunu doğrudan göster
|
|
130
|
+
console.log('Ödeme formu oluşturuldu');
|
|
131
|
+
res.send(`
|
|
132
|
+
<h1>AnyPay Ödeme Formu</h1>
|
|
133
|
+
<p>Sipariş No: ${result.data.pay_id}</p>
|
|
134
|
+
<div id="payment-form">${result.data.formHtml}</div>
|
|
135
|
+
<p><a href="/">Ana Sayfaya Dön</a></p>
|
|
136
|
+
<script>
|
|
137
|
+
// Form otomatik olarak gönderilsin
|
|
138
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
139
|
+
document.querySelector('form').submit();
|
|
140
|
+
});
|
|
141
|
+
</script>
|
|
142
|
+
`);
|
|
143
|
+
} else {
|
|
144
|
+
res.status(400).json({ error: 'Ödeme formu oluşturulamadı', details: result });
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error('Ödeme hatası:', error);
|
|
148
|
+
res.status(500).json({ error: error.message });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// API yöntemiyle ödeme oluşturma
|
|
153
|
+
app.post('/create-payment-api', async (req, res) => {
|
|
154
|
+
try {
|
|
155
|
+
const result = await quickPos.providers['anypay'].createPayment({
|
|
156
|
+
amount: req.body.amount,
|
|
157
|
+
currency: req.body.currency,
|
|
158
|
+
orderId: `ORDER${Date.now()}`,
|
|
159
|
+
desc: req.body.desc,
|
|
160
|
+
method: req.body.method,
|
|
161
|
+
email: req.body.email,
|
|
162
|
+
successUrl: `http://${req.headers.host}/success`,
|
|
163
|
+
failUrl: `http://${req.headers.host}/fail`,
|
|
164
|
+
notificationUrl: `http://${req.headers.host}/webhook/anypay`,
|
|
165
|
+
useApi: true // API yöntemini kullan
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (result.status === 'success') {
|
|
169
|
+
console.log('API ile ödeme bağlantısı oluşturuldu:', result.data.url);
|
|
170
|
+
res.redirect(result.data.url);
|
|
171
|
+
} else {
|
|
172
|
+
res.status(400).json({ error: 'API ile ödeme oluşturulamadı', details: result });
|
|
173
|
+
}
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error('API ödeme hatası:', error);
|
|
176
|
+
res.status(500).json({ error: error.message });
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Webhook işleme
|
|
181
|
+
app.post('/webhook/anypay', async (req, res) => {
|
|
182
|
+
try {
|
|
183
|
+
const notification = req.body;
|
|
184
|
+
const ipAddress = req.ip;
|
|
185
|
+
|
|
186
|
+
console.log('Webhook çağrısı alındı:', notification);
|
|
187
|
+
console.log('IP Adresi:', ipAddress);
|
|
188
|
+
|
|
189
|
+
// IP adresini kontrol et (isteğe bağlı)
|
|
190
|
+
const validIPs = ['185.162.128.38', '185.162.128.39', '185.162.128.88'];
|
|
191
|
+
if (!validIPs.includes(ipAddress)) {
|
|
192
|
+
console.warn('Uyarı: İstek bilinen bir Anypay IP adresinden gelmiyor');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// İmza doğrulaması
|
|
196
|
+
const isValid = quickPos.providers['anypay'].validateNotification(notification, ipAddress);
|
|
197
|
+
|
|
198
|
+
if (!isValid) {
|
|
199
|
+
console.error('Geçersiz imza veya IP adresi');
|
|
200
|
+
return res.status(400).send('Invalid signature or IP');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// İşlemi doğrula ve işle
|
|
204
|
+
const paymentResult = await quickPos.providers['anypay'].handleCallback(notification);
|
|
205
|
+
|
|
206
|
+
console.log('Ödeme sonucu:', paymentResult);
|
|
207
|
+
|
|
208
|
+
if (paymentResult.status === 'success') {
|
|
209
|
+
// Burada sipariş durumunu güncelleyebilir, veritabanı işlemleri yapabilirsiniz
|
|
210
|
+
console.log(`Ödeme başarılı: Sipariş #${paymentResult.orderId}, Tutar: ${paymentResult.amount} ${paymentResult.currency}`);
|
|
211
|
+
|
|
212
|
+
// AnyPay başarılı yanıt bekliyor
|
|
213
|
+
res.send('OK');
|
|
214
|
+
} else {
|
|
215
|
+
// Başarısız işlem
|
|
216
|
+
res.status(400).send('FAIL');
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error('Webhook hatası:', error);
|
|
220
|
+
res.status(500).send('ERROR');
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// Başarılı ödeme sayfası
|
|
225
|
+
app.get('/success', (req, res) => {
|
|
226
|
+
res.send('<h1>Ödemeniz başarıyla tamamlandı!</h1><a href="/">Ana Sayfaya Dön</a>');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Başarısız ödeme sayfası
|
|
230
|
+
app.get('/fail', (req, res) => {
|
|
231
|
+
res.send('<h1>Ödeme işlemi başarısız oldu!</h1><a href="/">Tekrar Deneyin</a>');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Bakiye sorgulama
|
|
235
|
+
app.get('/balance', async (req, res) => {
|
|
236
|
+
try {
|
|
237
|
+
const balance = await quickPos.providers['anypay'].getBalance();
|
|
238
|
+
res.json(balance);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
res.status(500).json({ error: error.message });
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Döviz kurları
|
|
245
|
+
app.get('/rates', async (req, res) => {
|
|
246
|
+
try {
|
|
247
|
+
const rates = await quickPos.providers['anypay'].getRates();
|
|
248
|
+
|
|
249
|
+
res.send(`
|
|
250
|
+
<h1>AnyPay Döviz Kurları</h1>
|
|
251
|
+
<h2>Giriş Kurları (In)</h2>
|
|
252
|
+
<pre>${JSON.stringify(rates.in, null, 2)}</pre>
|
|
253
|
+
<h2>Çıkış Kurları (Out)</h2>
|
|
254
|
+
<pre>${JSON.stringify(rates.out, null, 2)}</pre>
|
|
255
|
+
<p><a href="/">Ana Sayfaya Dön</a></p>
|
|
256
|
+
`);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
res.status(500).json({ error: error.message });
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// Komisyon oranları
|
|
263
|
+
app.get('/commissions', async (req, res) => {
|
|
264
|
+
try {
|
|
265
|
+
const commissions = await quickPos.providers['anypay'].getCommissions();
|
|
266
|
+
res.send(`
|
|
267
|
+
<h1>AnyPay Komisyon Oranları</h1>
|
|
268
|
+
<pre>${JSON.stringify(commissions, null, 2)}</pre>
|
|
269
|
+
<p><a href="/">Ana Sayfaya Dön</a></p>
|
|
270
|
+
`);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
res.status(500).json({ error: error.message });
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Bildirim IP adresleri
|
|
277
|
+
app.get('/notification-ips', async (req, res) => {
|
|
278
|
+
try {
|
|
279
|
+
const ips = await quickPos.providers['anypay'].getNotificationIPs();
|
|
280
|
+
res.send(`
|
|
281
|
+
<h1>AnyPay Bildirim IP Adresleri</h1>
|
|
282
|
+
<p>Şu IP adreslerinden gelen bildirimler kabul edilmeli:</p>
|
|
283
|
+
<ul>
|
|
284
|
+
${ips.ip.map(ip => `<li>${ip}</li>`).join('')}
|
|
285
|
+
</ul>
|
|
286
|
+
<p><a href="/">Ana Sayfaya Dön</a></p>
|
|
287
|
+
`);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
res.status(500).json({ error: error.message });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// Ödemeleri listeleme
|
|
294
|
+
app.get('/payments', async (req, res) => {
|
|
295
|
+
try {
|
|
296
|
+
const payments = await quickPos.providers['anypay'].getPayments({
|
|
297
|
+
offset: 0,
|
|
298
|
+
count: 10
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
res.send(`
|
|
302
|
+
<h1>Son Ödemeler</h1>
|
|
303
|
+
<p>Toplam Ödeme: ${payments.total}</p>
|
|
304
|
+
<table border="1" cellpadding="5" cellspacing="0">
|
|
305
|
+
<tr>
|
|
306
|
+
<th>İşlem ID</th>
|
|
307
|
+
<th>Sipariş ID</th>
|
|
308
|
+
<th>Tutar</th>
|
|
309
|
+
<th>Para Birimi</th>
|
|
310
|
+
<th>Durum</th>
|
|
311
|
+
<th>Tarih</th>
|
|
312
|
+
</tr>
|
|
313
|
+
${payments.payments.map(p => `
|
|
314
|
+
<tr>
|
|
315
|
+
<td>${p.transaction_id}</td>
|
|
316
|
+
<td>${p.pay_id}</td>
|
|
317
|
+
<td>${p.amount}</td>
|
|
318
|
+
<td>${p.currency}</td>
|
|
319
|
+
<td>${p.status}</td>
|
|
320
|
+
<td>${p.date}</td>
|
|
321
|
+
</tr>
|
|
322
|
+
`).join('')}
|
|
323
|
+
</table>
|
|
324
|
+
<p><a href="/">Ana Sayfaya Dön</a></p>
|
|
325
|
+
`);
|
|
326
|
+
} catch (error) {
|
|
327
|
+
res.status(500).json({ error: error.message });
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const PORT = process.env.PORT || 80;
|
|
332
|
+
app.listen(PORT, () => {
|
|
333
|
+
console.log(`Server ${PORT} portunda çalışıyor`);
|
|
334
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
const express = require('express');
|
|
3
|
+
const bodyParser = require('body-parser');
|
|
4
|
+
const QuickPos = require('./app');
|
|
5
|
+
|
|
6
|
+
const app = express();
|
|
7
|
+
app.use(bodyParser.urlencoded({ extended: true }));
|
|
8
|
+
app.use(require('multer')().none());
|
|
9
|
+
|
|
10
|
+
const quickPos = new QuickPos({
|
|
11
|
+
providers: {
|
|
12
|
+
cryptomus: {
|
|
13
|
+
merchantId: 'xxxx',
|
|
14
|
+
paymentKey: 'xxxxx'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
app.use(quickPos.middleware());
|
|
20
|
+
|
|
21
|
+
quickPos.providers['cryptomus'].createPayment({
|
|
22
|
+
orderId: `ST${Date.now()}`,
|
|
23
|
+
amount: String(123), //Sağlayıcı String istiyor.
|
|
24
|
+
currency: 'USD',
|
|
25
|
+
network: 'ETH',
|
|
26
|
+
callbackUrl: 'https://yourdomain.com/webhook',
|
|
27
|
+
returnUrl: 'https://yourdomain.com/return',
|
|
28
|
+
lifetime: 3600,
|
|
29
|
+
toCurrency: 'ETH'
|
|
30
|
+
})
|
|
31
|
+
.then(response => console.log(response))
|
|
32
|
+
.catch(error => console.error(error));
|
|
33
|
+
|
|
34
|
+
app.post('/cryptomusWebhook', quickPos.handleCallback('cryptomus'), (req, res) => {
|
|
35
|
+
console.log('Payment result:', req.paymentResult);
|
|
36
|
+
|
|
37
|
+
res.json({ status: 'success' });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
app.listen(3000, () => console.log('Server started on http://localhost:3000'));
|
|
@@ -0,0 +1,254 @@
|
|
|
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
|
+
esnekpos: {
|
|
12
|
+
merchant: 'TEST1234',
|
|
13
|
+
merchantKey: '4oK26hK8MOXrIV1bzTRVPA==',
|
|
14
|
+
testMode: true,
|
|
15
|
+
debug: false
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.use(quickPos.middleware());
|
|
21
|
+
|
|
22
|
+
// Ana sayfa - Ödeme formu
|
|
23
|
+
app.get('/', (req, res) => {
|
|
24
|
+
res.send(`
|
|
25
|
+
<h1>EsnekPOS Ödeme Testi</h1>
|
|
26
|
+
<h2>Ortak Ödeme Sayfası</h2>
|
|
27
|
+
<form action="/create-common-payment" method="post">
|
|
28
|
+
<div>
|
|
29
|
+
<label>Tutar:</label>
|
|
30
|
+
<input type="text" name="amount" value="100.00" required>
|
|
31
|
+
</div>
|
|
32
|
+
<div>
|
|
33
|
+
<label>Para Birimi:</label>
|
|
34
|
+
<select name="currency" required>
|
|
35
|
+
<option value="TRY">TRY</option>
|
|
36
|
+
<option value="USD">USD</option>
|
|
37
|
+
<option value="EUR">EUR</option>
|
|
38
|
+
</select>
|
|
39
|
+
</div>
|
|
40
|
+
<div>
|
|
41
|
+
<label>Sipariş Numarası:</label>
|
|
42
|
+
<input type="text" name="orderId" value="ORDER-${Date.now()}" required>
|
|
43
|
+
</div>
|
|
44
|
+
<div>
|
|
45
|
+
<label>Açıklama:</label>
|
|
46
|
+
<input type="text" name="description" value="Test ödemesi" required>
|
|
47
|
+
</div>
|
|
48
|
+
<div>
|
|
49
|
+
<label>E-posta:</label>
|
|
50
|
+
<input type="email" name="email" value="musteri@example.com" required>
|
|
51
|
+
</div>
|
|
52
|
+
<button type="submit">Ortak Ödeme Sayfası Oluştur</button>
|
|
53
|
+
</form>
|
|
54
|
+
|
|
55
|
+
<hr>
|
|
56
|
+
|
|
57
|
+
<h2>3D Secure Ödeme</h2>
|
|
58
|
+
<form action="/create-3d-payment" method="post">
|
|
59
|
+
<div>
|
|
60
|
+
<label>Tutar:</label>
|
|
61
|
+
<input type="text" name="amount" value="100.00" required>
|
|
62
|
+
</div>
|
|
63
|
+
<div>
|
|
64
|
+
<label>Para Birimi:</label>
|
|
65
|
+
<select name="currency" required>
|
|
66
|
+
<option value="TRY">TRY</option>
|
|
67
|
+
<option value="USD">USD</option>
|
|
68
|
+
<option value="EUR">EUR</option>
|
|
69
|
+
</select>
|
|
70
|
+
</div>
|
|
71
|
+
<div>
|
|
72
|
+
<label>Sipariş Numarası:</label>
|
|
73
|
+
<input type="text" name="orderId" value="ORDER-${Date.now()}" required>
|
|
74
|
+
</div>
|
|
75
|
+
<div>
|
|
76
|
+
<label>Açıklama:</label>
|
|
77
|
+
<input type="text" name="description" value="Test ödemesi" required>
|
|
78
|
+
</div>
|
|
79
|
+
<div>
|
|
80
|
+
<label>E-posta:</label>
|
|
81
|
+
<input type="email" name="email" value="musteri@example.com" required>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<h3>Kart Bilgileri</h3>
|
|
85
|
+
<div>
|
|
86
|
+
<label>Kart Numarası:</label>
|
|
87
|
+
<input type="text" name="cardNumber" value="4159562885391991" required>
|
|
88
|
+
</div>
|
|
89
|
+
<div>
|
|
90
|
+
<label>Son Kullanma Ay:</label>
|
|
91
|
+
<input type="text" name="expireMonth" value="12" required>
|
|
92
|
+
</div>
|
|
93
|
+
<div>
|
|
94
|
+
<label>Son Kullanma Yıl:</label>
|
|
95
|
+
<input type="text" name="expireYear" value="2025" required>
|
|
96
|
+
</div>
|
|
97
|
+
<div>
|
|
98
|
+
<label>CVV:</label>
|
|
99
|
+
<input type="text" name="cvv" value="123" required>
|
|
100
|
+
</div>
|
|
101
|
+
<div>
|
|
102
|
+
<label>Kart Sahibi:</label>
|
|
103
|
+
<input type="text" name="cardOwner" value="John Doe" required>
|
|
104
|
+
</div>
|
|
105
|
+
<div>
|
|
106
|
+
<label>Taksit Sayısı:</label>
|
|
107
|
+
<select name="installment">
|
|
108
|
+
<option value="1">Tek Çekim</option>
|
|
109
|
+
<option value="2">2 Taksit</option>
|
|
110
|
+
<option value="3">3 Taksit</option>
|
|
111
|
+
<option value="6">6 Taksit</option>
|
|
112
|
+
</select>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<button type="submit">3D Secure Ödeme Başlat</button>
|
|
116
|
+
</form>
|
|
117
|
+
`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Ortak ödeme sayfası oluşturma rotası
|
|
121
|
+
app.post('/create-common-payment', async (req, res) => {
|
|
122
|
+
try {
|
|
123
|
+
const result = await quickPos.providers['esnekpos'].createPayment({
|
|
124
|
+
amount: req.body.amount,
|
|
125
|
+
currency: req.body.currency,
|
|
126
|
+
orderId: req.body.orderId,
|
|
127
|
+
description: req.body.description,
|
|
128
|
+
email: req.body.email,
|
|
129
|
+
ip: '195.142.21.81', // Opsiyonel
|
|
130
|
+
phone: '5555555555',
|
|
131
|
+
city: 'İstanbul',
|
|
132
|
+
state: 'Kadıköy',
|
|
133
|
+
address: 'Örnek Mahallesi, Örnek Sokak No: 1',
|
|
134
|
+
name: 'Müşteri',
|
|
135
|
+
surname: 'Test',
|
|
136
|
+
callbackUrl: `http://${req.headers.host}/webhook-callback`
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
if (result.status === 'success') {
|
|
140
|
+
console.log('Ödeme sayfası başarıyla oluşturuldu:', result.data);
|
|
141
|
+
// Ödeme sayfası başarıyla oluşturuldu: {
|
|
142
|
+
// transactionId: 'ORDER-1742140882252',
|
|
143
|
+
// url: 'https://postest.esnekpos.com/Pages/CommonPaymentNew.aspx?hash=837e4aafc61c9e1e9a074922b165fd540b0e4374db4740c511b51f5efb3b9b49',
|
|
144
|
+
// id: '29386',
|
|
145
|
+
// html: null
|
|
146
|
+
// }
|
|
147
|
+
res.redirect(result.data.url);
|
|
148
|
+
} else {
|
|
149
|
+
res.status(400).json({ error: 'Ödeme sayfası oluşturulamadı', details: result });
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('Ödeme sayfası oluşturma hatası:', error);
|
|
153
|
+
res.status(500).json({ error: error.message });
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// 3D Secure ödeme başlatma rotası
|
|
158
|
+
app.post('/create-3d-payment', async (req, res) => {
|
|
159
|
+
try {
|
|
160
|
+
const result = await quickPos.providers['esnekpos'].createPayment({
|
|
161
|
+
amount: req.body.amount,
|
|
162
|
+
currency: req.body.currency,
|
|
163
|
+
orderId: req.body.orderId,
|
|
164
|
+
description: req.body.description,
|
|
165
|
+
email: req.body.email,
|
|
166
|
+
name: 'Müşteri',
|
|
167
|
+
surname: 'Test',
|
|
168
|
+
callbackUrl: `http://${req.headers.host}/webhook-callback`,
|
|
169
|
+
creditCard: {
|
|
170
|
+
number: req.body.cardNumber,
|
|
171
|
+
expireMonth: req.body.expireMonth,
|
|
172
|
+
expireYear: req.body.expireYear,
|
|
173
|
+
cvv: req.body.cvv,
|
|
174
|
+
owner: req.body.cardOwner,
|
|
175
|
+
installment: req.body.installment
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (result.status === 'success') {
|
|
180
|
+
console.log('3D Secure ödeme başarıyla başlatıldı:', result.data);
|
|
181
|
+
|
|
182
|
+
if (result.data.html) {
|
|
183
|
+
// 3D Secure form HTML'i varsa göster
|
|
184
|
+
res.send(`
|
|
185
|
+
<h1>3D Secure İşlemi</h1>
|
|
186
|
+
<p>3D Secure doğrulama sayfasına yönlendiriliyorsunuz...</p>
|
|
187
|
+
${result.data.html}
|
|
188
|
+
`);
|
|
189
|
+
} else {
|
|
190
|
+
// URL varsa yönlendir
|
|
191
|
+
res.redirect(result.data.url);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
res.status(400).json({ error: 'Ödeme başlatılamadı', details: result });
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error('Ödeme başlatma hatası:', error);
|
|
198
|
+
res.status(500).json({ error: error.message });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Webhook callback
|
|
203
|
+
app.post('/webhook-callback', quickPos.handleCallback('esnekpos'), (req, res) => {
|
|
204
|
+
try {
|
|
205
|
+
console.log('Ödeme sonucu:', req.paymentResult);
|
|
206
|
+
// Ödeme sonucu: {
|
|
207
|
+
// status: 'success',
|
|
208
|
+
// orderId: 'ORDER-1742140882252',
|
|
209
|
+
// transactionId: 'ORDER-1742140882252',
|
|
210
|
+
// amount: 101,
|
|
211
|
+
// currency: 'TRY',
|
|
212
|
+
// paymentType: 'creditcard',
|
|
213
|
+
// date: '2025-03-16T16:12:32.022Z'
|
|
214
|
+
// }
|
|
215
|
+
if (req.paymentResult && req.paymentResult.status === 'success') {
|
|
216
|
+
// Burada ödemeyi onaylayabilir, veritabanına kaydedebilirsiniz
|
|
217
|
+
res.status(200).send('OK');
|
|
218
|
+
} else {
|
|
219
|
+
console.error('Ödeme başarısız:', req.paymentResult || 'Sonuç yok');
|
|
220
|
+
res.status(400).send('Payment failed');
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.error('Webhook hatası:', error);
|
|
224
|
+
res.status(500).send('Internal Server Error');
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Ödeme durumu sorgulama
|
|
229
|
+
app.get('/check-payment/:orderRefNumber', async (req, res) => {
|
|
230
|
+
try {
|
|
231
|
+
const result = await quickPos.providers['esnekpos'].getPaymentStatus(req.params.orderRefNumber);
|
|
232
|
+
res.json(result);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
console.error('Ödeme sorgulama hatası:', error);
|
|
235
|
+
res.status(500).json({ error: error.message });
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// İade işlemi
|
|
240
|
+
app.post('/refund-payment', async (req, res) => {
|
|
241
|
+
try {
|
|
242
|
+
const { orderRefNumber, amount } = req.body;
|
|
243
|
+
const result = await quickPos.providers['esnekpos'].refundPayment(orderRefNumber, amount);
|
|
244
|
+
res.json(result);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
console.error('İade işlemi hatası:', error);
|
|
247
|
+
res.status(500).json({ error: error.message });
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const PORT = process.env.PORT || 80;
|
|
252
|
+
app.listen(PORT, () => {
|
|
253
|
+
console.log(`Server ${PORT} portunda çalışıyor`);
|
|
254
|
+
});
|