Beispiel #1
0
        public void ScriptNotify(string value)
        {
            try
            {
                var        obj = JsonObject.Parse(value);
                IJsonValue eventType;
                if (obj.TryGetValue("eventType", out eventType))
                {
                    if (string.Equals(eventType.GetString(), "payment_form_submit", StringComparison.OrdinalIgnoreCase))
                    {
                        IJsonValue eventData;
                        if (obj.TryGetValue("eventData", out eventData))
                        {
                            if (PaymentInfo != null)
                            {
                                var eventDataObject = eventData.GetObject();
                                if (eventDataObject != null)
                                {
                                    IJsonValue title;
                                    if (eventDataObject.TryGetValue("title", out title))
                                    {
                                        PaymentInfo.CredentialsTitle = title.Stringify().Trim('\"');
                                    }

                                    IJsonValue credentials;
                                    if (eventDataObject.TryGetValue("credentials", out credentials))
                                    {
                                        var paymentCredentials = new TLInputPaymentCredentials
                                        {
                                            Flags = new TLInt(0),
                                            Data  = new TLDataJSON
                                            {
                                                Data = new TLString(credentials.Stringify())
                                            }
                                        };
                                        PaymentInfo.Credentials = paymentCredentials;
                                        NavigateToNextStep();
                                        return;
                                    }
                                }
                            }

                            return;
                        }

                        return;
                    }
                }

                MessageBox.Show(value);
            }
            catch (Exception ex)
            {
                Telegram.Api.Helpers.Execute.ShowDebugMessage(string.Format("WebViewModel.ScriptNotify {0} exception {1}", value, ex));
            }
        }
Beispiel #2
0
        private async void SendExecute()
        {
            var disclaimer = await TLMessageDialog.ShowAsync(string.Format(Strings.Android.PaymentWarningText, _bot.FullName, _provider.FullName), Strings.Android.PaymentWarning, Strings.Android.OK);

            var confirm = await TLMessageDialog.ShowAsync(string.Format(Strings.Android.PaymentTransactionMessage, LocaleHelper.FormatCurrency(_totalAmount, _paymentForm.Invoice.Currency), _bot.FullName, _invoice.Title), Strings.Android.PaymentTransactionReview, Strings.Android.OK, Strings.Android.Cancel);

            if (confirm != Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
            {
                return;
            }

            IsLoading = true;

            TLInputPaymentCredentialsBase credentials;

            if (_paymentForm.HasSavedCredentials && _paymentForm.SavedCredentials is TLPaymentSavedCredentialsCard savedCard)
            {
                credentials = new TLInputPaymentCredentialsSaved {
                    Id = savedCard.Id, TmpPassword = ApplicationSettings.Current.TmpPassword.TmpPassword
                };
            }
            else
            {
                credentials = new TLInputPaymentCredentials {
                    Data = new TLDataJSON {
                        Data = _credentials
                    }, IsSave = _save
                };
            }

            var response = await ProtoService.SendPaymentFormAsync(_message.Id, _requestedInfo?.Id, _shipping?.Id, credentials);

            if (response.IsSucceeded)
            {
                if (response.Result is TLPaymentsPaymentVerficationNeeded verificationNeeded)
                {
                    if (Uri.TryCreate(verificationNeeded.Url, UriKind.Absolute, out Uri uri))
                    {
                        await Launcher.LaunchUriAsync(uri);
                    }
                }

                NavigationService.GoBackAt(1);
            }
            else if (response.Error != null)
            {
            }
        }
        private async void SendExecute()
        {
            var confirm = await TLMessageDialog.ShowAsync(string.Format("Neither Telegram, nor {0} will have access to your credit card information. Credit card details will be handled only by the payment system, {1}.\n\nPayments will go directly to the developer of {0}. Telegram cannot provide any guarantees, so proceed at your own risk. In case of problems, please contact the developer of {0} or your bank.", _bot.FullName, _provider.FullName), "Transaction review", "OK", "Cancel");

            //var confirm = await TLMessageDialog.ShowAsync(string.Format("Do you really want to transfer {0} to the {1} bot for {2}?", BindConvert.Current.FormatAmount(_totalAmount, _paymentForm.Invoice.Currency), _bot.FullName, _invoice.Title), "Transaction review", "OK", "Cancel");
            if (confirm != Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
            {
                return;
            }

            IsLoading = true;

            TLInputPaymentCredentialsBase credentials;

            if (_paymentForm.HasSavedCredentials && _paymentForm.SavedCredentials is TLPaymentSavedCredentialsCard savedCard)
            {
                credentials = new TLInputPaymentCredentialsSaved {
                    Id = savedCard.Id, TmpPassword = ApplicationSettings.Current.TmpPassword.TmpPassword
                };
            }
            else
            {
                credentials = new TLInputPaymentCredentials {
                    Data = new TLDataJSON {
                        Data = _credentials
                    }, IsSave = _save
                };
            }

            var response = await ProtoService.SendPaymentFormAsync(_message.Id, _requestedInfo?.Id, _shipping?.Id, credentials);

            if (response.IsSucceeded)
            {
                if (response.Result is TLPaymentsPaymentVerficationNeeded verificationNeeded)
                {
                    if (Uri.TryCreate(verificationNeeded.Url, UriKind.Absolute, out Uri uri))
                    {
                        await Launcher.LaunchUriAsync(uri);
                    }
                }

                NavigationService.GoBackAt(1);
            }
            else if (response.Error != null)
            {
            }
        }
Beispiel #4
0
        private async void SendExecute()
        {
            var confirm = await TLMessageDialog.ShowAsync(string.Format("Do you really want to transfer {0} to the {1} bot for {2}?", BindConvert.Current.FormatAmount(_totalAmount, _paymentForm.Invoice.Currency), _bot.FullName, _invoice.Title), "Transaction review", "OK", "Cancel");

            if (confirm != Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
            {
                return;
            }

            IsLoading = true;

            TLInputPaymentCredentialsBase credentials;

            if (_paymentForm.HasSavedCredentials && _paymentForm.SavedCredentials is TLPaymentSavedCredentialsCard savedCard)
            {
                credentials = new TLInputPaymentCredentialsSaved {
                    Id = savedCard.Id, TmpPassword = ApplicationSettings.Current.TmpPassword.TmpPassword
                };
            }
            else
            {
                credentials = new TLInputPaymentCredentials {
                    Data = new TLDataJSON {
                        Data = _credentials
                    }, IsSave = _save
                };
            }

            var response = await ProtoService.SendPaymentFormAsync(_message.Id, _requestedInfo?.Id, _shipping?.Id, credentials);

            if (response.IsSucceeded)
            {
                if (response.Result is TLPaymentsPaymentVerficationNeeded verificationNeeded)
                {
                    if (Uri.TryCreate(verificationNeeded.Url, UriKind.Absolute, out Uri uri))
                    {
                        await Launcher.LaunchUriAsync(uri);
                    }
                }

                NavigationService.GoBackAt(1);
            }
            else if (response.Error != null)
            {
            }
        }
        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);
            }
        }