From fb3bb6c77c36ef4ddabfa7214999f091a0fc204e Mon Sep 17 00:00:00 2001 From: sdarbinyan Date: Thu, 18 Jun 2026 15:09:56 +0400 Subject: [PATCH] submited --- src/app/pages/cart/cart.component.ts | 52 +++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/app/pages/cart/cart.component.ts b/src/app/pages/cart/cart.component.ts index 6e395f9..18aabbb 100644 --- a/src/app/pages/cart/cart.component.ts +++ b/src/app/pages/cart/cart.component.ts @@ -274,8 +274,13 @@ export class CartComponent implements OnDestroy { if (paymentStatus === 'COMPLETED' || paymentStatus === 'APPROVED' || paymentStatus === 'PAID' || paymentCode === 'SUCCESS') { this.paymentStatus.set('success'); this.stopPolling(); - // Clear cart but don't close popup - wait for email submission this.cartService.clearCart(); + + // Auto-submit purchase after 5 seconds + if (this.closeTimeout) clearTimeout(this.closeTimeout); + this.closeTimeout = setTimeout(() => { + this.autoSubmitPurchase(); + }, 5000); } // Continue checking for 3 minutes regardless of other statuses }, @@ -310,6 +315,51 @@ export class CartComponent implements OnDestroy { } } + private autoSubmitPurchase(): void { + const telegramUserId = this.getTelegramUserId(); + + // Telegram ID is mandatory + if (!telegramUserId) { + console.error('Cannot submit purchase: Telegram ID is required'); + this.emailSubmitting.set(false); + return; + } + + this.emailSubmitting.set(true); + + const emailData = { + email: '', + phone: '', + telegramUserId: telegramUserId, + items: this.paidItems.map((item: CartItem) => ({ + itemID: item.itemID, + name: item.name, + price: item.discount > 0 + ? item.price * (1 - item.discount / 100) + : item.price, + currency: item.currency, + quantity: item.quantity + })) + }; + + this.apiService.submitPurchaseEmail(emailData).subscribe({ + next: () => { + this.emailSubmitting.set(false); + this.closePaymentPopup(); + const lang = this.langService.currentLanguage(); + this.router.navigate([`/${lang}`]); + }, + error: (err) => { + console.error('Error submitting purchase:', err); + this.emailSubmitting.set(false); + // Still close popup and redirect even if submission fails + this.closePaymentPopup(); + const lang = this.langService.currentLanguage(); + this.router.navigate([`/${lang}`]); + } + }); + } + copyPaymentLink(): void { const url = this.paymentUrl(); if (url) {