quickpos 1.0.909 → 1.0.910
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/example-heleket.js +22 -1
- package/lib/heleket.js +36 -0
- package/package.json +1 -1
package/example-heleket.js
CHANGED
|
@@ -6,7 +6,7 @@ const QuickPos = require('./app');
|
|
|
6
6
|
const quickPos = new QuickPos({
|
|
7
7
|
providers: {
|
|
8
8
|
heleket: {
|
|
9
|
-
merchantId: '6764fdb7-7a2c-4599-962e-',
|
|
9
|
+
merchantId: '6764fdb7-7a2c-4599-962e-fbac2bcd498',
|
|
10
10
|
apiKey: ''
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -54,9 +54,30 @@ function verifyWebhook() {
|
|
|
54
54
|
console.log('Webhook geçerli mi:', isValid);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// Webhook callback işleme örneği
|
|
58
|
+
async function handleCallbackExample() {
|
|
59
|
+
const webhookData = {
|
|
60
|
+
order_id: 'test-123',
|
|
61
|
+
transaction_id: 'tx-456789',
|
|
62
|
+
status: 'completed',
|
|
63
|
+
amount: '20',
|
|
64
|
+
currency: 'USDT',
|
|
65
|
+
network: 'tron',
|
|
66
|
+
sign: 'example-signature-here'
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const result = await heleket.handleCallback(webhookData);
|
|
71
|
+
console.log('Callback işleme sonucu:', result);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error('Callback işlenirken hata:', error.message);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
57
77
|
// Örnek fonksiyonları çalıştır
|
|
58
78
|
(async () => {
|
|
59
79
|
await createSampleInvoice();
|
|
60
80
|
// await getServices();
|
|
61
81
|
verifyWebhook();
|
|
82
|
+
handleCallbackExample();
|
|
62
83
|
})();
|
package/lib/heleket.js
CHANGED
|
@@ -110,6 +110,42 @@ class Heleket {
|
|
|
110
110
|
|
|
111
111
|
return receivedSign === expectedSign;
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Handle callback from Heleket webhook
|
|
116
|
+
* @param {object} webhookData - Webhook data received from Heleket
|
|
117
|
+
* @returns {object} - Processed payment result
|
|
118
|
+
*/
|
|
119
|
+
async handleCallback(webhookData) {
|
|
120
|
+
try {
|
|
121
|
+
// Verify signature first
|
|
122
|
+
const isValidSignature = this.verifyWebhookSignature(webhookData);
|
|
123
|
+
|
|
124
|
+
if (!isValidSignature) {
|
|
125
|
+
throw new Error("Heleket notification failed: invalid signature");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Clone webhook data to avoid modifying the original
|
|
129
|
+
const data = {...webhookData};
|
|
130
|
+
|
|
131
|
+
// Process successful payments
|
|
132
|
+
if (data.status === 'completed' || data.status === 'success') {
|
|
133
|
+
return {
|
|
134
|
+
status: 'success',
|
|
135
|
+
orderId: data.order_id,
|
|
136
|
+
transactionId: data.transaction_id || data.order_id,
|
|
137
|
+
amount: data.amount,
|
|
138
|
+
currency: data.currency,
|
|
139
|
+
network: data.network || null,
|
|
140
|
+
paymentType: 'crypto'
|
|
141
|
+
};
|
|
142
|
+
} else {
|
|
143
|
+
throw new Error(`Payment failed with status: ${data.status}`);
|
|
144
|
+
}
|
|
145
|
+
} catch (error) {
|
|
146
|
+
throw new Error(`Error in Heleket callback handling: ${error.message}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
113
149
|
}
|
|
114
150
|
|
|
115
151
|
module.exports = Heleket;
|