@duvdu-v1/duvdu 1.1.266 → 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
|
/**
|
|
@@ -117,15 +117,17 @@ class PaymobService {
|
|
|
117
117
|
* @returns The payment URL and related data
|
|
118
118
|
*/
|
|
119
119
|
createPaymentUrlWithUserData(amount, userId, contractId, userData, serviceType) {
|
|
120
|
+
var _a;
|
|
120
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
122
|
// Create metadata with custom data
|
|
122
|
-
const
|
|
123
|
+
const customData = {
|
|
123
124
|
contractId,
|
|
124
125
|
userId,
|
|
125
126
|
service_type: serviceType,
|
|
126
127
|
booking_id: 'BOOK_' + Date.now(),
|
|
127
128
|
timestamp: new Date().toISOString(),
|
|
128
129
|
};
|
|
130
|
+
const extras = customData;
|
|
129
131
|
const billingData = {
|
|
130
132
|
first_name: userData.firstName,
|
|
131
133
|
last_name: userData.lastName,
|
|
@@ -146,8 +148,39 @@ class PaymobService {
|
|
|
146
148
|
quantity: 1,
|
|
147
149
|
},
|
|
148
150
|
];
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
// For Flash Integration, we need to create a modified intention request
|
|
152
|
+
// that includes merchant_order_id
|
|
153
|
+
const intentionData = {
|
|
154
|
+
amount,
|
|
155
|
+
currency: 'EGP',
|
|
156
|
+
payment_methods: [this.integrationId, 'card'],
|
|
157
|
+
items,
|
|
158
|
+
billing_data: billingData,
|
|
159
|
+
customer: {
|
|
160
|
+
first_name: billingData.first_name,
|
|
161
|
+
last_name: billingData.last_name,
|
|
162
|
+
email: billingData.email,
|
|
163
|
+
extras: extras || {},
|
|
164
|
+
},
|
|
165
|
+
extras: extras || {},
|
|
166
|
+
merchant_order_id: JSON.stringify(customData), // Store custom data here
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
const response = yield axios_1.default.post(`${this.baseUrl}/v1/intention/`, intentionData, {
|
|
170
|
+
headers: {
|
|
171
|
+
'Authorization': `Token ${this.secretKey}`,
|
|
172
|
+
'Content-Type': 'application/json',
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
// Create the payment URL for Flash Checkout
|
|
176
|
+
const paymentUrl = `${this.baseUrl}/unifiedcheckout/?publicKey=${this.publicKey}&clientSecret=${response.data.client_secret}`;
|
|
177
|
+
return { paymentUrl };
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
const axiosError = error;
|
|
181
|
+
console.log('PayMob intention error:', (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
182
|
+
throw new Error(`Failed to create Paymob payment intention: ${axiosError.message}`);
|
|
183
|
+
}
|
|
151
184
|
});
|
|
152
185
|
}
|
|
153
186
|
verifyPayment(hmac, data) {
|
|
@@ -293,28 +326,74 @@ class PaymobService {
|
|
|
293
326
|
});
|
|
294
327
|
}
|
|
295
328
|
/**
|
|
296
|
-
*
|
|
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
|
|
297
353
|
*/
|
|
298
354
|
getOrderDetails(orderId) {
|
|
355
|
+
var _a, _b, _c, _d, _e, _f;
|
|
299
356
|
return __awaiter(this, void 0, void 0, function* () {
|
|
300
357
|
try {
|
|
301
|
-
|
|
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
|
+
}, {
|
|
302
364
|
headers: {
|
|
303
365
|
'Content-Type': 'application/json',
|
|
304
|
-
'Authorization': `
|
|
366
|
+
'Authorization': `Bearer ${authToken}`,
|
|
305
367
|
},
|
|
306
368
|
});
|
|
369
|
+
// The response might contain transaction data, we need to extract order info
|
|
370
|
+
const transactionData = response.data;
|
|
307
371
|
return {
|
|
308
|
-
id:
|
|
309
|
-
amount_cents:
|
|
310
|
-
currency:
|
|
311
|
-
items:
|
|
312
|
-
created_at:
|
|
313
|
-
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) || '',
|
|
314
378
|
};
|
|
315
379
|
}
|
|
316
380
|
catch (error) {
|
|
317
381
|
const axiosError = error;
|
|
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);
|
|
384
|
+
// If still failing, provide a fallback that returns minimal data
|
|
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) {
|
|
386
|
+
console.log('Authentication failed, using fallback approach...');
|
|
387
|
+
// Return a minimal response that won't break the webhook
|
|
388
|
+
return {
|
|
389
|
+
id: orderId,
|
|
390
|
+
amount_cents: 0,
|
|
391
|
+
currency: 'EGP',
|
|
392
|
+
items: [],
|
|
393
|
+
created_at: new Date().toISOString(),
|
|
394
|
+
merchant_order_id: '', // Empty merchant_order_id will trigger fallback logic
|
|
395
|
+
};
|
|
396
|
+
}
|
|
318
397
|
throw new Error(`Failed to get order details: ${axiosError.message}`);
|
|
319
398
|
}
|
|
320
399
|
});
|