@duvdu-v1/duvdu 1.1.267 → 1.1.268
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.
|
@@ -192,7 +192,11 @@ export declare class PaymobService {
|
|
|
192
192
|
handleWebhookQuery(queryParams: Record<string, string>): WebhookResult<WebhookQueryTransactionData>;
|
|
193
193
|
getTransactionStatus(transactionId: number): Promise<TransactionStatusResult>;
|
|
194
194
|
/**
|
|
195
|
-
*
|
|
195
|
+
* Authenticate with Paymob to get Bearer token
|
|
196
|
+
*/
|
|
197
|
+
private authenticate;
|
|
198
|
+
/**
|
|
199
|
+
* Get order details including metadata using the correct Paymob API
|
|
196
200
|
*/
|
|
197
201
|
getOrderDetails(orderId: number): Promise<OrderDetailsResult>;
|
|
198
202
|
/**
|
|
@@ -326,47 +326,63 @@ class PaymobService {
|
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
|
-
*
|
|
329
|
+
* Authenticate with Paymob to get Bearer token
|
|
330
|
+
*/
|
|
331
|
+
authenticate() {
|
|
332
|
+
var _a;
|
|
333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
try {
|
|
335
|
+
const response = yield axios_1.default.post(`${this.baseUrl}/api/auth/tokens`, {
|
|
336
|
+
api_key: this.secretKey,
|
|
337
|
+
}, {
|
|
338
|
+
headers: {
|
|
339
|
+
'Content-Type': 'application/json',
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
return response.data.token;
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
const axiosError = error;
|
|
346
|
+
console.error('Authentication error:', (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
347
|
+
throw new Error(`Failed to authenticate with Paymob: ${axiosError.message}`);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Get order details including metadata using the correct Paymob API
|
|
330
353
|
*/
|
|
331
354
|
getOrderDetails(orderId) {
|
|
332
|
-
var _a, _b, _c;
|
|
355
|
+
var _a, _b, _c, _d, _e, _f;
|
|
333
356
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334
357
|
try {
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
response = yield axios_1.default.get(`${this.baseUrl}/api/ecommerce/orders/${orderId}`, {
|
|
349
|
-
headers: {
|
|
350
|
-
'Content-Type': 'application/json',
|
|
351
|
-
'Authorization': `Token ${this.secretKey}`,
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
}
|
|
358
|
+
// Step 1: Authenticate to get Bearer token
|
|
359
|
+
const authToken = yield this.authenticate();
|
|
360
|
+
// Step 2: Get transaction details using the order inquiry endpoint
|
|
361
|
+
const response = yield axios_1.default.post(`${this.baseUrl}/api/ecommerce/orders/transaction_inquiry`, {
|
|
362
|
+
order_id: orderId.toString(),
|
|
363
|
+
}, {
|
|
364
|
+
headers: {
|
|
365
|
+
'Content-Type': 'application/json',
|
|
366
|
+
'Authorization': `Bearer ${authToken}`,
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
// The response might contain transaction data, we need to extract order info
|
|
370
|
+
const transactionData = response.data;
|
|
355
371
|
return {
|
|
356
|
-
id:
|
|
357
|
-
amount_cents:
|
|
358
|
-
currency:
|
|
359
|
-
items:
|
|
360
|
-
created_at:
|
|
361
|
-
merchant_order_id:
|
|
372
|
+
id: orderId,
|
|
373
|
+
amount_cents: transactionData.amount_cents || 0,
|
|
374
|
+
currency: transactionData.currency || 'EGP',
|
|
375
|
+
items: ((_a = transactionData.order) === null || _a === void 0 ? void 0 : _a.items) || [],
|
|
376
|
+
created_at: transactionData.created_at || new Date().toISOString(),
|
|
377
|
+
merchant_order_id: ((_b = transactionData.order) === null || _b === void 0 ? void 0 : _b.merchant_order_id) || '',
|
|
362
378
|
};
|
|
363
379
|
}
|
|
364
380
|
catch (error) {
|
|
365
381
|
const axiosError = error;
|
|
366
|
-
console.error('Order details error response:', (
|
|
367
|
-
console.error('Order details error status:', (
|
|
382
|
+
console.error('Order details error response:', (_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.data);
|
|
383
|
+
console.error('Order details error status:', (_d = axiosError.response) === null || _d === void 0 ? void 0 : _d.status);
|
|
368
384
|
// If still failing, provide a fallback that returns minimal data
|
|
369
|
-
if (((
|
|
385
|
+
if (((_e = axiosError.response) === null || _e === void 0 ? void 0 : _e.status) === 401 || ((_f = axiosError.response) === null || _f === void 0 ? void 0 : _f.status) === 403) {
|
|
370
386
|
console.log('Authentication failed, using fallback approach...');
|
|
371
387
|
// Return a minimal response that won't break the webhook
|
|
372
388
|
return {
|