瀏覽代碼

Order Synchronozation with the payment gateway

master
kj1352 5 年之前
父節點
當前提交
59179fb5f8
共有 2 個文件被更改,包括 39 次插入19 次删除
  1. +27
    -19
      src/app/cart/cart.page.ts
  2. +12
    -0
      src/app/services/order.service.ts

+ 27
- 19
src/app/cart/cart.page.ts 查看文件

@@ -42,6 +42,7 @@ export class CartPage implements OnInit {
selected_promocode: string = '';
userInfo: any;
mallPromoCodes: Array<any> = [];
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();
}

}

+ 12
- 0
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();
}
}

Loading…
取消
儲存