private async void SendExecute() { var save = _isSave ?? false; if (_paymentForm.SavedCredentials != null && !save && _paymentForm.CanSaveCredentials) { //_paymentForm.HasSavedCredentials = false; _paymentForm.SavedCredentials = null; ProtoService.Send(new DeleteSavedCredentials()); } 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)); // } //} }
public async void Validate() { if (PaymentInfo.Form.SavedCredentials != null && !SavePaymentInformation && PaymentInfo.Form.CanSaveCredentials) { PaymentInfo.Form.SavedCredentials = null; StateService.SaveTmpPassword(null); MTProtoService.ClearSavedInfoAsync(false, true, result => { }, error => { }); } var month = 0; var year = 0; try { if (ExpirationDate != null) { var args = ExpirationDate.Split('/'); if (args.Length == 2) { month = int.Parse(args[0]); year = int.Parse(args[1]); } } } catch (Exception ex) { Error = "CARD_EXPIRE_DATE_INVALID"; NotifyOfPropertyChange(() => Error); return; } var card = new Card( CardNumber, month, year, SecurityCode, CardholderName, null, null, null, null, PostCode, SelectedCountry != null ? _selectedCountry.Code.ToUpperInvariant() : null, null); if (!card.ValidateNumber()) { Error = "CARD_NUMBER_INVALID"; NotifyOfPropertyChange(() => Error); return; } if (!card.ValidateExpireDate()) { Error = "CARD_EXPIRE_DATE_INVALID"; NotifyOfPropertyChange(() => Error); return; } if (NeedCardholderName && string.IsNullOrWhiteSpace(CardholderName)) { Error = "CARD_HOLDER_NAME_INVALID"; NotifyOfPropertyChange(() => Error); return; } if (!card.ValidateCVC()) { Error = "CARD_CVC_INVALID"; NotifyOfPropertyChange(() => Error); return; } if (NeedCountry && _selectedCountry == null) { Error = "CARD_COUNTRY_INVALID"; NotifyOfPropertyChange(() => Error); return; } if (NeedZip && string.IsNullOrWhiteSpace(PostCode)) { Error = "CARD_ZIP_INVALID"; NotifyOfPropertyChange(() => Error); return; } IsWorking = true; using (var stripe = new StripeClient(_publishableKey)) { var token = await stripe.CreateTokenAsync(card); IsWorking = false; if (token != null) { if (token.Error != null) { Error = token.Error.code; NotifyOfPropertyChange(() => Error); return; } if (!string.IsNullOrEmpty(token.Id) && !string.IsNullOrEmpty(token.Type)) { var title = card.GetBrand() + " *" + card.GetLast4(); var credentials = string.Format("{{\"type\":\"{0}\", \"id\":\"{1}\"}}", token.Type, token.Id); PaymentInfo.CredentialsTitle = title; var paymentCredentials = new TLInputPaymentCredentials { Flags = new TLInt(0), Data = new TLDataJSON { Data = new TLString(credentials) }, Save = SavePaymentInformation }; PaymentInfo.Credentials = paymentCredentials; NavigateToNextStep(); return; } } Error = "invalid_button"; NotifyOfPropertyChange(() => Error); } }