diff --git a/apps/api/src/billing/billing.controller.ts b/apps/api/src/billing/billing.controller.ts index a346a12..d97df55 100644 --- a/apps/api/src/billing/billing.controller.ts +++ b/apps/api/src/billing/billing.controller.ts @@ -51,6 +51,89 @@ export class BillingController { throw new BadRequestException('Invalid payment provider'); } + /** + * PayMob Redirection Callback (Success/Fail) + * This handles the GET request when PayMob redirects the user back to our site + */ + @Get('callback/paymob') + @ApiOperation({ summary: 'PayMob Redirection Handler' }) + async handlePaymobCallback(@Query() query: any, @Req() req: any) { + this.logger.log(`🔄 PayMob Redirect Callback: ID ${query.id}, Success: ${query.success}`); + + // Fallback: If success=true, proactively fetch transaction details and upgrade + if (query.success === 'true' && query.id) { + try { + const txDetails = await this.paymobProvider.getTransactionDetails(query.id); + if (txDetails && txDetails.success === true) { + const extraDesc = txDetails.order?.shipping_data?.extra_description || ""; + const [tenantId, plan] = extraDesc.split('|'); + + if (tenantId) { + await this.billingService.processSuccessfulPayment( + query.id.toString(), + PaymentProvider.PAYMOB, + txDetails.amount_cents / 100, + { tenantId, plan: plan || 'PRO' } + ); + this.logger.log(`🚀 Immediate Activation triggered via Callback for Tenant ${tenantId}`); + } + } + } catch (e) { + this.logger.error(`Failed during immediate activation fallback: ${e.message}`); + } + } + + // Redirect back to dashboard with status + const targetUrl = `https://map-dashbord.intaleqapp.com/dashboard.html#billing?payment_status=${query.success === 'true' ? 'success' : 'failed'}&id=${query.id}`; + + return ` + + +
+ +تم تفعيل خطة PRO بنجاح. يتم الآن توجيهك إلى لوحة التحكم...
+ +Live traffic across all API endpoints
Deep insights into your API performance