payment updates

This commit is contained in:
Cyril Joseph 2025-08-22 08:40:07 -03:00
parent ca979c7488
commit abfbdb94c0
2 changed files with 32 additions and 4 deletions

View File

@ -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'
}
})
}
}

View File

@ -13,8 +13,13 @@ export class PaymentService {
private http = inject(HttpClient);
createOrder(orderDetails: any): Promise<string> {
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);
}