Beispiel #1
0
        protected virtual async Task LoadOrderDependenciesAsync(CustomerOrder order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            var searchShippingMethodsTask = _shippingMethodsSearchService.SearchShippingMethodsAsync(new ShippingMethodsSearchCriteria {
                StoreId = order.StoreId
            });
            var searchPaymentMethodsTask = _paymentMethodSearchService.SearchPaymentMethodsAsync(new PaymentMethodsSearchCriteria {
                StoreId = order.StoreId
            });

            await Task.WhenAll(searchShippingMethodsTask, searchPaymentMethodsTask);

            if (!searchShippingMethodsTask.Result.Results.IsNullOrEmpty() && !order.Shipments.IsNullOrEmpty())
            {
                foreach (var shipment in order.Shipments)
                {
                    shipment.ShippingMethod = searchShippingMethodsTask.Result.Results.FirstOrDefault(x => x.Code.EqualsInvariant(shipment.ShipmentMethodCode));
                }
            }
            if (!searchPaymentMethodsTask.Result.Results.IsNullOrEmpty() && !order.InPayments.IsNullOrEmpty())
            {
                foreach (var payment in order.InPayments)
                {
                    payment.PaymentMethod = searchPaymentMethodsTask.Result.Results.FirstOrDefault(x => x.Code.EqualsInvariant(payment.GatewayCode));
                }
            }
        }
Beispiel #2
0
        public virtual async Task <ICollection <PaymentMethod> > GetAvailablePaymentMethodsAsync()
        {
            var criteria = new PaymentMethodsSearchCriteria
            {
                IsActive = true,
                Take     = int.MaxValue,
                StoreId  = Store.Id
            };

            var searchResult = await _paymentMethodsSearchService.SearchPaymentMethodsAsync(criteria);

            return(searchResult.Results);
        }
Beispiel #3
0
        protected virtual async Task <ICollection <PaymentMethod> > GetPaymentMethodsAsync(string storeId, string[] codes)
        {
            var criteria = new PaymentMethodsSearchCriteria
            {
                IsActive = true,
                StoreId  = storeId,
                Codes    = codes,
                Take     = int.MaxValue
            };

            var searchResult = await _paymentMethodsSearchService.SearchPaymentMethodsAsync(criteria);

            var paymentMethod = searchResult.Results;

            return(paymentMethod);
        }
        public async Task <IEnumerable <PaymentMethod> > GetAvailablePaymentMethodsAsync(CartAggregate cartAggr)
        {
            if (cartAggr == null)
            {
                return(Enumerable.Empty <PaymentMethod>());
            }

            var criteria = new PaymentMethodsSearchCriteria
            {
                IsActive = true,
                Take     = _takeOnSearch,
                StoreId  = cartAggr.Store?.Id,
            };

            var result = await _paymentMethodsSearchService.SearchPaymentMethodsAsync(criteria);

            if (result.Results.IsNullOrEmpty())
            {
                return(Enumerable.Empty <PaymentMethod>());
            }

            var evalContext = _mapper.Map <PromotionEvaluationContext>(cartAggr);
            var promoResult = await cartAggr.EvaluatePromotionsAsync(evalContext);

            foreach (var paymentMethod in result.Results)
            {
                paymentMethod.ApplyRewards(promoResult.Rewards);
            }

            //Evaluate taxes for available payments
            var taxProvider = await GetActiveTaxProviderAsync(cartAggr.Store.Id);

            if (taxProvider != null)
            {
                var taxEvalContext = _mapper.Map <TaxEvaluationContext>(cartAggr);
                taxEvalContext.Lines.Clear();
                taxEvalContext.Lines.AddRange(result.Results.SelectMany(x => _mapper.Map <IEnumerable <TaxLine> >(x)));
                var taxRates = taxProvider.CalculateRates(taxEvalContext);
                foreach (var paymentMethod in result.Results)
                {
                    paymentMethod.ApplyTaxRates(taxRates);
                }
            }

            return(result.Results);
        }
Beispiel #5
0
        public async Task DoExportAsync(Stream outStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo {
                Description = "The payment methods are loading"
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream))
                using (var writer = new JsonTextWriter(sw))
                {
                    await writer.WriteStartObjectAsync();

                    progressInfo.Description = "Payment mthods are started to export";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("PaymentMethods");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchCriteria  = AbstractTypeFactory <PaymentMethodsSearchCriteria> .TryCreateInstance();
                        searchCriteria.Take = take;
                        searchCriteria.Skip = skip;

                        var searchResult = await _paymentMethodsSearchService.SearchPaymentMethodsAsync(searchCriteria);
                        return((GenericSearchResult <PaymentMethod>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{processedCount} of {totalCount} payment methods have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
        }
        public async Task <ActionResult <PaymentMethodsSearchResult> > SearchPaymentMethods([FromBody] PaymentMethodsSearchCriteria criteria)
        {
            var result = await _paymentMethodsSearchService.SearchPaymentMethodsAsync(criteria);

            return(Ok(result));
        }