-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-payeer.js
74 lines (66 loc) · 1.86 KB
/
example-payeer.js
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
const express = require('express');
const bodyParser = require('body-parser');
const QuickPos = require('quickpos');
const app = express();
app.use(bodyParser.json({ limit: '50mb', extended: true }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(require('multer')().none());
const quickPos = new QuickPos({
providers: {
payeer: {
m_shop: 'XXXX',
m_key: 'XXXXXX'
}
}
});
app.use(quickPos.middleware());
app.use(async (req, res, next) => {
console.log('Middleware çalıştı');
console.log(req.method, req.url);
next();
});
(async () => {
const payment = await quickPos.providers['payeer'].createPayment({
orderId: 'S12345',
amount: '0.01',
currency: 'RUB',
description: 'Test payment'
});
console.log(payment);
})();
app.post('/status', quickPos.handleCallback('payeer'), async (req, res) => {
/*
POST /status
{
status: 'success',
orderId: 'S12345',
amount: '0.01',
currency: 'RUB',
operationId: '2175845325',
paymentDate: '29.12.2024 20:37:43'
}
Ödeme başarılı: {
status: 'success',
orderId: 'S12345',
amount: '0.01',
currency: 'RUB',
operationId: 'xxxx',
paymentDate: '29.12.2024 20:37:43'
}
*/
console.log(req.paymentResult);
try {
if (req.paymentResult.status === 'success') {
console.log('Ödeme başarılı:', req.paymentResult);
} else {
console.error('Ödeme başarısız:', req.paymentResult);
}
} catch (error) {
console.error('Webhook hatası:', error);
res.status(400).json({error: error.message});
}
});
const PORT = 80;
app.listen(PORT, () => {
console.log(`Webhook server running on port ${PORT}`);
});