Example #1
0
        public virtual async Task <CustomerPaymentMethodsViewModel> GetCustomerPaymentMethodsViewModelAsync(GetCustomerPaymentMethodListViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var allMethods = await PaymentRepository.GetPaymentMethodsAsync(new GetPaymentMethodsParam
            {
                CartName      = CartConfiguration.ShoppingCartName,
                CultureInfo   = param.CultureInfo,
                CustomerId    = param.CustomerId,
                Scope         = param.ScopeId,
                ProviderNames = param.ProviderNames
            }).ConfigureAwait(false);

            var savedCreditCardVm = allMethods.Where(m => m.Type == PaymentMethodType.SavedCreditCard)
                                    .Select(m => CartViewModelFactory.MapSavedCreditCard(m, param.CultureInfo)).ToList();

            var isUsedInRecurringTasks = savedCreditCardVm.Select(vm => IsSavedCardUsedInRecurringOrders(vm, param.CultureInfo, param.CustomerId, param.ScopeId)).ToList();
            await Task.WhenAll(isUsedInRecurringTasks).ConfigureAwait(false);

            return(new CustomerPaymentMethodsViewModel
            {
                SavedCreditCards = savedCreditCardVm
                                   //AddWalletUrl
            });
        }
Example #2
0
        public virtual async Task <CustomerPaymentMethodListViewModel> GetCustomerPaymentMethodListViewModelAsync(GetCustomerPaymentMethodListViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param), ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param)));
            }

            var tasks = param.ProviderNames.Select(pName => PaymentRepository.GetCustomerPaymentMethodForProviderAsync(new GetCustomerPaymentMethodsForProviderParam
            {
                CustomerId   = param.CustomerId,
                ScopeId      = param.ScopeId,
                ProviderName = pName
            })).ToArray();

            try
            {
                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Log.Warn($"GetCustomerPaymentMethodsRequest failed. {e.ToString()}");
            }

            tasks = tasks.Where(t => !t.IsFaulted).ToArray();
            var paymentMethods = tasks.SelectMany(t => t.Result).ToList();

            var savedCreditCardVm = paymentMethods.Select(s => CartViewModelFactory.MapSavedCreditCard(s, param.CultureInfo)).ToList();

            List <Task> taskList = new List <Task>();

            foreach (var vm in savedCreditCardVm)
            {
                taskList.Add(IsSavedCardUsedInRecurringOrders(vm, param.CultureInfo, param.CustomerId, param.ScopeId));
            }

            await Task.WhenAll(taskList).ConfigureAwait(false);

            return(new CustomerPaymentMethodListViewModel
            {
                SavedCreditCards = savedCreditCardVm
                                   //AddWalletUrl
            });
        }