feedback updates

This commit is contained in:
Cyril Joseph 2025-09-07 21:53:04 -03:00
parent 07e7a0da63
commit a695cc8f4e
4 changed files with 52 additions and 21 deletions

View File

@ -9,6 +9,7 @@ import { NotificationService } from '../../core/services/common/notification.ser
import { StorageService } from '../../core/services/common/storage.service'; import { StorageService } from '../../core/services/common/storage.service';
import { finalize } from 'rxjs'; import { finalize } from 'rxjs';
import { AngularMaterialModule } from '../../shared/module/angular-material.module'; import { AngularMaterialModule } from '../../shared/module/angular-material.module';
import { PaymentDetail } from '../../core/models/carnet/payment-details';
// This is necessary to tell TypeScript that a global 'paypal' object exists. // This is necessary to tell TypeScript that a global 'paypal' object exists.
declare var paypal: any; declare var paypal: any;
@ -30,10 +31,7 @@ export class CheckoutComponent {
@ViewChild('paypalcontrol', { static: true }) paypalElement!: ElementRef; @ViewChild('paypalcontrol', { static: true }) paypalElement!: ElementRef;
orderDetails = { orderDetails: PaymentDetail = {};
price: '',
description: '',
};
orderTotal = 0.00; orderTotal = 0.00;
currency = 'USD'; currency = 'USD';
@ -47,6 +45,8 @@ export class CheckoutComponent {
constructor() { constructor() {
this.currentApplicationDetails = this.storageService.get<{ headerid: number, applicationName: string, applicationType: string }>('currentapplication') this.currentApplicationDetails = this.storageService.get<{ headerid: number, applicationName: string, applicationType: string }>('currentapplication')
this.orderDetails.headerid = this.currentApplicationDetails?.headerid;
this.orderDetails.applicationName = this.currentApplicationDetails?.applicationName;
this.orderDetails.description = ` 'Carnet Application - ${this.currentApplicationDetails?.headerid} - ${this.currentApplicationDetails?.applicationName}` this.orderDetails.description = ` 'Carnet Application - ${this.currentApplicationDetails?.headerid} - ${this.currentApplicationDetails?.applicationName}`
} }
@ -99,7 +99,7 @@ export class CheckoutComponent {
try { try {
// Call the createOrder method from your service // Call the createOrder method from your service
const orderId = await this.paymentService.createOrder(this.orderDetails); const orderId = await this.paymentService.createOrder(this.orderDetails);
// console.log('Order ID created by server:', orderId); this.orderDetails.orderId = orderId;
return orderId; return orderId;
} catch (error) { } catch (error) {
this.notificationService.showError('Failed to initiate the payment'); this.notificationService.showError('Failed to initiate the payment');
@ -112,7 +112,7 @@ export class CheckoutComponent {
onApprove: async (data: any, actions: any) => { onApprove: async (data: any, actions: any) => {
try { try {
// data.orderID is the ID of the transaction from PayPal // data.orderID is the ID of the transaction from PayPal
const captureDetails = await this.paymentService.completePayment(data.orderID); await this.paymentService.completePayment(this.orderDetails);
// You can now redirect the user or update the UI // You can now redirect the user or update the UI
this.changeInProgress = true; this.changeInProgress = true;
@ -139,11 +139,20 @@ export class CheckoutComponent {
// 3. Handle errors // 3. Handle errors
onError: (error: any) => { onError: (error: any) => {
this.notificationService.showError('Payment transaction failed'); this.notificationService.showError('Payment transaction failed');
this.orderDetails.paymentStatus = 'Failed';
this.orderDetails.paymentErrorDetails = JSON.stringify(error);
this.paymentService.logTransactionDetails(this.orderDetails);
console.error('An error occurred during the transaction:', error); console.error('An error occurred during the transaction:', error);
}, },
// 4. Handle cancellation // 4. Handle cancellation
onCancel: (data: any) => { onCancel: (data: any) => {
this.orderDetails.paymentStatus = 'Cancelled';
if (this.orderDetails.orderId) {
this.paymentService.logTransactionDetails(this.orderDetails);
}
this.onCancel(); this.onCancel();
} }
}).render(this.paypalElement.nativeElement) }).render(this.paypalElement.nativeElement)

View File

@ -0,0 +1,9 @@
export interface PaymentDetail {
headerid?: number;
applicationName?: string;
price?: string;
description?: string;
orderId?: string;
paymentStatus?: string;
paymentErrorDetails?: string;
}

View File

@ -1,9 +0,0 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class InsuranceService {
constructor() { }
}

View File

@ -2,6 +2,8 @@ import { inject, Injectable } from '@angular/core';
import { environment } from '../../../../environments/environment'; import { environment } from '../../../../environments/environment';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom } from 'rxjs';
import { PaymentDetail } from '../../models/carnet/payment-details';
import { UserService } from '../common/user.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -11,11 +13,14 @@ export class PaymentService {
private apiDb = environment.apiDb; private apiDb = environment.apiDb;
private http = inject(HttpClient); private http = inject(HttpClient);
private userService = inject(UserService);
createOrder(orderDetails: any): Promise<string> { createOrder(paymentDetails: PaymentDetail): Promise<string> {
const data = { const data = {
P_PRICE: orderDetails.price, P_APPLICATIONNAME: paymentDetails.applicationName,
P_DESCRIPTION: orderDetails.description P_PRICE: paymentDetails.price,
P_DESCRIPTION: paymentDetails.description,
P_USERID: this.userService.getUser()
} }
return firstValueFrom( return firstValueFrom(
@ -23,12 +28,29 @@ export class PaymentService {
).then(order => order.id); ).then(order => order.id);
} }
completePayment(orderId: string): Promise<any> { completePayment(paymentDetails: PaymentDetail): Promise<any> {
const data = { const data = {
P_ORDERID: orderId P_ORDERID: paymentDetails.orderId,
P_APPLICATIONNAME: paymentDetails.applicationName,
P_PRICE: paymentDetails.price,
P_USERID: this.userService.getUser()
} }
return firstValueFrom( return firstValueFrom(
this.http.post(`${this.apiUrl}/oracle/CompletePayment`, data)); this.http.post(`${this.apiUrl}/${this.apiDb}/CompletePayment`, data));
}
logTransactionDetails(paymentDetails: PaymentDetail): Promise<any> {
const data = {
P_APPLICATIONNAME: paymentDetails.applicationName,
P_ORDERID: paymentDetails.orderId,
P_PAYMENTAMOUNT: paymentDetails.price,
P_STATUS: paymentDetails.paymentStatus,
P_USERID: this.userService.getUser(),
P_PAYMENTERROR: paymentDetails.paymentErrorDetails
}
return firstValueFrom(
this.http.post(`${this.apiUrl}/${this.apiDb}/SaveHistory`, data));
} }
} }