public OrderDetailViewModel(Order order = null) { Title = "Order detail"; Order = order; if (Order.Status != "PENDING") { IsFinished = true; } // ------------------------------------------------------------------------- MessagingCenter.Instance.Subscribe <Application, string>(Application.Current, "Redirect", async(sender, result) => { IsBusy = true; try { /// NOTE: Need to query to your backend service and then your backend will check the ZaloPay API to get the order status var response = await ZaloPayHelper.GetOrderStatus(Order.AppTransId); int returnCode = int.Parse(response["return_code"].ToString()); if (returnCode == 1) { Order.Status = "SUCCESS"; IsFinished = true; } else { IsFinished = true; Order.Status = "FAILED"; } await App.Database.SaveItemAsync(Order); } catch (Exception e) { Console.WriteLine(">> EXCEPTION: " + e.ToString()); Order.Status = "FAILED"; IsFinished = true; } finally { IsBusy = false; await Navigation.PopAsync(); } }); // ------------------------------------------------------------------------- }
// GET: Redirect public async Task <ActionResult> Index() { bool isValidRedirect; try { var data = new Dictionary <string, object>(); Request.QueryString.CopyTo(data); isValidRedirect = ZaloPayHelper.VerifyRedirect(data); if (isValidRedirect) { var apptransid = data["apptransid"].ToString(); using (var db = new ZaloPayDemoContext()) { var orderDTO = db.Orders.First(o => o.Apptransid.Equals(apptransid)); if (orderDTO != null && orderDTO.Status == 0) { var orderStatus = await ZaloPayHelper.GetOrderStatus(apptransid); var returncode = int.Parse(orderStatus["returncode"].ToString()); orderDTO.Zptransid = orderStatus["zptransid"].ToString(); orderDTO.Channel = int.Parse(orderStatus["pmcid"].ToString()); orderDTO.Status = returncode == 1 ? 1 : -1; } } } } catch (Exception ex) { isValidRedirect = false; ViewData["Exception"] = ex.Message; } ViewData["isValidRedirect"] = isValidRedirect; return(View()); }