public void Payments() { var content = new StackPanel(); var shippingInfo = new CheckBox { Content = AppResources.ShippingInfo, IsChecked = true }; var paymentInfo = new CheckBox { Content = AppResources.PaymentInfo, IsChecked = true }; content.Children.Add(shippingInfo); content.Children.Add(paymentInfo); ShellViewModel.ShowCustomMessageBox(string.Empty, string.Empty, AppResources.Clear.ToLowerInvariant(), AppResources.Cancel.ToLowerInvariant(), r => { if (r == CustomMessageBoxResult.RightButton) { var credentials = paymentInfo.IsChecked.HasValue && paymentInfo.IsChecked.Value; var info = shippingInfo.IsChecked.HasValue && shippingInfo.IsChecked.Value; if (!info && !credentials) { return; } IsWorking = true; MTProtoService.ClearSavedInfoAsync(credentials, info, result => Execute.BeginOnUIThread(() => { IsWorking = false; }), error => Execute.BeginOnUIThread(() => { IsWorking = false; })); } }, content); }
public void Validate() { if (PaymentInfo == null) { return; } if (PaymentInfo.Message == null) { return; } if (PaymentInfo.Form == null) { return; } var info = new TLPaymentRequestedInfo { Flags = new TLInt(0) }; if (PaymentInfo.Form.Invoice.NameRequested) { info.Name = new TLString(Name); } if (PaymentInfo.Form.Invoice.PhoneRequested) { info.Phone = new TLString(PhoneCode + PhoneNumber); } if (PaymentInfo.Form.Invoice.EmailRequested) { info.Email = new TLString(Email); } if (PaymentInfo.Form.Invoice.ShippingAddressRequested) { info.ShippingAddress = new TLPostAddress { StreetLine1 = new TLString(StreetLine1), StreetLine2 = new TLString(StreetLine2), City = new TLString(City), State = new TLString(State), CountryIso2 = new TLString(SelectedCountry != null ? SelectedCountry.Code : string.Empty), PostCode = new TLString(PostCode) }; } IsWorking = true; MTProtoService.ValidateRequestedInfoAsync( SaveShippingInformation, PaymentInfo.Message.Id, info, result => Execute.BeginOnUIThread(() => { IsWorking = false; PaymentInfo.ValidatedInfo = result; PaymentInfo.Form.SavedInfo = info; if (!SaveShippingInformation && PaymentInfo != null && PaymentInfo.Form != null && PaymentInfo.Form.SavedInfo != null) { IsWorking = true; MTProtoService.ClearSavedInfoAsync(false, true, result2 => Execute.BeginOnUIThread(() => { IsWorking = false; NavigateToNextStep(); }), error2 => Execute.BeginOnUIThread(() => { IsWorking = false; Telegram.Api.Helpers.Execute.ShowDebugMessage("payments.clearInfo error " + error2); })); } else { NavigateToNextStep(); } }), error => Execute.BeginOnUIThread(() => { IsWorking = false; Error = error; NotifyOfPropertyChange(() => Error); Telegram.Api.Helpers.Execute.ShowDebugMessage("payments.validateRequestedInfo error " + error); })); }
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); } }