From 59179fb5f8787554014c615ee62c0a614aa6346f Mon Sep 17 00:00:00 2001 From: kj1352 Date: Thu, 26 Nov 2020 15:20:59 +0530 Subject: [PATCH] Order Synchronozation with the payment gateway --- src/app/cart/cart.page.ts | 46 ++++++++++++++++++------------- src/app/services/order.service.ts | 12 ++++++++ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/app/cart/cart.page.ts b/src/app/cart/cart.page.ts index 36e599c..e769ea9 100644 --- a/src/app/cart/cart.page.ts +++ b/src/app/cart/cart.page.ts @@ -42,6 +42,7 @@ export class CartPage implements OnInit { selected_promocode: string = ''; userInfo: any; mallPromoCodes: Array = []; + invoiceData: any; constructor( private location: Location, @@ -54,24 +55,7 @@ export class CartPage implements OnInit { ngOnInit() { this.hideMenuButton(); this.userInfo = JSON.parse(localStorage.userInfo)['User Info']; - } - - async presentModal(url: string) { - const modal = await this.modalController.create({ - component: InAppBrowserPage, - componentProps: { - url: url - } - }); - - modal.onDidDismiss().then(() => { - this.showMenuButton(); - localStorage.removeItem('userCart'); - this.router.navigate(['/profile']); - }); - - return await modal.present(); - } + } ngOnDestroy() { this.showMenuButton(); @@ -297,11 +281,35 @@ export class CartPage implements OnInit { }; this.orderService.generateInvoice(invoice_data).then((data: any) => { - console.log(data.shorturl); + this.invoiceData = data; this.presentModal(data.shorturl); }, (err) => { this.toastService.presentToast("Oops, something went wrong", "danger"); }); } + + async presentModal(url: string) { + const modal = await this.modalController.create({ + component: InAppBrowserPage, + componentProps: { + url: url + } + }); + + modal.onDidDismiss().then(() => { + this.showMenuButton(); + + this.orderService.getPaymentDetailsByOrderID(this.invoiceData.orderId).then((paymentDetails: any) => { + if (paymentDetails.Status === "paid") { + this.placeOrder(); + } else { + this.toastService.presentToast("Payment Failed!", "danger"); + } + }); + }); + + return await modal.present(); + } + } diff --git a/src/app/services/order.service.ts b/src/app/services/order.service.ts index e7c7a45..99260e6 100644 --- a/src/app/services/order.service.ts +++ b/src/app/services/order.service.ts @@ -64,4 +64,16 @@ export class OrderService { return await this.http.get(URL + '/api/maioraservice/offers/getoffer/mall_id/' + mallId, httpOptions).toPromise(); } + + async getPaymentDetailsByOrderID(orderId: string) { + const httpOptions = { + headers: new HttpHeaders({ + 'Access-Control-Allow-Origin': '*', + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + localStorage.access_Token + }) + }; + + return await this.http.get(URL + '/Payment/v1/Order/order_id/' + orderId, httpOptions).toPromise(); + } }