quickpos 1.0.909 → 1.0.911

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.
@@ -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--fbeac2bcd498',
10
10
  apiKey: ''
11
11
  }
12
12
  }
@@ -54,9 +54,86 @@ 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
+
77
+ // Örnek ödeme webhook'u test etme
78
+ async function testPaymentWebhookExample() {
79
+ try {
80
+ const result = await heleket.testPaymentWebhook({
81
+ url_callback: "https://test.speedsmm.com/api/payment/callback/heleket",
82
+ currency: "USDT",
83
+ network: "tron",
84
+ order_id: "aa5a7a7c-7aa3-4d9b-8dc7-ef45b6088d82",
85
+ status: "paid"
86
+ });
87
+
88
+ console.log('Ödeme webhook testi sonucu:', result);
89
+ } catch (error) {
90
+ console.error('Ödeme webhook testi sırasında hata:', error.message);
91
+ }
92
+ }
93
+ testPaymentWebhookExample();
94
+ // Örnek ödeme çıkışı webhook'u test etme
95
+ async function testPayoutWebhookExample() {
96
+ try {
97
+ const result = await heleket.testPayoutWebhook({
98
+ url_callback: "https://your-webhook-url.com/callback",
99
+ currency: "USDT",
100
+ network: "tron",
101
+ order_id: "test-5678",
102
+ status: "paid"
103
+ });
104
+
105
+ console.log('Ödeme çıkışı webhook testi sonucu:', result);
106
+ } catch (error) {
107
+ console.error('Ödeme çıkışı webhook testi sırasında hata:', error.message);
108
+ }
109
+ }
110
+
111
+ // Örnek cüzdan webhook'u test etme
112
+ async function testWalletWebhookExample() {
113
+ try {
114
+ const result = await heleket.testWalletWebhook({
115
+ url_callback: "https://your-webhook-url.com/callback",
116
+ currency: "USDT",
117
+ network: "tron",
118
+ uuid: "e1830f1b-50fc-432e-80ec-15b58ccac867",
119
+ status: "paid"
120
+ });
121
+
122
+ console.log('Cüzdan webhook testi sonucu:', result);
123
+ } catch (error) {
124
+ console.error('Cüzdan webhook testi sırasında hata:', error.message);
125
+ }
126
+ }
127
+
57
128
  // Örnek fonksiyonları çalıştır
58
129
  (async () => {
59
- await createSampleInvoice();
60
- // await getServices();
61
- verifyWebhook();
130
+ // await createSampleInvoice();
131
+ // // await getServices();
132
+ // verifyWebhook();
133
+ // handleCallbackExample();
134
+
135
+ // Test webhook fonksiyonlarını çalıştır
136
+ // await testPaymentWebhookExample();
137
+ // await testPayoutWebhookExample();
138
+ // await testWalletWebhookExample();
62
139
  })();
package/lib/heleket.js CHANGED
@@ -110,6 +110,108 @@ 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 === 'paid') {
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
+ }
149
+
150
+ /**
151
+ * Test payment webhook
152
+ * @param {object} params - Test parameters
153
+ * @param {string} params.url_callback - URL to which webhooks will be sent
154
+ * @param {string} params.currency - Invoice currency code
155
+ * @param {string} params.network - Invoice network code
156
+ * @param {string} [params.uuid] - UUID of the invoice
157
+ * @param {string} [params.order_id] - Order ID of the invoice
158
+ * @param {string} [params.status=paid] - Payment status
159
+ * @returns {Promise} - Promise resolving to test result
160
+ */
161
+ testPaymentWebhook(params) {
162
+ if (!params.url_callback || !params.currency || !params.network) {
163
+ throw new Error('Missing required parameters: url_callback, currency, network');
164
+ }
165
+
166
+ // Set default status if not provided
167
+ params.status = params.status || 'paid';
168
+
169
+ return this.request('/v1/test-webhook/payment', params);
170
+ }
171
+
172
+ /**
173
+ * Test payout webhook
174
+ * @param {object} params - Test parameters
175
+ * @param {string} params.url_callback - URL to which webhooks will be sent
176
+ * @param {string} params.currency - Payout currency code
177
+ * @param {string} params.network - Payout network code
178
+ * @param {string} [params.uuid] - UUID of the payout
179
+ * @param {string} [params.order_id] - Order ID of the payout
180
+ * @param {string} [params.status=paid] - Payout status
181
+ * @returns {Promise} - Promise resolving to test result
182
+ */
183
+ testPayoutWebhook(params) {
184
+ if (!params.url_callback || !params.currency || !params.network) {
185
+ throw new Error('Missing required parameters: url_callback, currency, network');
186
+ }
187
+
188
+ // Set default status if not provided
189
+ params.status = params.status || 'paid';
190
+
191
+ return this.request('/v1/test-webhook/payout', params);
192
+ }
193
+
194
+ /**
195
+ * Test wallet webhook
196
+ * @param {object} params - Test parameters
197
+ * @param {string} params.url_callback - URL to which webhooks will be sent
198
+ * @param {string} params.currency - Payment currency code
199
+ * @param {string} params.network - Payment network code
200
+ * @param {string} [params.uuid] - UUID of business wallet
201
+ * @param {string} [params.order_id] - Order ID of the invoice
202
+ * @param {string} [params.status=paid] - Payment status
203
+ * @returns {Promise} - Promise resolving to test result
204
+ */
205
+ testWalletWebhook(params) {
206
+ if (!params.url_callback || !params.currency || !params.network) {
207
+ throw new Error('Missing required parameters: url_callback, currency, network');
208
+ }
209
+
210
+ // Set default status if not provided
211
+ params.status = params.status || 'paid';
212
+
213
+ return this.request('/v1/test-webhook/wallet', params);
214
+ }
113
215
  }
114
216
 
115
217
  module.exports = Heleket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickpos",
3
- "version": "1.0.909",
3
+ "version": "1.0.911",
4
4
  "main": "app.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"