feedback updates
This commit is contained in:
parent
07e7a0da63
commit
a695cc8f4e
@ -9,6 +9,7 @@ import { NotificationService } from '../../core/services/common/notification.ser
|
||||
import { StorageService } from '../../core/services/common/storage.service';
|
||||
import { finalize } from 'rxjs';
|
||||
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.
|
||||
declare var paypal: any;
|
||||
@ -30,10 +31,7 @@ export class CheckoutComponent {
|
||||
|
||||
@ViewChild('paypalcontrol', { static: true }) paypalElement!: ElementRef;
|
||||
|
||||
orderDetails = {
|
||||
price: '',
|
||||
description: '',
|
||||
};
|
||||
orderDetails: PaymentDetail = {};
|
||||
|
||||
orderTotal = 0.00;
|
||||
currency = 'USD';
|
||||
@ -47,6 +45,8 @@ export class CheckoutComponent {
|
||||
|
||||
constructor() {
|
||||
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}`
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ export class CheckoutComponent {
|
||||
try {
|
||||
// Call the createOrder method from your service
|
||||
const orderId = await this.paymentService.createOrder(this.orderDetails);
|
||||
// console.log('Order ID created by server:', orderId);
|
||||
this.orderDetails.orderId = orderId;
|
||||
return orderId;
|
||||
} catch (error) {
|
||||
this.notificationService.showError('Failed to initiate the payment');
|
||||
@ -112,7 +112,7 @@ export class CheckoutComponent {
|
||||
onApprove: async (data: any, actions: any) => {
|
||||
try {
|
||||
// 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
|
||||
this.changeInProgress = true;
|
||||
@ -139,11 +139,20 @@ export class CheckoutComponent {
|
||||
// 3. Handle errors
|
||||
onError: (error: any) => {
|
||||
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);
|
||||
},
|
||||
|
||||
// 4. Handle cancellation
|
||||
onCancel: (data: any) => {
|
||||
this.orderDetails.paymentStatus = 'Cancelled';
|
||||
if (this.orderDetails.orderId) {
|
||||
this.paymentService.logTransactionDetails(this.orderDetails);
|
||||
}
|
||||
|
||||
this.onCancel();
|
||||
}
|
||||
}).render(this.paypalElement.nativeElement)
|
||||
|
||||
9
src/app/core/models/carnet/payment-details.ts
Normal file
9
src/app/core/models/carnet/payment-details.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export interface PaymentDetail {
|
||||
headerid?: number;
|
||||
applicationName?: string;
|
||||
price?: string;
|
||||
description?: string;
|
||||
orderId?: string;
|
||||
paymentStatus?: string;
|
||||
paymentErrorDetails?: string;
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class InsuranceService {
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
@ -2,6 +2,8 @@ import { inject, Injectable } from '@angular/core';
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { PaymentDetail } from '../../models/carnet/payment-details';
|
||||
import { UserService } from '../common/user.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -11,11 +13,14 @@ export class PaymentService {
|
||||
private apiDb = environment.apiDb;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private userService = inject(UserService);
|
||||
|
||||
createOrder(orderDetails: any): Promise<string> {
|
||||
createOrder(paymentDetails: PaymentDetail): Promise<string> {
|
||||
const data = {
|
||||
P_PRICE: orderDetails.price,
|
||||
P_DESCRIPTION: orderDetails.description
|
||||
P_APPLICATIONNAME: paymentDetails.applicationName,
|
||||
P_PRICE: paymentDetails.price,
|
||||
P_DESCRIPTION: paymentDetails.description,
|
||||
P_USERID: this.userService.getUser()
|
||||
}
|
||||
|
||||
return firstValueFrom(
|
||||
@ -23,12 +28,29 @@ export class PaymentService {
|
||||
).then(order => order.id);
|
||||
}
|
||||
|
||||
completePayment(orderId: string): Promise<any> {
|
||||
completePayment(paymentDetails: PaymentDetail): Promise<any> {
|
||||
const data = {
|
||||
P_ORDERID: orderId
|
||||
P_ORDERID: paymentDetails.orderId,
|
||||
P_APPLICATIONNAME: paymentDetails.applicationName,
|
||||
P_PRICE: paymentDetails.price,
|
||||
P_USERID: this.userService.getUser()
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user