Пример #1
0
        public override IPaymentWidget GetPaymentWidget(PaymentInfoCarrier paymentInfoCarrier)
        {
            var paymentWidget = GetPaymentWidget(paymentInfoCarrier?.PaymentProvider);

            if (paymentWidget?.IsEnabled(paymentInfoCarrier?.PaymentMethod) == true)
            {
                return(paymentWidget);
            }

            return(null);
        }
Пример #2
0
        public void PreventDiscountHigherThanOrderTotal()
        {
            var paymentInfo = new PaymentInfoCarrier();
            var order       = new OrderCarrier();

            order.PaymentInfo.Add(paymentInfo);
            order.OrderRows.Add(new OrderRowCarrier
            {
                TotalPrice     = 10m,
                TotalVATAmount = 2.5m
            });
            order.Fees.Add(new FeeCarrier
            {
                TotalAmount    = 10m,
                TotalVATAmount = 2.5m
            });
            order.Deliveries.Add(new DeliveryCarrier
            {
                TotalDeliveryCost = 10m,
                TotalVATAmount    = 2.5m
            });
            order.OrderDiscounts.Add(new OrderDiscountCarrier
            {
                DiscountAmount = 10m,
                VATAmount      = 2.5m,
                VATPercentage  = 0.25m
            });
            order.OrderDiscounts.Add(new OrderDiscountCarrier
            {
                DiscountAmount = 30m,
                VATAmount      = 7.5m,
                VATPercentage  = 0.25m
            });
            order.OrderDiscounts.Add(new OrderDiscountCarrier
            {
                DiscountAmount = 10m,
                VATAmount      = 2.5m,
                VATPercentage  = 0.25m
            });

            sut.Create(order, null).ToList();
            var result = order.PaymentInfo.Single().Rows;

            Assert.Equal(12.5m, result.First().TotalAmountWithVAT);
            Assert.Equal(12.5m, result.Skip(1).First().TotalAmountWithVAT);
            Assert.Equal(12.5m, result.Skip(2).First().TotalAmountWithVAT);
            Assert.Equal(-12.5m, result.Skip(3).First().TotalAmountWithVAT);
            Assert.Equal(-25m, result.Skip(4).First().TotalAmountWithVAT);
            Assert.Equal(0, result.Skip(5).First().TotalAmountWithVAT);
        }
Пример #3
0
            public PaymentWidgetResult GetWidget(OrderCarrier order, PaymentInfoCarrier paymentInfo)
            {
                var urlHelper        = new UrlHelper(HttpContext.Current.Request.RequestContext);
                var paymentAccountId = _paymentWidgetService.GetPaymentAccountId(paymentInfo.PaymentMethod);
                var klarnaCheckout   = LitiumKcoApi.CreateFrom(
                    paymentAccountId,
                    (orderCarrier, payment, kcoOrder) => _paymentConfig.UpdateDataSentToKlarna(urlHelper, orderCarrier, payment, kcoOrder));

                var checkoutOrder = string.IsNullOrEmpty(paymentInfo.TransactionNumber) ? null : klarnaCheckout.FetchKcoOrder(order);

                if (checkoutOrder == null || checkoutOrder.KlarnaOrderStatus == KlarnaOrderStatus.Incomplete)
                {
                    using (_distributedLockService.AcquireLock($"{nameof(PaymentWidgetService)}:{order.ID}", TimeSpan.FromMinutes(1)))
                    {
                        _paymentInfoCalculator.CalculateFromCarrier(order, _securityToken);
                        var args = CreatePaymentArgs(order, paymentAccountId);

                        checkoutOrder = klarnaCheckout.CreateOrUpdateKcoOrder(order, args);
                    }
                }

                switch (checkoutOrder.KlarnaOrderStatus)
                {
                case KlarnaOrderStatus.Incomplete:
                    return(new PaymentWidgetResult
                    {
                        Id = nameof(PaymentMethod.KlarnaCheckout),
                        IsChangeable = true,
                        ResponseString = checkoutOrder.HtmlSnippet,
                    });

                case KlarnaOrderStatus.Error:
                    throw new Exception(checkoutOrder.HtmlSnippet);

                case KlarnaOrderStatus.Authorized:
                case KlarnaOrderStatus.Cancelled:
                case KlarnaOrderStatus.Captured:
                case KlarnaOrderStatus.Complete:
                case KlarnaOrderStatus.Created:
                    _cartAccessor.Cart.Clear();
                    return(new PaymentWidgetResult
                    {
                        Id = nameof(PaymentMethod.KlarnaCheckout),
                        IsChangeable = false,
                        ResponseString = checkoutOrder.HtmlSnippet,
                    });
                }

                throw new Exception(checkoutOrder.HtmlSnippet);
            }
