public async Task <bool> RemoveCardById(string customerKey, string cardId)
        {
            var response = await AcquiringUI.GetAcquiringSdk().RemoveCard(customerKey, cardId);

            if (response && cache.ContainsKey(customerKey))
            {
                var cards = cache[customerKey];
                cache[customerKey] = cards.Where(c => c.CardId != cardId).ToArray();
            }
            return(response);
        }
        public async Task <Card> GetCardById(string customerKey, string cardId)
        {
            Card[] cards = null;
            if (cache.ContainsKey(customerKey))
            {
                cards = cache[customerKey];
            }
            if (cards == null)
            {
                cards = await AcquiringUI.GetAcquiringSdk().GetCardList(customerKey);

                cache[customerKey] = cards;
            }
            return(cards.FirstOrDefault(c => c.CardId == cardId));
        }
        public async Task <IEnumerable <Card> > GetAllCards(string customerKey)
        {
            Card[] cards = null;
            if (cache.ContainsKey(customerKey))
            {
                cards = cache[customerKey];
            }
            if (cards == null)
            {
                cards = await AcquiringUI.GetAcquiringSdk().GetCardList(customerKey);

                cache[customerKey] = cards;
            }
            return(cards);
        }
Exemplo n.º 4
0
        private async void OnPayClick(object sender, RoutedEventArgs e)
        {
            if (!CardModel.IsValid || !IsEmailValid)
            {
                return;
            }

            var button = sender as Button;

            if (button != null)
            {
                button.IsEnabled = false;
            }
            ProgressBar.Visibility = Visibility.Visible;

            try
            {
                var sdk       = AcquiringUI.GetAcquiringSdk();
                var paymentId = await sdk.Init(order.Amount, order.OrderId, order.CustomerKey);

                if (string.IsNullOrEmpty(paymentId))
                {
                    return;
                }

                var cardData = cardModel is SavedCardModel
                    ? (CardData) new SavedCardData {
                    Id = cardId, SecureCode = cardModel.SecurityCode.Data
                }
                    : new DefaultCardData
                {
                    Pan        = cardModel.Number.Data,
                    ExpiryDate = cardModel.ExpiryDate.Data,
                    SecureCode = cardModel.SecurityCode.Data
                };

                var response = await sdk.FinishAuthorize(paymentId, false, cardData, Email.Text);

                if (response.IsThreeDsNeed)
                {
                    if (Frame.Navigate(typeof(SecureView), new SecureViewParams {
                        ThreeDsData = response, PaymentId = paymentId
                    }))
                    {
                        cardIsLoaded = true;
                        SetPreviousSettings();
                        var secureView = (SecureView)Frame.Content;
                        if (secureView == null)
                        {
                            return;
                        }

                        secureView.Succeeded += () => OnSucceeded(paymentId);
                        secureView.Cancelled += async() =>
                        {
                            await ShowMessageDialogAsync("Оплата была отменена Вами.", "Оплата отменена");

                            OnCancelled();
                        };
                        secureView.Failed += async exception =>
                        {
                            if (exception is WebException)
                            {
                                if (!Frame.CanGoBack)
                                {
                                    return;
                                }

                                Frame.GoBack();
                                await ShowMessageDialogAsync("Возникли проблемы с интернетом. Проверьте соединение и повторите запрос.", "Проблемы с соединением");
                            }
                            else if (exception is InvalidOperationException)
                            {
                                if (!Frame.CanGoBack)
                                {
                                    return;
                                }

                                Frame.GoBack();
                                await ShowMessageDialogAsync("Платёж отклонён банком. Убедитесь, что на карте достаточно средств и попробуйте снова.", "Платёж отклонён");
                            }
                            else
                            {
                                OnFailed(exception);
                            }
                        };
                    }
                }
                else
                {
                    OnSucceeded(paymentId);
                }
            }
            catch (AcquiringApiException ex)
            {
                OnFailed(ex);
            }
            catch (AcquiringSdkException)
            {
                await ShowMessageDialogAsync("Возникли проблемы с интернетом. Проверьте соединение и повторите запрос.", "Проблемы с соединением");
            }
            finally
            {
                ProgressBar.Visibility = Visibility.Collapsed;
                if (button != null)
                {
                    button.IsEnabled = true;
                }
            }
        }
 public SecureView()
 {
     InitializeComponent();
     sdk = AcquiringUI.GetAcquiringSdk();
 }