bank type added
This commit is contained in:
@@ -2,6 +2,7 @@ import { Component, ChangeDetectionStrategy, signal, OnDestroy, inject } from '@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
||||
import { CartService, ApiService, LanguageService, AuthService } from '../../services';
|
||||
import { Item, CartItem, DeliveryOption } from '../../models';
|
||||
import { interval, of, Subscription } from 'rxjs';
|
||||
@@ -47,6 +48,9 @@ export class CartComponent implements OnDestroy {
|
||||
paymentStatus = signal<'creating' | 'waiting' | 'success' | 'timeout' | 'error' | null>('creating');
|
||||
qrCodeUrl = signal<string>('');
|
||||
paymentUrl = signal<string>('');
|
||||
bankPaymentUrl = signal<string>('');
|
||||
bankPaymentFrameUrl = signal<SafeResourceUrl | null>(null);
|
||||
showBankPaymentPopup = signal<boolean>(false);
|
||||
paymentId = signal<string>('');
|
||||
linkCopied = signal<boolean>(false);
|
||||
|
||||
@@ -68,7 +72,8 @@ export class CartComponent implements OnDestroy {
|
||||
private cartService: CartService,
|
||||
private apiService: ApiService,
|
||||
private router: Router,
|
||||
private langService: LanguageService
|
||||
private langService: LanguageService,
|
||||
private sanitizer: DomSanitizer
|
||||
) {
|
||||
this.items = this.cartService.items;
|
||||
this.itemCount = this.cartService.itemCount;
|
||||
@@ -175,6 +180,9 @@ export class CartComponent implements OnDestroy {
|
||||
this.paymentId.set('');
|
||||
this.qrCodeUrl.set('');
|
||||
this.paymentUrl.set('');
|
||||
this.bankPaymentUrl.set('');
|
||||
this.bankPaymentFrameUrl.set(null);
|
||||
this.showBankPaymentPopup.set(false);
|
||||
this.linkCopied.set(false);
|
||||
this.userEmail.set('');
|
||||
this.userPhone.set('');
|
||||
@@ -189,6 +197,7 @@ export class CartComponent implements OnDestroy {
|
||||
|
||||
closePaymentPopup(): void {
|
||||
this.showPaymentPopup.set(false);
|
||||
this.closeBankPaymentPopup();
|
||||
this.stopPolling();
|
||||
if (this.closeTimeout) {
|
||||
clearTimeout(this.closeTimeout);
|
||||
@@ -206,6 +215,9 @@ export class CartComponent implements OnDestroy {
|
||||
this.paymentId.set('');
|
||||
this.qrCodeUrl.set('');
|
||||
this.paymentUrl.set('');
|
||||
this.bankPaymentUrl.set('');
|
||||
this.bankPaymentFrameUrl.set(null);
|
||||
this.showBankPaymentPopup.set(false);
|
||||
this.linkCopied.set(false);
|
||||
this.createPayment();
|
||||
}
|
||||
@@ -228,9 +240,10 @@ export class CartComponent implements OnDestroy {
|
||||
const qrId = this.apiService.resolvePaymentQrId(response);
|
||||
const qrUrl = this.apiService.resolvePaymentQrUrl(response);
|
||||
const paymentLink = this.apiService.resolvePaymentLink(response);
|
||||
const bankUrl = this.apiService.resolveBankPaymentUrl(response);
|
||||
|
||||
if (!qrId || !qrUrl) {
|
||||
console.error('Payment response missing qr fields:', response);
|
||||
if (!qrId || (!qrUrl && !bankUrl)) {
|
||||
console.error('Payment response missing payment fields:', response);
|
||||
this.setPaymentError();
|
||||
return;
|
||||
}
|
||||
@@ -238,6 +251,7 @@ export class CartComponent implements OnDestroy {
|
||||
this.paymentId.set(qrId);
|
||||
this.qrCodeUrl.set(qrUrl);
|
||||
this.paymentUrl.set(paymentLink);
|
||||
this.bankPaymentUrl.set(bankUrl);
|
||||
|
||||
this.paymentStatus.set('waiting');
|
||||
this.startPolling();
|
||||
@@ -280,6 +294,7 @@ export class CartComponent implements OnDestroy {
|
||||
|
||||
if (paymentStatus === 'FAILED' || paymentStatus === 'EXPIRED' || paymentStatus === 'CANCELLED' || paymentStatus === 'REJECTED') {
|
||||
this.paymentStatus.set('timeout');
|
||||
this.closeBankPaymentPopup();
|
||||
this.stopPolling();
|
||||
if (this.closeTimeout) clearTimeout(this.closeTimeout);
|
||||
this.closeTimeout = setTimeout(() => {
|
||||
@@ -291,6 +306,7 @@ export class CartComponent implements OnDestroy {
|
||||
// Check if payment is successful
|
||||
if (paymentStatus === 'COMPLETED' || paymentStatus === 'APPROVED' || paymentStatus === 'PAID' || paymentCode === 'SUCCESS') {
|
||||
this.paymentStatus.set('success');
|
||||
this.closeBankPaymentPopup();
|
||||
this.stopPolling();
|
||||
// Auto-submit purchase after 5 seconds
|
||||
if (this.closeTimeout) clearTimeout(this.closeTimeout);
|
||||
@@ -308,6 +324,7 @@ export class CartComponent implements OnDestroy {
|
||||
// If all checks are done but payment not completed
|
||||
if (this.paymentStatus() === 'waiting') {
|
||||
this.paymentStatus.set('timeout');
|
||||
this.closeBankPaymentPopup();
|
||||
// Close popup after showing timeout message
|
||||
if (this.closeTimeout) clearTimeout(this.closeTimeout);
|
||||
this.closeTimeout = setTimeout(() => {
|
||||
@@ -325,8 +342,24 @@ export class CartComponent implements OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
openBankPaymentPopup(): void {
|
||||
const bankUrl = this.bankPaymentUrl();
|
||||
if (!bankUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bankPaymentFrameUrl.set(this.sanitizer.bypassSecurityTrustResourceUrl(bankUrl));
|
||||
this.showBankPaymentPopup.set(true);
|
||||
}
|
||||
|
||||
closeBankPaymentPopup(): void {
|
||||
this.showBankPaymentPopup.set(false);
|
||||
this.bankPaymentFrameUrl.set(null);
|
||||
}
|
||||
|
||||
private setPaymentError(): void {
|
||||
this.paymentStatus.set('error');
|
||||
this.closeBankPaymentPopup();
|
||||
this.stopPolling();
|
||||
if (this.closeTimeout) {
|
||||
clearTimeout(this.closeTimeout);
|
||||
|
||||
Reference in New Issue
Block a user