Пример #4
0
        public void AddDeliveries()
        {
            var paymentInfo = new PaymentInfoCarrier();
            var order       = new OrderCarrier();

            order.PaymentInfo.Add(paymentInfo);
            order.Deliveries.Add(new DeliveryCarrier
            {
                TotalDeliveryCost = 1.999999m,
                TotalVATAmount    = 1.888888m
            });

            sut.Create(order, null).ToList();
            var result = order.PaymentInfo.Single().Rows.Single();

            Assert.Equal(1.999999m, result.TotalPrice);
            Assert.Equal(1.888888m, result.TotalVatAmount);
        }
Пример #5
0
        public void AddDiscounts()
        {
            var paymentInfo = new PaymentInfoCarrier();
            var order       = new OrderCarrier();

            order.PaymentInfo.Add(paymentInfo);
            order.OrderRows.Add(new OrderRowCarrier
            {
                TotalPrice     = 1.999999m,
                TotalVATAmount = 1.888888m
            });
            order.OrderDiscounts.Add(new OrderDiscountCarrier
            {
                DiscountAmount = 1.999999m,
                VATAmount      = 1.888888m
            });

            sut.Create(order, null).ToList();
            var result = order.PaymentInfo.Single().Rows.Last();

            Assert.Equal(-1.999999m, result.TotalPrice);
            Assert.Equal(-1.888888m, result.TotalVatAmount);
        }
Пример #6
0
        public void SetDescriptionToDeliveryDisplayName()
        {
            var channelId        = Guid.NewGuid();
            var deliveryMethodId = Guid.NewGuid();

            var paymentInfo = new PaymentInfoCarrier();
            var order       = new OrderCarrier();

            order.ChannelID = channelId;
            order.PaymentInfo.Add(paymentInfo);
            order.Deliveries.Add(new DeliveryCarrier
            {
                DeliveryMethodID  = deliveryMethodId,
                TotalDeliveryCost = 1.999999m,
                TotalVATAmount    = 1.888888m
            });

            sut.Create(order, null).ToList();
            var result = order.PaymentInfo.Single().Rows.Single();

            Assert.Equal("DeliveryDisplayName", result.Description);
            deliveryMethodService.Received().GetPaymentInfoDescription(deliveryMethodId, channelId);
        }
Пример #7
0
        public void SetsIndex()
        {
            var paymentInfo = new PaymentInfoCarrier();
            var order       = new OrderCarrier();

            order.PaymentInfo.Add(paymentInfo);
            order.OrderRows.Add(new OrderRowCarrier
            {
                TotalPrice     = 1.999999m,
                TotalVATAmount = 1.888888m
            });
            order.Fees.Add(new FeeCarrier
            {
                TotalAmount    = 1.999999m,
                TotalVATAmount = 1.888888m
            });
            order.Deliveries.Add(new DeliveryCarrier
            {
                // We assume the TotalPrice was rounded by OrderTotalCalculator
                TotalDeliveryCost = 1.999999m,
                TotalVATAmount    = 1.888888m
            });
            order.OrderDiscounts.Add(new OrderDiscountCarrier
            {
                // We assume the TotalPrice was rounded by OrderTotalCalculator
                DiscountAmount = 1.999999m,
                VATAmount      = 1.888888m
            });

            sut.Create(order, null).ToList();
            var result = order.PaymentInfo.Single().Rows;

            Assert.Equal(1, result.First().Index);
            Assert.Equal(2, result.Skip(1).First().Index);
            Assert.Equal(3, result.Skip(2).First().Index);
            Assert.Equal(4, result.Skip(3).First().Index);
        }
Пример #8
0
 public abstract IPaymentWidget GetPaymentWidget(PaymentInfoCarrier paymentInfoCarrier);
Пример #9
0
 public abstract bool IsPaymentWidget(PaymentInfoCarrier paymentInfoCarrier);
Пример #10
0
 public override bool IsPaymentWidget(PaymentInfoCarrier paymentInfoCarrier)
 => GetPaymentWidget(paymentInfoCarrier) != null;