diff --git a/src/app/carnet/checkout/checkout.component.ts b/src/app/carnet/checkout/checkout.component.ts index 7572591..f8e1926 100644 --- a/src/app/carnet/checkout/checkout.component.ts +++ b/src/app/carnet/checkout/checkout.component.ts @@ -47,7 +47,7 @@ export class CheckoutComponent { constructor() { this.currentApplicationDetails = this.storageService.get<{ headerid: number, applicationName: string, applicationType: string }>('currentapplication') - this.orderDetails.description = ` 'Carnet Application - ${this.currentApplicationDetails?.applicationName}` + this.orderDetails.description = ` 'Carnet Application - ${this.currentApplicationDetails?.headerid} - ${this.currentApplicationDetails?.applicationName}` } ngOnInit(): void { @@ -114,8 +114,6 @@ export class CheckoutComponent { // data.orderID is the ID of the transaction from PayPal const captureDetails = await this.paymentService.completePayment(data.orderID); - // console.log('Capture details:', captureDetails); - // You can now redirect the user or update the UI this.changeInProgress = true; this.carnetService.submitApplication(this.currentApplicationDetails?.headerid!).pipe(finalize(() => { @@ -146,6 +144,7 @@ export class CheckoutComponent { // 4. Handle cancellation onCancel: (data: any) => { + this.onCancel(); } }).render(this.paypalElement.nativeElement) .catch((error: any) => { @@ -158,5 +157,29 @@ export class CheckoutComponent { (fee): fee is number => typeof fee === 'number' ); this.orderTotal = validFees.reduce((total, fee) => total + fee, 0); + this.orderDetails.price = this.orderTotal?.toString() ?? '0.00'; + } + + onCancel(): void { + this.storageService.removeItem('currentapplication'); + + let route: string = 'edit-carnet'; + if (this.currentApplicationDetails?.applicationType === 'duplicate') { + route = 'duplicate-carnet'; + } + else if (this.currentApplicationDetails?.applicationType === 'extend') { + route = 'extend-carnet'; + } else if (this.currentApplicationDetails?.applicationType === 'additional') { + route = 'additional-sets'; + } + + this.navigationService.navigate([route, this.currentApplicationDetails?.headerid], + { + state: { isEditMode: true }, + queryParams: { + applicationname: this.currentApplicationDetails?.applicationName, + return: 'shipping' + } + }) } } \ No newline at end of file diff --git a/src/app/core/services/carnet/payment.service.ts b/src/app/core/services/carnet/payment.service.ts index 1218014..0635983 100644 --- a/src/app/core/services/carnet/payment.service.ts +++ b/src/app/core/services/carnet/payment.service.ts @@ -13,8 +13,13 @@ export class PaymentService { private http = inject(HttpClient); createOrder(orderDetails: any): Promise { + const data = { + P_PRICE: orderDetails.price, + P_DESCRIPTION: orderDetails.description + } + return firstValueFrom( - this.http.post<{ id: string }>(`${this.apiUrl}/${this.apiDb}/InitiatePayment`, {}) + this.http.post<{ id: string }>(`${this.apiUrl}/${this.apiDb}/InitiatePayment`, data) ).then(order => order.id); }