Ejemplo n.º 1
0
        private async void OnSave_Tapped(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtCardNumber.Text) || string.IsNullOrEmpty(txtCountry.Text) || string.IsNullOrEmpty(txtCardName.Text) || string.IsNullOrEmpty(txtcvv.Text) || string.IsNullOrEmpty(txtExp.Text))
                {
                    await DisplayAlert(AppResource.alertAlert, AppResource.alertAlert, AppResource.textOk);

                    return;
                }


                Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResource.alertLoading);

                if (string.IsNullOrEmpty(lblBrand.Text) || lblBrand.Text == "Invalid Card Number")
                {
                    await DisplayAlert(AppResource.alertAlert, "Invalid Card Number", AppResource.textOk);

                    return;
                }


                var userService = new UserServicev2();

                var stripe  = new StripeService();
                var expDate = txtExp.Text.Split('/');

                var token = stripe.Generate(txtCardNumber.Text, txtcvv.Text, Convert.ToInt32(expDate[0]), Convert.ToInt32(expDate[1]));

                var result = await userService.AddCardV2(token, "");

                //var result = await userService.AddCard(new Models.UserWallet()
                //{
                //    CardBrand = lblBrand.Text,
                //    CardName = txtCardName.Text,
                //    CVV = txtcvv.Text,
                //    UserId = Helpers.Settings.DisplayUserId,
                //    ExpirationDate = txtExp.Text,
                //    CardNumber = txtCardNumber.Text
                //}, Helpers.Settings.DisplayUserToken);

                if (result)
                {
                    App.AppCurrent.NavigationService.ModalGoBack();
                    return;

                    //if (_ret)
                    //    return;
                }
                else
                {
                    await DisplayAlert(AppResource.alertAlert, AppResource.alertAtention, AppResource.textOk);

                    return;
                }


                await App.AppCurrent.NavigationService.ModalGoBack();
            }
            catch (Exception ex)
            {
                await DisplayAlert(AppResource.alertAlert, ex.Message, AppResource.textOk);
            }
            finally
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
            }


            App.AppCurrent.NavigationService.ModalGoBack();
        }