public CheckoutViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            Prices = new List <TLLabeledPrice>();

            if (PaymentInfo != null)
            {
                if (PaymentInfo.Form != null)
                {
                    Invoice   = PaymentInfo.Form.Invoice;
                    SavedInfo = PaymentInfo.Form.SavedInfo;
                    foreach (var price in PaymentInfo.Form.Invoice.Prices)
                    {
                        price.Currency = PaymentInfo.Form.Invoice.Currency;
                        Prices.Add(price);
                    }

                    if (PaymentInfo.ValidatedInfo != null &&
                        PaymentInfo.ValidatedInfo.ShippingOptions != null)
                    {
                        foreach (var shippingOption in PaymentInfo.ValidatedInfo.ShippingOptions)
                        {
                            if (shippingOption.IsSelected)
                            {
                                ShippingOption = shippingOption;
                                foreach (var price in shippingOption.Prices)
                                {
                                    price.Currency = PaymentInfo.Form.Invoice.Currency;
                                    Prices.Add(price);
                                }
                                break;
                            }
                        }
                    }
                }
                else if (PaymentInfo.Receipt != null)
                {
                    Invoice   = PaymentInfo.Receipt.Invoice;
                    SavedInfo = PaymentInfo.Receipt.SavedInfo;
                    PaymentInfo.CredentialsTitle = PaymentInfo.Receipt.CredentialsTitle.ToString();

                    foreach (var price in PaymentInfo.Receipt.Invoice.Prices)
                    {
                        price.Currency = PaymentInfo.Receipt.Invoice.Currency;
                        Prices.Add(price);
                    }

                    var shippingOption = PaymentInfo.Receipt.Shipping;
                    if (shippingOption != null)
                    {
                        ShippingOption = shippingOption;
                        foreach (var price in shippingOption.Prices)
                        {
                            price.Currency = PaymentInfo.Receipt.Invoice.Currency;
                            Prices.Add(price);
                        }
                    }
                }
            }
        }
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer == null)
            {
                return(Task.CompletedTask);
            }

            using (var from = TLObjectSerializer.CreateReader(buffer.AsBuffer()))
            {
                var tuple = new TLTuple <TLMessage, TLPaymentsPaymentForm, TLPaymentRequestedInfo, TLPaymentsValidatedRequestedInfo, TLShippingOption>(from);

                Message     = tuple.Item1;
                Invoice     = tuple.Item1.Media as TLMessageMediaInvoice;
                PaymentForm = tuple.Item2;

                // TODO: real hint
                PasswordHint = Strings.Android.LoginPassword;

                if (_paymentForm.HasSavedCredentials && _paymentForm.SavedCredentials is TLPaymentSavedCredentialsCard savedCard)
                {
                    CredentialsTitle = savedCard.Title;
                }

                _info          = tuple.Item3;
                _requestedInfo = tuple.Item4;
                _shipping      = tuple.Item5;
            }

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        private void UpdateRowsAndColumns()
        {
            if (_options != null && _currency != null)
            {
                Children.Clear();
                RowDefinitions.Clear();

                Shipping = _options[0];

                for (int i = 0; i < _options.Count; i++)
                {
                    var option = _options[i];

                    var radio = new RadioButton();
                    radio.IsChecked   = i == 0;
                    radio.Content     = BindConvert.Current.ShippingOption(option, _currency);
                    radio.Margin      = new Thickness(12, 4, 12, 4);
                    radio.DataContext = option;
                    radio.Checked    += (s, args) =>
                    {
                        Shipping = radio.DataContext as TLShippingOption;
                    };

                    Grid.SetRow(radio, i);

                    Children.Add(radio);
                    RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(0, GridUnitType.Auto)
                    });
                }
            }
        }
Esempio n. 4
0
        public string ShippingOption(TLShippingOption option, string currency)
        {
            var amount = 0L;

            foreach (var price in option.Prices)
            {
                amount += price.Amount;
            }

            return($"{FormatAmount(amount, currency)} - {option.Title}");
        }
Esempio n. 5
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer == null)
            {
                return(Task.CompletedTask);
            }

            using (var from = TLObjectSerializer.CreateReader(buffer.AsBuffer()))
            {
                var tuple = new TLTuple <TLMessage, TLPaymentsPaymentForm, TLPaymentRequestedInfo, TLPaymentsValidatedRequestedInfo, TLShippingOption>(from);

                Message     = tuple.Item1;
                Invoice     = tuple.Item1.Media as TLMessageMediaInvoice;
                PaymentForm = tuple.Item2;

                _info          = tuple.Item3;
                _requestedInfo = tuple.Item4;
                _shipping      = tuple.Item5;

                if (_paymentForm.HasNativeProvider && _paymentForm.HasNativeParams && _paymentForm.NativeProvider.Equals("stripe"))
                {
                    IsNativeUsed    = true;
                    SelectedCountry = null;

                    var json = JsonObject.Parse(_paymentForm.NativeParams.Data);

                    NeedCountry        = json.GetNamedBoolean("need_country", false);
                    NeedZip            = json.GetNamedBoolean("need_zip", false);
                    NeedCardholderName = json.GetNamedBoolean("need_cardholder_name", false);

                    _publishableKey = json.GetNamedString("publishable_key", string.Empty);
                }
                else
                {
                    IsNativeUsed = false;
                    RaisePropertyChanged("Navigate");
                }

                //var info = PaymentForm.HasSavedInfo ? PaymentForm.SavedInfo : new TLPaymentRequestedInfo();
                //if (info.ShippingAddress == null)
                //{
                //    info.ShippingAddress = new TLPostAddress();
                //}

                //Info = info;
                //SelectedCountry = null;
            }

            return(Task.CompletedTask);
        }
Esempio n. 6
0
 public static void NavigateToPaymentFormStep5(this INavigationService service, MessageViewModel message, PaymentForm paymentForm, TLPaymentRequestedInfo info, TLPaymentsValidatedRequestedInfo validatedInfo, TLShippingOption shipping, string title, string credentials, bool save)
 {
     service.Navigate(typeof(PaymentFormStep5Page), TLTuple.Create(message, paymentForm, info, validatedInfo, shipping, title ?? string.Empty, credentials ?? string.Empty, save));
 }
Esempio n. 7
0
 public static void NavigateToPaymentFormStep4(this INavigationService service, MessageViewModel message, PaymentForm paymentForm, TLPaymentRequestedInfo info, TLPaymentsValidatedRequestedInfo validatedInfo, TLShippingOption shipping)
 {
     service.Navigate(typeof(PaymentFormStep4Page), TLTuple.Create(message, paymentForm, info, validatedInfo, shipping));
 }