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.
- package/PROVIDERS-DETAILS.md +1544 -0
- package/examples/example-2checkout.js +78 -0
- package/examples/example-bitpay.js +83 -0
- package/examples/example-cardcom.js +80 -0
- package/examples/example-cashfree.js +109 -0
- package/examples/example-checkout.js +85 -0
- package/examples/example-coingate.js +101 -0
- package/examples/example-coinpayments.js +89 -0
- package/examples/example-doku.js +27 -0
- package/examples/example-epay.js +64 -0
- package/examples/example-epoint.js +91 -0
- package/examples/example-freekassa.js +26 -0
- package/examples/example-heleket.js +139 -0
- package/examples/example-konnect.js +227 -0
- package/examples/example-midtrans.js +80 -0
- package/examples/example-noonpayments.js +297 -0
- package/examples/example-nowpayments.js +289 -0
- package/examples/example-omise.js +27 -0
- package/examples/example-paycom.js +82 -0
- package/{example-paydisini.js → examples/example-paydisini.js} +1 -1
- package/examples/example-payid19.js +87 -0
- package/examples/example-paykun.js +29 -0
- package/examples/example-payme.js +202 -0
- package/examples/example-paymentwall.js +201 -0
- package/examples/example-paynet.js +104 -0
- package/examples/example-paynettr.js +18 -0
- package/examples/example-payoneer.js +74 -0
- package/examples/example-payop.js +351 -0
- package/examples/example-paypal.js +200 -0
- package/examples/example-payriff.js +89 -0
- package/examples/example-paysend.js +81 -0
- package/examples/example-payspace.js +103 -0
- package/examples/example-payssion.js +27 -0
- package/examples/example-paytabs.js +28 -0
- package/examples/example-paytm.js +78 -0
- package/examples/example-payuindia.js +108 -0
- package/examples/example-payulatam.js +75 -0
- package/examples/example-phonepe.js +27 -0
- package/examples/example-picpay.js +27 -0
- package/examples/example-plisio.js +84 -0
- package/examples/example-portwallet.js +90 -0
- package/examples/example-primepayments.js +250 -0
- package/examples/example-razorpay.js +30 -0
- package/examples/example-senangpay.js +28 -0
- package/examples/example-shurjopay.js +94 -0
- package/examples/example-toyyibpay.js +80 -0
- package/examples/example-tripay.js +89 -0
- package/examples/example-unitpay.js +26 -0
- package/examples/example-urway.js +28 -0
- package/examples/example-volet.js +80 -0
- package/examples/example-xendit.js +28 -0
- package/examples/example-yallapay.js +253 -0
- package/examples/example-yookassa.js +27 -0
- package/examples/example-youcanpay.js +28 -0
- package/examples/example-zarinpal.js +98 -0
- package/{example.js → examples/example.js} +1 -1
- package/lib/2checkout.js +165 -0
- package/lib/amazonpay.js +161 -0
- package/lib/bitpay.js +122 -0
- package/lib/cardcom.js +193 -0
- package/lib/cashfree.js +184 -0
- package/lib/checkout.js +248 -0
- package/lib/coinbase.js +150 -0
- package/lib/coingate.js +137 -0
- package/lib/coinpayments.js +245 -0
- package/lib/doku.js +173 -0
- package/lib/epay.js +175 -0
- package/lib/epoint.js +162 -0
- package/lib/freekassa.js +128 -0
- package/lib/heleket.js +67 -1
- package/lib/instamojo.js +158 -0
- package/lib/konnect.js +211 -0
- package/lib/midtrans.js +227 -0
- package/lib/noonpayments.js +650 -0
- package/lib/nowpayments.js +311 -0
- package/lib/omise.js +150 -0
- package/lib/paddle.js +180 -0
- package/lib/paycom.js +216 -0
- package/lib/payid19.js +211 -0
- package/lib/paykun.js +144 -0
- package/lib/payme.js +302 -0
- package/lib/paymentwall.js +205 -0
- package/lib/paynet.js +186 -0
- package/lib/paynettr.js +165 -0
- package/lib/payoneer.js +128 -0
- package/lib/payop.js +256 -0
- package/lib/paypal.js +542 -0
- package/lib/payriff.js +148 -0
- package/lib/paysend.js +189 -0
- package/lib/payspace.js +168 -0
- package/lib/payssion.js +177 -0
- package/lib/paytabs.js +145 -0
- package/lib/paytm.js +253 -0
- package/lib/payuindia.js +162 -0
- package/lib/payulatam.js +179 -0
- package/lib/perfectmoney.js +143 -0
- package/lib/phonepe.js +174 -0
- package/lib/picpay.js +119 -0
- package/lib/plisio.js +234 -0
- package/lib/portwallet.js +152 -0
- package/lib/primepayments.js +256 -0
- package/lib/razorpay.js +205 -0
- package/lib/senangpay.js +130 -0
- package/lib/shurjopay.js +159 -0
- package/lib/toyyibpay.js +151 -0
- package/lib/tripay.js +220 -0
- package/lib/unitpay.js +223 -0
- package/lib/urway.js +182 -0
- package/lib/volet.js +147 -0
- package/lib/xendit.js +206 -0
- package/lib/yallapay.js +279 -0
- package/lib/yookassa.js +193 -0
- package/lib/youcanpay.js +124 -0
- package/lib/zarinpal.js +157 -0
- package/package.json +138 -64
- package/readme.md +348 -105
- package/test.js +492 -0
- package/example-heleket.js +0 -83
- package/lib/vallet.js +0 -22
- /package/{example-anypay.js → examples/example-anypay.js} +0 -0
- /package/{example-bufpay.js → examples/example-bufpay.js} +0 -0
- /package/{example-cryptomus.js → examples/example-cryptomus.js} +0 -0
- /package/{example-esnekpos.js → examples/example-esnekpos.js} +0 -0
- /package/{example-fedapay.js → examples/example-fedapay.js} +0 -0
- /package/{example-iyzico.js → examples/example-iyzico.js} +0 -0
- /package/{example-papara.js → examples/example-papara.js} +0 -0
- /package/{example-payeer.js → examples/example-payeer.js} +0 -0
- /package/{example-paymaya.js → examples/example-paymaya.js} +0 -0
- /package/{example-shopier.js → examples/example-shopier.js} +0 -0
- /package/{ipaymu.js → examples/ipaymu.js} +0 -0
- /package/{oderopay.js → examples/oderopay.js} +0 -0
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* NOONPayments Ödeme Entegrasyonu
|
|
5
|
+
*
|
|
6
|
+
* Başlamadan önce:
|
|
7
|
+
* 1. NOONPayments hesabı oluşturun
|
|
8
|
+
* 2. BusinessId, AppName ve AppKey bilgilerinizi alın
|
|
9
|
+
* 3. Gerekli webhook URL'lerini ayarlayın
|
|
10
|
+
*/
|
|
11
|
+
class NOONPaymentsService {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config || {};
|
|
14
|
+
const requiredFields = ['businessId', 'appName', 'appKey'];
|
|
15
|
+
for (let field of requiredFields) {
|
|
16
|
+
if (!config[field]) throw new Error(`Missing required field: ${field}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.businessId = config.businessId;
|
|
20
|
+
this.appName = config.appName;
|
|
21
|
+
this.appKey = config.appKey;
|
|
22
|
+
|
|
23
|
+
// Sandbox veya Production modu seçimi
|
|
24
|
+
this.sandbox = config.sandbox || false;
|
|
25
|
+
|
|
26
|
+
// Region seçimi (global, sa veya eg)
|
|
27
|
+
this.region = config.region || '';
|
|
28
|
+
|
|
29
|
+
// API URL'ini ortama göre ayarla
|
|
30
|
+
let baseUrl = 'https://api';
|
|
31
|
+
if (this.sandbox) {
|
|
32
|
+
baseUrl = 'https://api-test';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Bölgeye göre endpoint ayarla
|
|
36
|
+
if (this.region === 'sa') {
|
|
37
|
+
baseUrl += '.sa';
|
|
38
|
+
} else if (this.region === 'eg') {
|
|
39
|
+
baseUrl += '.eg';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
baseUrl += '.noonpayments.com/payment/v1/';
|
|
43
|
+
|
|
44
|
+
this.baseUrl = config.baseUrl || baseUrl;
|
|
45
|
+
|
|
46
|
+
// Auth key oluştur
|
|
47
|
+
this.authKey = this._generateAuthKey();
|
|
48
|
+
|
|
49
|
+
// Debug modu
|
|
50
|
+
this.debug = config.debug || false;
|
|
51
|
+
|
|
52
|
+
if (this.debug) {
|
|
53
|
+
console.log(`NOONPayments API URL: ${this.baseUrl}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Base64 encoded auth key oluşturur
|
|
59
|
+
*/
|
|
60
|
+
_generateAuthKey() {
|
|
61
|
+
const authString = `${this.businessId}.${this.appName}:${this.appKey}`;
|
|
62
|
+
return Buffer.from(authString).toString('base64');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Ödeme başlatır
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} paymentDetails - Ödeme detayları
|
|
69
|
+
* @returns {Promise<Object>} Ödeme sonucu
|
|
70
|
+
*/
|
|
71
|
+
async createPayment(paymentDetails) {
|
|
72
|
+
try {
|
|
73
|
+
// Zorunlu alanları kontrol et
|
|
74
|
+
let requiredData = ['amount', 'currency', 'reference', 'name'];
|
|
75
|
+
for (let data of requiredData) {
|
|
76
|
+
if (!paymentDetails[data]) throw new Error(`Missing required data: ${data}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Ödeme verilerini hazırla
|
|
80
|
+
const paymentData = {
|
|
81
|
+
apiOperation: "INITIATE",
|
|
82
|
+
order: {
|
|
83
|
+
amount: paymentDetails.amount,
|
|
84
|
+
currency: paymentDetails.currency,
|
|
85
|
+
reference: paymentDetails.reference || `order-${Date.now()}`,
|
|
86
|
+
name: paymentDetails.name,
|
|
87
|
+
channel: paymentDetails.channel || "web",
|
|
88
|
+
category: paymentDetails.category || "pay"
|
|
89
|
+
},
|
|
90
|
+
configuration: {
|
|
91
|
+
tokenizeCc: paymentDetails.tokenizeCc || "true",
|
|
92
|
+
returnUrl: paymentDetails.returnUrl || "https://merchant.com/response",
|
|
93
|
+
locale: paymentDetails.locale || "en",
|
|
94
|
+
paymentAction: paymentDetails.paymentAction || "AUTHORIZE,SALE"
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// İsteğe bağlı alanları ekle
|
|
99
|
+
if (paymentDetails.billing) {
|
|
100
|
+
paymentData.billing = paymentDetails.billing;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (paymentDetails.shipping) {
|
|
104
|
+
paymentData.shipping = paymentDetails.shipping;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Kart bilgisi ekleme (PCI-DSS uyumlu direct integration için)
|
|
108
|
+
if (paymentDetails.cardData) {
|
|
109
|
+
paymentData.paymentData = {
|
|
110
|
+
type: "CARD",
|
|
111
|
+
data: paymentDetails.cardData
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Token kullanarak ödeme
|
|
116
|
+
if (paymentDetails.tokenIdentifier) {
|
|
117
|
+
paymentData.paymentData = {
|
|
118
|
+
type: "CARD",
|
|
119
|
+
data: {
|
|
120
|
+
tokenIdentifier: paymentDetails.tokenIdentifier
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Debug modunda istek detaylarını göster
|
|
126
|
+
if (this.debug) {
|
|
127
|
+
console.log('NOONPayments ödeme isteği hazırlanıyor:', JSON.stringify(paymentData, null, 2));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// API isteği gönder
|
|
131
|
+
const response = await axios({
|
|
132
|
+
method: 'POST',
|
|
133
|
+
url: `${this.baseUrl}order`,
|
|
134
|
+
headers: {
|
|
135
|
+
'Content-Type': 'application/json',
|
|
136
|
+
'Accept': 'application/json',
|
|
137
|
+
'Authorization': `Key ${this.authKey}`
|
|
138
|
+
},
|
|
139
|
+
data: paymentData
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const responseData = response.data;
|
|
143
|
+
|
|
144
|
+
// Debug modunda yanıt detaylarını göster
|
|
145
|
+
if (this.debug) {
|
|
146
|
+
console.log('NOONPayments API yanıtı:', JSON.stringify(responseData, null, 2));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Hata kontrolü
|
|
150
|
+
if (responseData.resultCode !== 0) {
|
|
151
|
+
throw new Error(`NOONPayments API error: ${responseData.resultMessage || 'Unknown error'}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// QR kod oluştur (isteğe bağlı)
|
|
155
|
+
let qrCode = null;
|
|
156
|
+
if (paymentDetails.generateQr && responseData.result.url) {
|
|
157
|
+
qrCode = await this.generateQrCode(responseData.result.url);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
status: 'success',
|
|
162
|
+
data: {
|
|
163
|
+
transactionId: responseData.result.order.id,
|
|
164
|
+
orderId: responseData.result.order.reference,
|
|
165
|
+
url: responseData.result.url,
|
|
166
|
+
id: responseData.result.order.id,
|
|
167
|
+
qr: qrCode
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (this.debug) {
|
|
172
|
+
console.error('NOONPayments API hatası:', error);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (error.response) {
|
|
176
|
+
console.error('Hata detayları:', {
|
|
177
|
+
statusCode: error.response.status,
|
|
178
|
+
statusText: error.response.statusText,
|
|
179
|
+
data: error.response.data
|
|
180
|
+
});
|
|
181
|
+
throw new Error(`NOONPayments API error (${error.response.status}): ${JSON.stringify(error.response.data)}`);
|
|
182
|
+
} else if (error.request) {
|
|
183
|
+
console.error('Yanıt alınamadı:', error.request);
|
|
184
|
+
throw new Error('No response received from NOONPayments API');
|
|
185
|
+
} else {
|
|
186
|
+
throw new Error(`Error in NOONPayments payment creation: ${error.message}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Ödeme durumunu kontrol eder
|
|
193
|
+
*
|
|
194
|
+
* @param {string} orderId - Sipariş ID
|
|
195
|
+
* @returns {Promise<Object>} İşlem durumu
|
|
196
|
+
*/
|
|
197
|
+
async getOrderStatus(orderId) {
|
|
198
|
+
try {
|
|
199
|
+
const response = await axios({
|
|
200
|
+
method: 'GET',
|
|
201
|
+
url: `${this.baseUrl}order/${orderId}`,
|
|
202
|
+
headers: {
|
|
203
|
+
'Content-Type': 'application/json',
|
|
204
|
+
'Accept': 'application/json',
|
|
205
|
+
'Authorization': `Key ${this.authKey}`
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const responseData = response.data;
|
|
210
|
+
|
|
211
|
+
if (this.debug) {
|
|
212
|
+
console.log('NOONPayments sipariş durumu:', JSON.stringify(responseData, null, 2));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
status: responseData.result.order.status === 'PAID' ? 'success' : responseData.result.order.status,
|
|
217
|
+
orderId: responseData.result.order.reference,
|
|
218
|
+
amount: responseData.result.order.amount,
|
|
219
|
+
currency: responseData.result.order.currency,
|
|
220
|
+
paymentDetails: responseData.result.paymentDetails || {},
|
|
221
|
+
transactions: responseData.result.transactions || []
|
|
222
|
+
};
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (this.debug) {
|
|
225
|
+
console.error('NOONPayments sipariş sorgulama hatası:', error);
|
|
226
|
+
}
|
|
227
|
+
throw new Error(`Error checking order status: ${error.message}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Sipariş referansına göre sipariş durumunu kontrol eder
|
|
233
|
+
*
|
|
234
|
+
* @param {string} orderReference - Sipariş referansı
|
|
235
|
+
* @returns {Promise<Object>} İşlem durumu
|
|
236
|
+
*/
|
|
237
|
+
async getOrderByReference(orderReference) {
|
|
238
|
+
try {
|
|
239
|
+
const response = await axios({
|
|
240
|
+
method: 'GET',
|
|
241
|
+
url: `${this.baseUrl}order/getbyreference/${orderReference}`,
|
|
242
|
+
headers: {
|
|
243
|
+
'Content-Type': 'application/json',
|
|
244
|
+
'Accept': 'application/json',
|
|
245
|
+
'Authorization': `Key ${this.authKey}`
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const responseData = response.data;
|
|
250
|
+
|
|
251
|
+
if (this.debug) {
|
|
252
|
+
console.log('NOONPayments sipariş durumu (referans ile):', JSON.stringify(responseData, null, 2));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
status: responseData.result.order.status === 'PAID' ? 'success' : responseData.result.order.status,
|
|
257
|
+
orderId: responseData.result.order.reference,
|
|
258
|
+
amount: responseData.result.order.amount,
|
|
259
|
+
currency: responseData.result.order.currency,
|
|
260
|
+
paymentDetails: responseData.result.paymentDetails || {},
|
|
261
|
+
transactions: responseData.result.transactions || []
|
|
262
|
+
};
|
|
263
|
+
} catch (error) {
|
|
264
|
+
if (this.debug) {
|
|
265
|
+
console.error('NOONPayments sipariş sorgulama hatası (referans ile):', error);
|
|
266
|
+
}
|
|
267
|
+
throw new Error(`Error checking order by reference: ${error.message}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* AUTHORIZE işlemi yapar
|
|
273
|
+
*
|
|
274
|
+
* @param {string} orderId - Sipariş ID
|
|
275
|
+
* @returns {Promise<Object>} İşlem sonucu
|
|
276
|
+
*/
|
|
277
|
+
async authorizePayment(orderId) {
|
|
278
|
+
try {
|
|
279
|
+
const requestData = {
|
|
280
|
+
apiOperation: "AUTHORIZE",
|
|
281
|
+
order: {
|
|
282
|
+
id: orderId
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const response = await axios({
|
|
287
|
+
method: 'POST',
|
|
288
|
+
url: `${this.baseUrl}order`,
|
|
289
|
+
headers: {
|
|
290
|
+
'Content-Type': 'application/json',
|
|
291
|
+
'Accept': 'application/json',
|
|
292
|
+
'Authorization': `Key ${this.authKey}`
|
|
293
|
+
},
|
|
294
|
+
data: requestData
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const responseData = response.data;
|
|
298
|
+
|
|
299
|
+
if (this.debug) {
|
|
300
|
+
console.log('NOONPayments yetkilendirme yanıtı:', JSON.stringify(responseData, null, 2));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Hata kontrolü
|
|
304
|
+
if (responseData.resultCode !== 0) {
|
|
305
|
+
throw new Error(`NOONPayments API error: ${responseData.resultMessage || 'Unknown error'}`);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
status: 'success',
|
|
310
|
+
data: {
|
|
311
|
+
transactionId: responseData.result.transaction.id,
|
|
312
|
+
orderId: responseData.result.order.reference,
|
|
313
|
+
orderStatus: responseData.result.order.status
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
} catch (error) {
|
|
317
|
+
if (this.debug) {
|
|
318
|
+
console.error('NOONPayments yetkilendirme hatası:', error);
|
|
319
|
+
}
|
|
320
|
+
throw new Error(`Error in payment authorization: ${error.message}`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* SALE işlemi yapar
|
|
326
|
+
*
|
|
327
|
+
* @param {string} orderId - Sipariş ID
|
|
328
|
+
* @returns {Promise<Object>} İşlem sonucu
|
|
329
|
+
*/
|
|
330
|
+
async salePayment(orderId) {
|
|
331
|
+
try {
|
|
332
|
+
const requestData = {
|
|
333
|
+
apiOperation: "SALE",
|
|
334
|
+
order: {
|
|
335
|
+
id: orderId
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const response = await axios({
|
|
340
|
+
method: 'POST',
|
|
341
|
+
url: `${this.baseUrl}order`,
|
|
342
|
+
headers: {
|
|
343
|
+
'Content-Type': 'application/json',
|
|
344
|
+
'Accept': 'application/json',
|
|
345
|
+
'Authorization': `Key ${this.authKey}`
|
|
346
|
+
},
|
|
347
|
+
data: requestData
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const responseData = response.data;
|
|
351
|
+
|
|
352
|
+
if (this.debug) {
|
|
353
|
+
console.log('NOONPayments sale yanıtı:', JSON.stringify(responseData, null, 2));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Hata kontrolü
|
|
357
|
+
if (responseData.resultCode !== 0) {
|
|
358
|
+
throw new Error(`NOONPayments API error: ${responseData.resultMessage || 'Unknown error'}`);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return {
|
|
362
|
+
status: 'success',
|
|
363
|
+
data: {
|
|
364
|
+
transactionId: responseData.result.transaction.id,
|
|
365
|
+
orderId: responseData.result.order.reference,
|
|
366
|
+
orderStatus: responseData.result.order.status
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
} catch (error) {
|
|
370
|
+
if (this.debug) {
|
|
371
|
+
console.error('NOONPayments sale hatası:', error);
|
|
372
|
+
}
|
|
373
|
+
throw new Error(`Error in payment sale: ${error.message}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* CAPTURE işlemi yapar (Authorization sonrası)
|
|
379
|
+
*
|
|
380
|
+
* @param {string} orderId - Sipariş ID
|
|
381
|
+
* @param {Object} transactionDetails - İşlem detayları
|
|
382
|
+
* @returns {Promise<Object>} İşlem sonucu
|
|
383
|
+
*/
|
|
384
|
+
async capturePayment(orderId, transactionDetails) {
|
|
385
|
+
try {
|
|
386
|
+
// Zorunlu alanları kontrol et
|
|
387
|
+
let requiredData = ['amount', 'currency'];
|
|
388
|
+
for (let data of requiredData) {
|
|
389
|
+
if (!transactionDetails[data]) throw new Error(`Missing required data: ${data}`);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const requestData = {
|
|
393
|
+
apiOperation: "CAPTURE",
|
|
394
|
+
order: {
|
|
395
|
+
id: orderId
|
|
396
|
+
},
|
|
397
|
+
transaction: {
|
|
398
|
+
amount: transactionDetails.amount,
|
|
399
|
+
currency: transactionDetails.currency,
|
|
400
|
+
finalCapture: transactionDetails.finalCapture || true,
|
|
401
|
+
description: transactionDetails.description || "Capture transaction"
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const response = await axios({
|
|
406
|
+
method: 'POST',
|
|
407
|
+
url: `${this.baseUrl}order`,
|
|
408
|
+
headers: {
|
|
409
|
+
'Content-Type': 'application/json',
|
|
410
|
+
'Accept': 'application/json',
|
|
411
|
+
'Authorization': `Key ${this.authKey}`
|
|
412
|
+
},
|
|
413
|
+
data: requestData
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
const responseData = response.data;
|
|
417
|
+
|
|
418
|
+
if (this.debug) {
|
|
419
|
+
console.log('NOONPayments capture yanıtı:', JSON.stringify(responseData, null, 2));
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Hata kontrolü
|
|
423
|
+
if (responseData.resultCode !== 0) {
|
|
424
|
+
throw new Error(`NOONPayments API error: ${responseData.resultMessage || 'Unknown error'}`);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
status: 'success',
|
|
429
|
+
data: {
|
|
430
|
+
transactionId: responseData.result.transaction.id,
|
|
431
|
+
orderId: responseData.result.order.reference,
|
|
432
|
+
orderStatus: responseData.result.order.status
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
} catch (error) {
|
|
436
|
+
if (this.debug) {
|
|
437
|
+
console.error('NOONPayments capture hatası:', error);
|
|
438
|
+
}
|
|
439
|
+
throw new Error(`Error in payment capture: ${error.message}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* REFUND işlemi yapar
|
|
445
|
+
*
|
|
446
|
+
* @param {string} orderId - Sipariş ID
|
|
447
|
+
* @param {Object} transactionDetails - İşlem detayları
|
|
448
|
+
* @returns {Promise<Object>} İşlem sonucu
|
|
449
|
+
*/
|
|
450
|
+
async refundPayment(orderId, transactionDetails) {
|
|
451
|
+
try {
|
|
452
|
+
// Zorunlu alanları kontrol et
|
|
453
|
+
let requiredData = ['amount', 'currency', 'targetTransactionId'];
|
|
454
|
+
for (let data of requiredData) {
|
|
455
|
+
if (!transactionDetails[data]) throw new Error(`Missing required data: ${data}`);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const requestData = {
|
|
459
|
+
apiOperation: "REFUND",
|
|
460
|
+
order: {
|
|
461
|
+
id: orderId
|
|
462
|
+
},
|
|
463
|
+
transaction: {
|
|
464
|
+
amount: transactionDetails.amount,
|
|
465
|
+
currency: transactionDetails.currency,
|
|
466
|
+
targetTransactionId: transactionDetails.targetTransactionId,
|
|
467
|
+
description: transactionDetails.description || "Refund transaction"
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
const response = await axios({
|
|
472
|
+
method: 'POST',
|
|
473
|
+
url: `${this.baseUrl}order`,
|
|
474
|
+
headers: {
|
|
475
|
+
'Content-Type': 'application/json',
|
|
476
|
+
'Accept': 'application/json',
|
|
477
|
+
'Authorization': `Key ${this.authKey}`
|
|
478
|
+
},
|
|
479
|
+
data: requestData
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
const responseData = response.data;
|
|
483
|
+
|
|
484
|
+
if (this.debug) {
|
|
485
|
+
console.log('NOONPayments refund yanıtı:', JSON.stringify(responseData, null, 2));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Hata kontrolü
|
|
489
|
+
if (responseData.resultCode !== 0) {
|
|
490
|
+
throw new Error(`NOONPayments API error: ${responseData.resultMessage || 'Unknown error'}`);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
status: 'success',
|
|
495
|
+
data: {
|
|
496
|
+
transactionId: responseData.result.transaction.id,
|
|
497
|
+
orderId: responseData.result.order.reference,
|
|
498
|
+
orderStatus: responseData.result.order.status
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
} catch (error) {
|
|
502
|
+
if (this.debug) {
|
|
503
|
+
console.error('NOONPayments refund hatası:', error);
|
|
504
|
+
}
|
|
505
|
+
throw new Error(`Error in payment refund: ${error.message}`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* CANCEL işlemi yapar
|
|
511
|
+
*
|
|
512
|
+
* @param {string} orderId - Sipariş ID
|
|
513
|
+
* @returns {Promise<Object>} İşlem sonucu
|
|
514
|
+
*/
|
|
515
|
+
async cancelPayment(orderId) {
|
|
516
|
+
try {
|
|
517
|
+
const requestData = {
|
|
518
|
+
apiOperation: "CANCEL",
|
|
519
|
+
order: {
|
|
520
|
+
id: orderId
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
const response = await axios({
|
|
525
|
+
method: 'POST',
|
|
526
|
+
url: `${this.baseUrl}order`,
|
|
527
|
+
headers: {
|
|
528
|
+
'Content-Type': 'application/json',
|
|
529
|
+
'Accept': 'application/json',
|
|
530
|
+
'Authorization': `Key ${this.authKey}`
|
|
531
|
+
},
|
|
532
|
+
data: requestData
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
const responseData = response.data;
|
|
536
|
+
|
|
537
|
+
if (this.debug) {
|
|
538
|
+
console.log('NOONPayments iptal yanıtı:', JSON.stringify(responseData, null, 2));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Hata kontrolü
|
|
542
|
+
if (responseData.resultCode !== 0) {
|
|
543
|
+
throw new Error(`NOONPayments API error: ${responseData.resultMessage || 'Unknown error'}`);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return {
|
|
547
|
+
status: 'success',
|
|
548
|
+
data: {
|
|
549
|
+
orderId: responseData.result.order.reference,
|
|
550
|
+
orderStatus: responseData.result.order.status
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
} catch (error) {
|
|
554
|
+
if (this.debug) {
|
|
555
|
+
console.error('NOONPayments iptal hatası:', error);
|
|
556
|
+
}
|
|
557
|
+
throw new Error(`Error in payment cancellation: ${error.message}`);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Webhook callback'ini işler
|
|
563
|
+
*
|
|
564
|
+
* @param {Object} callbackData - Callback verileri
|
|
565
|
+
* @returns {Promise<Object>} İşlem sonucu
|
|
566
|
+
*/
|
|
567
|
+
async handleCallback(callbackData) {
|
|
568
|
+
try {
|
|
569
|
+
// Debug modunda callback verilerini göster
|
|
570
|
+
if (this.debug) {
|
|
571
|
+
console.log('NOONPayments callback verileri:', JSON.stringify(callbackData, null, 2));
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Webhook verilerini doğrula
|
|
575
|
+
if (!callbackData.order || !callbackData.order.id) {
|
|
576
|
+
throw new Error("Missing required fields in callback data");
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Sipariş durumunu belirle
|
|
580
|
+
const orderStatus = callbackData.order.status;
|
|
581
|
+
|
|
582
|
+
// Ödeme durumunu orderStatus'a göre belirle
|
|
583
|
+
let paymentStatus = 'unknown';
|
|
584
|
+
if (orderStatus === 'PAID') {
|
|
585
|
+
paymentStatus = 'success';
|
|
586
|
+
} else if (orderStatus === 'CANCELLED') {
|
|
587
|
+
paymentStatus = 'cancelled';
|
|
588
|
+
} else if (orderStatus === 'FAILED') {
|
|
589
|
+
paymentStatus = 'failed';
|
|
590
|
+
} else if (orderStatus === 'AUTHORIZED') {
|
|
591
|
+
paymentStatus = 'authorized';
|
|
592
|
+
} else if (orderStatus === 'AUTHORIZED_FAILED') {
|
|
593
|
+
paymentStatus = 'authorization_failed';
|
|
594
|
+
} else if (orderStatus === 'CAPTURED') {
|
|
595
|
+
paymentStatus = 'captured';
|
|
596
|
+
} else if (orderStatus === 'CAPTURE_FAILED') {
|
|
597
|
+
paymentStatus = 'capture_failed';
|
|
598
|
+
} else if (orderStatus === 'REFUNDED') {
|
|
599
|
+
paymentStatus = 'refunded';
|
|
600
|
+
} else if (orderStatus === 'REFUND_FAILED') {
|
|
601
|
+
paymentStatus = 'refund_failed';
|
|
602
|
+
} else if (orderStatus === 'INITIATED') {
|
|
603
|
+
paymentStatus = 'initiated';
|
|
604
|
+
} else if (orderStatus === 'PAYMENT_INFO_ADDED') {
|
|
605
|
+
paymentStatus = 'payment_info_added';
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
return {
|
|
609
|
+
status: paymentStatus,
|
|
610
|
+
orderId: callbackData.order.reference,
|
|
611
|
+
merchant_oid: callbackData.order.id,
|
|
612
|
+
amount: callbackData.order.amount,
|
|
613
|
+
currency: callbackData.order.currency,
|
|
614
|
+
paymentType: 'noonpayments',
|
|
615
|
+
transactions: callbackData.transactions || []
|
|
616
|
+
};
|
|
617
|
+
} catch (error) {
|
|
618
|
+
if (this.debug) {
|
|
619
|
+
console.error('NOONPayments callback işleme hatası:', error);
|
|
620
|
+
}
|
|
621
|
+
throw new Error(`Error in NOONPayments callback handling: ${error.message}`);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Ödeme bağlantısı için QR kod oluşturur
|
|
627
|
+
*
|
|
628
|
+
* @param {string} paymentUrl - Ödeme URL'i
|
|
629
|
+
* @returns {Promise<string|null>} Base64 formatında QR kod
|
|
630
|
+
*/
|
|
631
|
+
async generateQrCode(paymentUrl) {
|
|
632
|
+
try {
|
|
633
|
+
const response = await axios.get('https://api.qrserver.com/v1/create-qr-code/', {
|
|
634
|
+
params: {
|
|
635
|
+
size: '300x300',
|
|
636
|
+
data: paymentUrl
|
|
637
|
+
},
|
|
638
|
+
responseType: 'arraybuffer'
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
const base64Image = Buffer.from(response.data, 'binary').toString('base64');
|
|
642
|
+
return `data:image/png;base64,${base64Image}`;
|
|
643
|
+
} catch (error) {
|
|
644
|
+
console.error('QR kod oluşturma hatası:', error);
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
module.exports = NOONPaymentsService;
|