public ProcessPaymentPage(double amount, string description, string customerid, string baseurl) { InitializeComponent(); Instance = this; _amount = amount; _description = description; _customerid = customerid; _baseurl = baseurl; ProgressIndicator.IsVisible = true; OpenPayBackend.Navigated += OpenPayBackend_Navigated; BtnCancelBuy.Clicked += BtnCancelBuy_Clicked; }
private async void BtnComprar_Clicked(object sender, EventArgs e) { BtnComprar.IsEnabled = false; if (App.Oauth == null) { await DisplayAlert(App.AppName, "Debes registrarte para poder comprar los productos", "Aceptar"); try { var result = await DisplayActionSheet(App.AppName, "Cancelar", null, "Registrarse"); if (!string.IsNullOrEmpty(result)) { if (result.Equals("Registrarse")) { App.Instance.SetMainPage(new SIgninPage(), true); } } } catch { } return; } var direction = BoxDirection.Text ?? ""; if (!string.IsNullOrEmpty(direction) || !string.IsNullOrWhiteSpace(direction)) { Device.BeginInvokeOnMainThread(async() => { Progress.IsVisible = true; CompraContainer.IsVisible = false; foreach (var shopitem in App.ShopList) { var result = await App.RestClient.Get <VerifyQtyResult>(App.BaseUrl + "/Stock/Verify", new Dictionary <string, object> { { "IdProducto", shopitem.IdProduct.ToString() }, { "Qty", shopitem.Qty.ToString() } }); if (result != null) { if (result.Success == 0) { string message = "La cantidad que deseas comprar excede nuestro stock, nos hacen falta " + result.Qty + " para el producto " + shopitem.Product.Nombre; await DisplayAlert(App.AppName, message, "Aceptar"); Progress.IsVisible = false; CompraContainer.IsVisible = true; return; } } else { string message = "Intenta nuevamente por favor."; await DisplayAlert(App.AppName, message, "Aceptar"); Progress.IsVisible = false; CompraContainer.IsVisible = true; return; } } List <dynamic> sendtobuy = new List <dynamic>(); _request = new TicketRequest { IdUsuario = App.Oauth.IdUsuario, IdCliente = App.IdCliente }; /* * if (ReferenceToCode != null) * { * request.Total = amountwithcode; * request.IdCodigo = ReferenceToCode.IdCodigo; * } */ double total = 0; foreach (var shopitem in App.ShopList) { _request.Articulos.Add(new Articulo { IdProducto = shopitem.IdProduct, Cantidad = shopitem.Qty, Costo = shopitem.Price }); total += shopitem.Price; } if (CrossConnectivity.Current.IsConnected) { _ticketstatus = await App.RestClient.Post <TicketResult, TicketRequest>(App.BaseUrl + "/Ticket/Add", _request); if (_ticketstatus != null) { if (_ticketstatus.Code == 100) { if (MainPage.Instance != null) { MainPage.Instance.SetTextBtnGoToShop("Items: 0, Total: $0"); } // Limpiamos las listas App.Products.Clear(); App.ShopList.Clear(); // Reseteamos el carrito Init(); // Procesamos el pago... ProcessPaymentPage paymentpage = new ProcessPaymentPage(total, $"DroidShop_{_ticketstatus.TicketNumber}", App.Oauth.CustomerId, App.BaseUrl); paymentpage.ChargeResult += Paymentpage_ChargeResult; paymentpage.CancelPayment += Paymentpage_CancelPayment; await Navigation.PushAsync(paymentpage); } else { await DisplayAlert(App.AppName, "Ocurrio un error al realizar la venta, intenta más tarde", "Aceptar"); CompraContainer.IsVisible = true; Progress.IsVisible = false; BtnComprar.IsEnabled = true; } } else { await DisplayAlert(App.AppName, "Ocurrio un error al realizar la venta, intenta más tarde", "Aceptar"); CompraContainer.IsVisible = true; Progress.IsVisible = false; BtnComprar.IsEnabled = true; } } else { await DisplayAlert(App.AppName, "Necesitas conexion a internet para continuar", "Aceptar"); CompraContainer.IsVisible = true; Progress.IsVisible = false; BtnComprar.IsEnabled = true; } }); } else { await DisplayAlert(App.AppName, "Debes ingresar una direccion de envio", "Aceptar"); CompraContainer.IsVisible = true; Progress.IsVisible = false; BtnComprar.IsEnabled = true; } }
protected override void OnDisappearing() { CancelPayment?.Invoke(this, EventArgs.Empty); Instance = null; base.OnDisappearing(); }
private void BtnCancelBuy_Clicked(object sender, EventArgs e) { CancelPayment?.Invoke(this, e); Instance = null; }
protected override bool OnBackButtonPressed() { CancelPayment?.Invoke(this, EventArgs.Empty); Instance = null; return(base.OnBackButtonPressed()); }