Example #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();
        }
        public async Task LoadWallet()
        {
            paymentMethods = new List <SelectionItem>()
            {
                new SelectionItem()
                {
                    Id = "2", Label = AppResource.textCartCash
                },
            };

            try
            {
                Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResource.alertLoading);
                if (_checkin.Company.CreditCardAllowed)
                {
                    var userService = new UserServicev2();
                    var myWallet    = await userService.GetMyWalletV2();

                    foreach (var item in myWallet)
                    {
                        paymentMethods.Add(
                            new SelectionItem()
                        {
                            Id = item.StripeId, Label = item.ShowName, IsSelected = item.Default
                        }
                            );
                        if (item.Default)
                        {
                            _stripeId = item.StripeId;
                        }
                    }
                }

                listPaymentMethods.ItemsSource   = paymentMethods;
                listPaymentMethods.HeightRequest = paymentMethods.Count * 40 + 48;
                listPaymentMethods.ItemTapped   += async(sender, args) =>
                {
                    foreach (var item in paymentMethods)
                    {
                        item.IsSelected = false;
                    }

                    var selected = args.Item as SelectionItem;
                    selected.IsSelected = true;

                    _stripeId = selected.Id;

                    //App.AppCurrent.Cart.PaymentMethod = selected.Id;
                };
                //else
                //{
                //    grdAddCard.IsVisible = false;
                //}
            }
            catch (Exception ex)
            {
            }
            finally
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
            }
        }