@duvdu-v1/duvdu 1.1.266 → 1.1.267
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.
|
@@ -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) {
|
|
@@ -296,14 +329,29 @@ class PaymobService {
|
|
|
296
329
|
* Get order details including metadata
|
|
297
330
|
*/
|
|
298
331
|
getOrderDetails(orderId) {
|
|
332
|
+
var _a, _b, _c;
|
|
299
333
|
return __awaiter(this, void 0, void 0, function* () {
|
|
300
334
|
try {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
335
|
+
// Try the Flash Integration API endpoint first
|
|
336
|
+
let response;
|
|
337
|
+
try {
|
|
338
|
+
response = yield axios_1.default.get(`${this.baseUrl}/v1/intention/orders/${orderId}`, {
|
|
339
|
+
headers: {
|
|
340
|
+
'Content-Type': 'application/json',
|
|
341
|
+
'Authorization': `Token ${this.secretKey}`,
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
catch (flashError) {
|
|
346
|
+
console.log('Flash API failed, trying legacy API...');
|
|
347
|
+
// Fallback to legacy API endpoint
|
|
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
|
+
}
|
|
307
355
|
return {
|
|
308
356
|
id: response.data.id,
|
|
309
357
|
amount_cents: response.data.amount_cents,
|
|
@@ -315,6 +363,21 @@ class PaymobService {
|
|
|
315
363
|
}
|
|
316
364
|
catch (error) {
|
|
317
365
|
const axiosError = error;
|
|
366
|
+
console.error('Order details error response:', (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
367
|
+
console.error('Order details error status:', (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.status);
|
|
368
|
+
// If still failing, provide a fallback that returns minimal data
|
|
369
|
+
if (((_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.status) === 401) {
|
|
370
|
+
console.log('Authentication failed, using fallback approach...');
|
|
371
|
+
// Return a minimal response that won't break the webhook
|
|
372
|
+
return {
|
|
373
|
+
id: orderId,
|
|
374
|
+
amount_cents: 0,
|
|
375
|
+
currency: 'EGP',
|
|
376
|
+
items: [],
|
|
377
|
+
created_at: new Date().toISOString(),
|
|
378
|
+
merchant_order_id: '', // Empty merchant_order_id will trigger fallback logic
|
|
379
|
+
};
|
|
380
|
+
}
|
|
318
381
|
throw new Error(`Failed to get order details: ${axiosError.message}`);
|
|
319
382
|
}
|
|
320
383
|
});
|