コード例 #1
0
        private async void placeOrderTap_Tapped(object sender, EventArgs e)
        {
            try
            {
                if ((_cart.data.user_address == null && _address_id.ToString() == null) || _address_id.ToString() == "0")
                {
                    await DisplayAlert("Alert", Message.addressBlank, "Ok");

                    return;
                }
                else
                {
                    Config.ShowDialog();
                    Dictionary <string, string> valuePairs = new Dictionary <string, string>();
                    valuePairs.Add("address_id", _address_id.ToString());
                    if (PaymentMode.SelectedIndex == 0)
                    {
                        valuePairs.Add("payment_method", "cod");
                    }
                    else
                    {
                        valuePairs.Add("payment_method", "online");
                    }
                    valuePairs.Add("coupon_code_id", CouponCodeId);
                    valuePairs.Add("user_id", Application.Current.Properties["user_id"].ToString());
                    var response = await CartLogic.PlaceOrder(valuePairs);

                    if (response.status == 200)
                    {
                        HomeVM.MyCartCounter = response.cart_count;
                        MessagingCenter.Send((App)Application.Current, "NavigationBar", _pageTitle);
                        //var accepted = await DisplayAlert("Success", response.message, "Ok","cancel");
                        //if (accepted || !accepted)
                        //{
                        //    //var existingPages = Navigation.NavigationStack.ToList();
                        //    //foreach (var page in existingPages)
                        //    //{
                        //    //    Navigation.RemovePage(page);
                        //    //}
                        //    await Navigation.PushAsync(new Home());
                        //}
                        Config.HideDialog();
                        if (PaymentMode.SelectedIndex == 0)
                        {
                            await Navigation.PushModalAsync(new OrderSuccessPage());
                        }
                        else
                        {
                            string url     = String.Format("{0}/paypalConfigure?order_id={1}&amount={2}&user_id={3}&device_type={4}", Config.ApiUrl, response.order_id, response.amount, Application.Current.Properties["user_id"].ToString(), Application.Current.Properties["device_type"].ToString());
                            var    browser = new WebView();
                            browser.Source      = url;
                            Content             = browser;
                            browser.Navigating += Browser_Navigating;
                            browser.Navigated  += Browser_Navigated;
                        }
                    }
                    else
                    {
                        Config.HideDialog();
                        Config.ErrorSnackbarMessage(response.message);
                    }
                }
            }
            catch (Exception ex)
            {
                Config.ErrorStore("CheckoutPage-placeOrderTap_Tapped", ex.Message);
                Config.HideDialog();
                EmptyCart();
                Config.ErrorSnackbarMessage(Config.ApiErrorMessage);
            }
        }