private async void SendExecute()
        {
            var save = _isSave ?? false;

            if (_paymentForm.HasSavedCredentials && !save && _paymentForm.IsCanSaveCredentials)
            {
                _paymentForm.HasSavedCredentials = false;
                _paymentForm.SavedCredentials    = null;

                ApplicationSettings.Current.TmpPassword = null;
                LegacyService.ClearSavedInfoAsync(false, true, null, null);
            }

            var month = 0;
            var year  = 0;

            if (_date != null)
            {
                var args = _date.Split('/');
                if (args.Length == 2)
                {
                    month = int.Parse(args[0]);
                    year  = int.Parse(args[1]);
                }
            }

            var card = new Card(
                _card,
                month,
                year,
                _cvc,
                _cardName,
                null, null, null, null,
                _postcode,
                _selectedCountry?.Code?.ToUpper(),
                null);

            if (!card.ValidateNumber())
            {
                RaisePropertyChanged("CARD_NUMBER_INVALID");
                return;
            }
            if (!card.ValidateExpireDate())
            {
                RaisePropertyChanged("CARD_EXPIRE_DATE_INVALID");
                return;
            }
            if (NeedCardholderName && string.IsNullOrWhiteSpace(_cardName))
            {
                RaisePropertyChanged("CARD_HOLDER_NAME_INVALID");
                return;
            }
            if (!card.ValidateCVC())
            {
                RaisePropertyChanged("CARD_CVC_INVALID");
                return;
            }
            if (NeedCountry && _selectedCountry == null)
            {
                RaisePropertyChanged("CARD_COUNTRY_INVALID");
                return;
            }
            if (NeedZip && string.IsNullOrWhiteSpace(_postcode))
            {
                RaisePropertyChanged("CARD_ZIP_INVALID");
                return;
            }

            IsLoading = true;

            using (var stripe = new StripeClient(_publishableKey))
            {
                var token = await stripe.CreateTokenAsync(card);

                if (token != null)
                {
                    var title       = card.GetBrand() + " *" + card.GetLast4();
                    var credentials = string.Format("{{\"type\":\"{0}\", \"id\":\"{1}\"}}", token.Type, token.Id);

                    NavigateToNextStep(title, credentials, _isSave ?? false);
                }
                else
                {
                    IsLoading = false;
                }
            }

            //var save = _isSave ?? false;
            //var info = new TLPaymentRequestedInfo();
            //if (_paymentForm.Invoice.IsNameRequested)
            //{
            //    info.Name = _info.Name;
            //}
            //if (_paymentForm.Invoice.IsEmailRequested)
            //{
            //    info.Email = _info.Email;
            //}
            //if (_paymentForm.Invoice.IsPhoneRequested)
            //{
            //    info.Phone = _info.Phone;
            //}
            //if (_paymentForm.Invoice.IsShippingAddressRequested)
            //{
            //    info.ShippingAddress = _info.ShippingAddress;
            //    info.ShippingAddress.CountryIso2 = _selectedCountry?.Code;
            //}

            //var response = await ProtoService.ValidateRequestedInfoAsync(save, _message.Id, info);
            //if (response.IsSucceeded)
            //{
            //    IsLoading = false;

            //    if (_paymentForm.HasSavedInfo && !save)
            //    {
            //        ProtoService.ClearSavedInfoAsync(true, false, null, null);
            //    }

            //    if (_paymentForm.Invoice.IsFlexible)
            //    {
            //        NavigationService.Navigate(typeof(PaymentFormStep2Page), TLTuple.Create(_message, _paymentForm, response.Result));
            //    }
            //    else if (_paymentForm.HasSavedCredentials)
            //    {
            //        // TODO: Is password expired?
            //        var expired = true;
            //        if (expired)
            //        {
            //            NavigationService.Navigate(typeof(PaymentFormStep4Page));
            //        }
            //        else
            //        {
            //            NavigationService.Navigate(typeof(PaymentFormStep5Page));
            //        }
            //    }
            //    else
            //    {
            //        NavigationService.Navigate(typeof(PaymentFormStep3Page));
            //    }
            //}
        }
Exemple #2
0
        private async void SendExecute()
        {
            IsLoading = true;

            var save = _isSave ?? false;
            var info = new TLPaymentRequestedInfo();

            if (_paymentForm.Invoice.IsNameRequested)
            {
                info.Name = _info.Name;
            }
            if (_paymentForm.Invoice.IsEmailRequested)
            {
                info.Email = _info.Email;
            }
            if (_paymentForm.Invoice.IsPhoneRequested)
            {
                info.Phone = _info.Phone;
            }
            if (_paymentForm.Invoice.IsShippingAddressRequested)
            {
                info.ShippingAddress             = _info.ShippingAddress;
                info.ShippingAddress.CountryIso2 = _selectedCountry?.Code?.ToUpper();
            }

            var response = await LegacyService.ValidateRequestedInfoAsync(_message.Id, info, save);

            if (response.IsSucceeded)
            {
                IsLoading = false;

                if (_paymentForm.HasSavedInfo && !save)
                {
                    LegacyService.ClearSavedInfoAsync(true, false, null, null);
                }

                if (_paymentForm.Invoice.IsFlexible)
                {
                    //NavigationService.NavigateToPaymentFormStep2(_message, _paymentForm, info, response.Result);
                }
                else if (_paymentForm.HasSavedCredentials)
                {
                    if (ApplicationSettings.Current.TmpPassword != null)
                    {
                        if (ApplicationSettings.Current.TmpPassword.ValidUntil < TLUtils.Now + 60)
                        {
                            ApplicationSettings.Current.TmpPassword = null;
                        }
                    }

                    if (ApplicationSettings.Current.TmpPassword != null)
                    {
                        //NavigationService.NavigateToPaymentFormStep5(_message, _paymentForm, info, response.Result, null, null, null, true);
                    }
                    else
                    {
                        //NavigationService.NavigateToPaymentFormStep4(_message, _paymentForm, info, response.Result, null);
                    }
                }
                else
                {
                    //NavigationService.NavigateToPaymentFormStep3(_message, _paymentForm, info, response.Result, null);
                }
            }
            else if (response.Error != null)
            {
                IsLoading = false;

                switch (response.Error.ErrorMessage)
                {
                case "REQ_INFO_NAME_INVALID":
                case "REQ_INFO_PHONE_INVALID":
                case "REQ_INFO_EMAIL_INVALID":
                case "ADDRESS_COUNTRY_INVALID":
                case "ADDRESS_CITY_INVALID":
                case "ADDRESS_POSTCODE_INVALID":
                case "ADDRESS_STATE_INVALID":
                case "ADDRESS_STREET_LINE1_INVALID":
                case "ADDRESS_STREET_LINE2_INVALID":
                    RaisePropertyChanged(response.Error.ErrorMessage);
                    break;

                default:
                    //AlertsCreator.processError(error, PaymentFormActivity.this, req);
                    break;
                }
            }
        }