Exemple #1
0
        public void RemoveTransientRows()
        {
            var row = new PaymentInfoRowCarrier();

            var order = new OrderCarrier
            {
                PaymentInfo = new List <PaymentInfoCarrier>
                {
                    new PaymentInfoCarrier
                    {
                        Rows = new List <PaymentInfoRowCarrier>
                        {
                            new PaymentInfoRowCarrier(),
                            new PaymentInfoRowCarrier
                            {
                                CarrierState = new CarrierState
                                {
                                    IsMarkedForCreating = false
                                }
                            }
                        }
                    }
                }
            };


            sut.Create(order, null).ToList();

            Assert.Single(order.PaymentInfo.Single().Rows);
        }
Exemple #2
0
        public void MarkExistingRowsForDeleting()
        {
            var row = new PaymentInfoRowCarrier
            {
                CarrierState = new CarrierState
                {
                    IsMarkedForCreating = false
                }
            };

            var order = new OrderCarrier
            {
                PaymentInfo = new List <PaymentInfoCarrier>
                {
                    new PaymentInfoCarrier
                    {
                        Rows = new List <PaymentInfoRowCarrier>
                        {
                            row
                        }
                    }
                }
            };


            sut.Create(order, null).ToList();

            Assert.True(row.CarrierState.IsMarkedForDeleting);
        }
        /// <summary>
        ///     Validates the specified order carrier.
        /// </summary>
        /// <param name="orderCarrier">The order carrier.</param>
        /// <param name="checkoutFlowInfo">The checkout flow info.</param>
        public void Validate(OrderCarrier orderCarrier, CheckoutFlowInfo checkoutFlowInfo)
        {
            //get allowed delivery methods, if configuration is missing, consider all delivery methods as allowed.
            var allowedDeliveryMethodIDs = _channelService.Get(orderCarrier.ChannelID)?.CountryLinks?.FirstOrDefault(x => x.CountrySystemId == orderCarrier.CountryID)?.DeliveryMethodSystemIds ??
                                           _moduleECommerce.DeliveryMethods.GetAll().Select(x => x.ID).ToList();

            foreach (var delivery in orderCarrier.Deliveries)
            {
                var deliveryMethod = _moduleECommerce.DeliveryMethods.Get(delivery.DeliveryMethodID, _moduleECommerce.AdminToken);
                if (deliveryMethod != null && allowedDeliveryMethodIDs.Contains(deliveryMethod.ID))
                {
                    continue;
                }

                if (allowedDeliveryMethodIDs.Count > 0)
                {
                    var payload = new DeliveryPayloadInfo
                    {
                        DeliveryAddress  = delivery.Address,
                        DeliveryMethodId = allowedDeliveryMethodIDs[0]
                    };
                    _moduleECommerce.CheckoutFlow.EditDelivery(orderCarrier, delivery.ID, payload, _moduleECommerce.AdminToken);
                }
                throw new PreOrderValidationException("accelerator.validation.deliverymethod.nolongersupported".AsAngularResourceString());
            }
        }
Exemple #4
0
        private void SetOrderMarker(OrderCarrier order)
        {
            if (order.EndLatLng == null || this.ordersMarkers.ContainsKey(order.Id))
            {
                return;
            }

            MarkerOptions options = new MarkerOptions();
            MarkerTag     tag     = new MarkerTag {
                OrderId = order.Id, SalepointId = order.SalepointId
            };

            tag.Type = MarkerType.Order;

            BitmapDescriptor icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.endpoint_marker);

            options.SetIcon(icon);

            string title = string.Concat(order.DestinationCity, ", ", order.DestinationAddress);

            options.SetTitle(title);
            options.SetPosition(new LatLng(order.EndLatLng.lat, order.EndLatLng.lng));

            this.activity.RunOnUiThread(() =>
            {
                Marker marker = this.map.AddMarker(options);
                marker.Tag    = tag;
                this.ordersMarkers.Add(order.Id, marker);
            });
        }
Exemple #5
0
 /// <summary>
 ///     Validates the specified order carrier.
 /// </summary>
 /// <param name="orderCarrier">The order carrier.</param>
 /// <param name="checkoutFlowInfo">The checkout flow info.</param>
 public void Validate(OrderCarrier orderCarrier, CheckoutFlowInfo checkoutFlowInfo)
 {
     if (orderCarrier.OrderRows.Count(x => !x.CarrierState.IsMarkedForDeleting) == 0)
     {
         throw new PreOrderValidationException("accelerator.validation.cart.doesnotcontainsproduct".AsAngularResourceString());
     }
 }
Exemple #6
0
        public void CalculateTotalOrderVat()
        {
            var order = new OrderCarrier();

            order.Deliveries.Add(new DeliveryCarrier
            {
                DeliveryCost  = 1.67226891m,
                VATPercentage = 0.19m
            });
            order.Fees.Add(new FeeCarrier
            {
                Amount        = 1.67226891m,
                VATPercentage = 0.19m
            });
            order.OrderRows.Add(new OrderRowCarrier
            {
                UnitListPrice = 1.67226891m,
                // Currency decimals in this example = 3
                TotalPrice    = 1.672m,
                VATPercentage = 0.19m,
                Quantity      = 1
            });
            order.OrderDiscounts.Add(new OrderDiscountCarrier
            {
                DiscountAmountWithVAT = 1.99m,
                VATPercentage         = 0.19m
            });

            sut.CalculateFromCarrier(order, null);

            Assert.Equal(0.318m * 2, order.TotalVAT);
        }
Exemple #7
0
        public void CalculateTotalDeliveryVat_VatPercentage_NoOrderTotal_ZeroRowTotal_DontCrash()
        {
            var delivery = new DeliveryCarrier
            {
                DeliveryCost        = 1.672268908m,
                DeliveryCostWithVAT = 1.99m
            };

            var order = new OrderCarrier
            {
                OrderRows = new List <OrderRowCarrier>
                {
                    new OrderRowCarrier
                    {
                        UnitListPrice     = 0,
                        UnitCampaignPrice = 0m,
                        VATPercentage     = 0.2400m,
                        TotalPrice        = 0,
                        TotalVATAmount    = 0,
                        Quantity          = 1m,
                    }
                }
            };

            order.Deliveries.Add(delivery);

            sut.CalculateTotalDeliveryVat(order);
        }
        /// <summary>
        ///     Adds the cash on delivery external payment method., by using Litium default "DirectPay" as the payment method.
        ///     Note: To use, Klarna has to configure the "Cash on delivery" external payment method for the merchant account.
        /// </summary>
        /// <param name="orderCarrier">The checkout order.</param>
        /// <param name="options">The checkout options</param>
        private void AddCashOnDeliveryExternalPaymentMethod(OrderCarrier orderCarrier, CheckoutOptions options)
        {
            var checkoutPage = _websiteService.Get(orderCarrier.WebSiteID)?.Fields.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.CheckouPage)?.EntitySystemId.MapTo <Page>();

            if (checkoutPage == null)
            {
                return;
            }

            var urlHelper   = new UrlHelper(HttpContext.Current.Request.RequestContext);
            var redirectUrl = urlHelper.Action(checkoutPage, routeValues: new { action = nameof(CheckoutController.PlaceOrderDirect) });
            var routeValues = new
            {
                PaymentProvider = "DirectPay",
                PaymentMethod   = "DirectPayment",
                RedirectUrl     = redirectUrl
            };

            var cashOnDeliveryExternalPayment = new ExternalPaymentMethod
            {
                Description = "Direct payment description",
                Fee         = 0,
                Name        = "Postförskott",
                RedirectUrl = new Uri(urlHelper.Action("ChangePaymentMethod", "KlarnaPayment", routeValues, Uri.UriSchemeHttps)).AbsoluteUri,
            };

            options.ExternalPaymentMethods = new List <ExternalPaymentMethod>
            {
                cashOnDeliveryExternalPayment
            };
        }
Exemple #9
0
        public virtual void CalculateTotalDiscount(OrderCarrier orderCarrier)
        {
            Currency currency      = GetCurrency(orderCarrier);
            decimal? vatPercentage = GetAverageVatPercentage(orderCarrier);

            decimal orderTotalDiscount    = 0;
            decimal orderTotalDiscountVat = 0;

            foreach (var discount in orderCarrier.OrderDiscounts.Where(r => !r.CarrierState.IsMarkedForDeleting))
            {
                if (vatPercentage != null)
                {
                    discount.VATPercentage = (decimal)vatPercentage;
                }
                if (discount.DiscountAmountWithVAT > 0)
                {
                    discount.DiscountAmountWithVAT = Math.Round(discount.DiscountAmountWithVAT, currency.GetDecimals());
                    discount.DiscountAmount        = Math.Round(discount.DiscountAmountWithVAT / (1 + discount.VATPercentage), currency.GetDecimals());
                }
                else
                {
                    discount.DiscountAmount        = Math.Round(discount.DiscountAmount, currency.GetDecimals());
                    discount.DiscountAmountWithVAT = Math.Round(discount.DiscountAmount * (1 + discount.VATPercentage), currency.GetDecimals());
                }
                discount.VATAmount     = discount.DiscountAmountWithVAT - discount.DiscountAmount;
                orderTotalDiscount    += discount.DiscountAmount;
                orderTotalDiscountVat += discount.VATAmount;
            }
            orderCarrier.TotalDiscount    = orderTotalDiscount;
            orderCarrier.TotalDiscountVAT = orderTotalDiscountVat;
        }
 private decimal GetOrderTotal(OrderCarrier orderCarrier)
 {
     return
         (orderCarrier.OrderRows.Where(r => !r.CarrierState.IsMarkedForDeleting).Sum(r => r.TotalPrice) +
          orderCarrier.Fees.Where(r => !r.CarrierState.IsMarkedForDeleting).Sum(r => r.TotalAmount) +
          orderCarrier.Deliveries.Where(r => !r.CarrierState.IsMarkedForDeleting).Sum(r => r.TotalDeliveryCost));
 }
 public void Validate(OrderCarrier orderCarrier, CheckoutFlowInfo checkoutFlowInfo)
 {
     if (orderCarrier.GrandTotal < 300)
     {
         throw new PreOrderValidationException("OrderGrandTotalOverLimitValidatorErrorMessage".AsWebSiteString());
     }
 }
        public void CalculateOverallVatPercentageBasedOnOrderRows_ZeroTotalRows_DontCrash()
        {
            var delivery = new DeliveryCarrier
            {
                DeliveryCost        = 1.672268908m,
                DeliveryCostWithVAT = 1.99m
            };

            var order = new OrderCarrier
            {
                OrderRows = new List <OrderRowCarrier>
                {
                    new OrderRowCarrier
                    {
                        UnitListPrice     = 0,
                        UnitCampaignPrice = 0,
                        VATPercentage     = 0.2400m,
                        TotalPrice        = 0,
                        TotalVATAmount    = 0,
                        Quantity          = 1m,
                    }
                }
            };

            order.Deliveries.Add(delivery);

            var sut = new OrderGrandTotalCalculator();

            sut.Calculate(order, null);
        }
        public void SalesOrder_OrderDiscountHigherThanTotal_NoNegativeOrderValue()
        {
            var order = new OrderCarrier
            {
                OrderRows = new List <OrderRowCarrier>
                {
                    new OrderRowCarrier
                    {
                        UnitListPrice     = 100,
                        UnitCampaignPrice = 0m,
                        VATPercentage     = 0.25m,
                        TotalPrice        = 100m,
                        TotalVATAmount    = 25m,
                        Quantity          = 1m,
                    }
                }
            };

            order.OrderDiscounts.Add(new OrderDiscountCarrier
            {
                DiscountAmount = 1000,
                VATAmount      = 250
            });

            var sut = new OrderGrandTotalCalculator();

            sut.Calculate(order, null);

            Assert.Equal(0, order.GrandTotal);
        }
Exemple #14
0
        /// <summary>
        ///     Validates the specified order carrier.
        /// </summary>
        /// <param name="orderCarrier">The order carrier.</param>
        /// <param name="checkoutFlowInfo">The checkout flow info.</param>
        public void Validate(OrderCarrier orderCarrier, CheckoutFlowInfo checkoutFlowInfo)
        {
            //get allowed payment methods, if configuration is missing, consider all payment methods as allowed.
            var allowedPaymentMethodIDs = _channelService.Get(orderCarrier.ChannelID)?.CountryLinks?.FirstOrDefault(x => x.CountrySystemId == orderCarrier.CountryID)?.PaymentMethodSystemIds ??
                                          _moduleECommerce.PaymentMethods.GetAll().Select(x => x.ID).ToList();

            foreach (var paymentInfo in orderCarrier.PaymentInfo)
            {
                var paymentMethod = _moduleECommerce.PaymentMethods.Get(paymentInfo.PaymentMethod, paymentInfo.PaymentProvider, _moduleECommerce.AdminToken);
                if (paymentMethod != null && allowedPaymentMethodIDs.Contains(paymentMethod.ID))
                {
                    continue;
                }

                if (allowedPaymentMethodIDs.Count > 0)
                {
                    var defaultPaymentmethod = _moduleECommerce.PaymentMethods.Get(allowedPaymentMethodIDs[0], _moduleECommerce.AdminToken);
                    if (defaultPaymentmethod != null)
                    {
                        _moduleECommerce.CheckoutFlow.AddPaymentInfo(orderCarrier, defaultPaymentmethod.PaymentProviderName, defaultPaymentmethod.Name, paymentInfo.BillingAddress, _moduleECommerce.AdminToken);
                    }
                }
                throw new PreOrderValidationException("accelerator.validation.paymentmethod.nolongersupported".AsAngularResourceString());
            }
        }
        /// <summary>
        ///     Gets the campaign ids.
        /// </summary>
        /// <param name="orderCarrier">The order carrier.</param>
        /// <returns></returns>
        public static List <Guid> GetCampaignIds(this OrderCarrier orderCarrier)
        {
            var result = new List <Guid>();

            if (orderCarrier != null)
            {
                //order row campaigns.
                if (orderCarrier.OrderRows != null)
                {
                    result.AddRange(orderCarrier.OrderRows.Where(x => x.CampaignID != Guid.Empty).Select(x => x.CampaignID));
                }
                //delivery campaigns.
                if (orderCarrier.Deliveries != null)
                {
                    result.AddRange(orderCarrier.Deliveries.Where(x => x.CampaignID != Guid.Empty).Select(x => x.CampaignID));
                }
                //fee campaigns
                if (orderCarrier.Fees != null)
                {
                    result.AddRange(orderCarrier.Fees.Where(x => x.CampaignID != Guid.Empty).Select(x => x.CampaignID));
                }
                //order campaigns.
                if (orderCarrier.OrderDiscounts != null)
                {
                    result.AddRange(orderCarrier.OrderDiscounts.Where(x => x.CampaignID != Guid.Empty).Select(x => x.CampaignID));
                }
            }
            return(result);
        }
        /// <summary>
        ///     Validates the specified order carrier.
        /// </summary>
        /// <param name="orderCarrier">The order carrier.</param>
        /// <param name="checkoutFlowInfo">The checkout flow info.</param>
        public void Validate(OrderCarrier orderCarrier, CheckoutFlowInfo checkoutFlowInfo)
        {
            if (orderCarrier.OrderRows.Count != 0 && !string.IsNullOrEmpty(orderCarrier.CampaignInfo))
            {
                var withVoucherCode = orderCarrier.Clone(true, true, true, true, true, true);
                var noVoucherCode   = withVoucherCode.Clone(true, true, true, true, true, true);
                noVoucherCode.CampaignInfo = string.Empty;

                _moduleECommerce.Orders.CalculateOrderTotals(noVoucherCode, _securityToken);
                _moduleECommerce.Orders.CalculateOrderTotals(withVoucherCode, _securityToken);

                //if the order total becomes modified, it surely is due to the voucherCode since the carriers are just clones of each other and only difference is voucher code.
                if (noVoucherCode.GrandTotal == withVoucherCode.GrandTotal)
                {
                    //the order grand total is not modified, but still the voucher code may have resulted in a different campaign.
                    //obtain all campaign ids in the order carrier and see whether withVoucherCode resulted in a new campaign id.
                    var noVoucherCodeCampaignIds   = noVoucherCode.GetCampaignIds();
                    var withVoucherCodeCampaignIds = withVoucherCode.GetCampaignIds();

                    //check whether withVoucherCodeCampaignIds has any campaign ids, that are not there in noVoucherCodeCampaignIds.
                    if (!withVoucherCodeCampaignIds.Except(noVoucherCodeCampaignIds).Any())
                    {
                        throw new PreOrderValidationException("accelerator.validation.campaigncode.notvalid".AsAngularResourceString());
                    }
                }
            }
        }
Exemple #17
0
        /// <summary>
        ///     Adds the cash on delivery external payment method., by using Litium default "DirectPay" as the payment method.
        ///     Note: To use, Klarna has to configure the "Cash on delivery" external payment method for the merchant account.
        /// </summary>
        private void AddCashOnDeliveryExternalPaymentMethod(UrlHelper urlHelper, OrderCarrier orderCarrier, CheckoutOrder klarnaCheckoutOrder)
        {
            var checkoutPage = _websiteService.Get(orderCarrier.WebSiteID)?.Fields.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.CheckouPage)?.EntitySystemId.MapTo <Page>();
            var channel      = _channelService.Get(orderCarrier.ChannelID);

            if (checkoutPage == null || channel == null)
            {
                return;
            }

            var redirectUrl = urlHelper.Action(checkoutPage, routeValues: new { action = nameof(CheckoutController.PlaceOrderDirect) }, channel: channel);

            var routeValues = new
            {
                PaymentProvider = "DirectPay",
                PaymentMethod   = "DirectPayment",
                RedirectUrl     = redirectUrl
            };

            var changePaymentProviderUrl      = new Uri(urlHelper.Action("ChangePaymentMethod", "KlarnaPayment", routeValues, Uri.UriSchemeHttps)).AbsoluteUri;
            var cashOnDeliveryExternalPayment = new PaymentProvider
            {
                Name        = "Cash on delivery",
                RedirectUrl = changePaymentProviderUrl,
                Fee         = 0
            };

            klarnaCheckoutOrder.ExternalPaymentMethods = new List <PaymentProvider>
            {
                cashOnDeliveryExternalPayment
            };
        }
Exemple #18
0
        public void CalculateTotalOrderRowsVat_CalledByCalculateFromCarrier()
        {
            var row = new OrderRowCarrier
            {
                UnitListPrice = 1.67226891m,
                // Currency decimals in this example = 3
                TotalPrice    = 1.672m,
                VATPercentage = 0.19m,
                Quantity      = 1
            };
            var skipRow = new OrderRowCarrier
            {
                UnitListPrice = 1.67226891m,
                // Currency decimals in this example = 3
                TotalPrice    = 1.672m,
                VATPercentage = 0.19m,
                Quantity      = 1,
                CarrierState  =
                {
                    IsMarkedForCreating = false,
                    IsMarkedForDeleting = true
                }
            };

            var order = new OrderCarrier();

            order.OrderRows.Add(row);
            order.OrderRows.Add(row);
            order.OrderRows.Add(skipRow);

            sut.CalculateFromCarrier(order, null);

            Assert.Equal(0.636m, order.TotalOrderRowVAT);
        }
Exemple #19
0
        private void AddOrderViewModel(OrderCarrier order)
        {
            var orderVM = Mvx.IocConstruct <FloatingPendingOrderViewModel>();

            orderVM.Order = order;
            this.Orders.Add(orderVM);
        }
Exemple #20
0
        public virtual void CalculateTotalDeliveryVat(OrderCarrier orderCarrier)
        {
            Currency currency      = GetCurrency(orderCarrier);
            decimal? vatPercentage = GetAverageVatPercentage(orderCarrier);

            decimal orderTotalDelivery    = 0;
            decimal orderTotalDeliveryVat = 0;

            foreach (var delivery in orderCarrier.Deliveries.Where(r => !r.CarrierState.IsMarkedForDeleting))
            {
                if (vatPercentage != null)
                {
                    delivery.VATPercentage = (decimal)vatPercentage;
                }
                if (delivery.KeepDeliveryCostWithVatConstant)
                {
                    var totalDeliveryCost = delivery.DeliveryCostWithVAT / (1 + delivery.VATPercentage) - delivery.DiscountAmount;
                    delivery.TotalDeliveryCost = Math.Round(totalDeliveryCost, currency.GetDecimals());
                    delivery.TotalVATAmount    = Math.Round(delivery.TotalDeliveryCost * delivery.VATPercentage, currency.GetDecimals());
                }
                else
                {
                    delivery.TotalDeliveryCost = Math.Round(delivery.DeliveryCost - delivery.DiscountAmount, currency.GetDecimals());
                    delivery.TotalVATAmount    = Math.Round(delivery.TotalDeliveryCost * delivery.VATPercentage, currency.GetDecimals());
                }
                orderTotalDelivery    += delivery.TotalDeliveryCost;
                orderTotalDeliveryVat += delivery.TotalVATAmount;
            }
            orderCarrier.TotalDeliveryCost    = orderTotalDelivery;
            orderCarrier.TotalDeliveryCostVAT = orderTotalDeliveryVat;
        }
Exemple #21
0
        public virtual void CalculateTotalFeeVat(OrderCarrier orderCarrier)
        {
            Currency currency      = GetCurrency(orderCarrier);
            decimal? vatPercentage = GetAverageVatPercentage(orderCarrier);

            decimal orderTotalFee    = 0;
            decimal orderTotalFeeVat = 0;

            foreach (var fee in orderCarrier.Fees.Where(r => !r.CarrierState.IsMarkedForDeleting))
            {
                if (vatPercentage != null)
                {
                    fee.VATPercentage = (decimal)vatPercentage;
                }
                if (fee.KeepAmountWithVATConstant)
                {
                    var totalAmount = fee.AmountWithVAT / (1 + fee.VATPercentage) - fee.DiscountAmount;
                    fee.TotalAmount    = Math.Round(totalAmount, currency.GetDecimals());
                    fee.TotalVATAmount = Math.Round(fee.TotalAmount * fee.VATPercentage, currency.GetDecimals());
                }
                else
                {
                    fee.TotalAmount    = Math.Round(fee.Amount - fee.DiscountAmount, currency.GetDecimals());
                    fee.TotalVATAmount = Math.Round(fee.TotalAmount * fee.VATPercentage, currency.GetDecimals());
                }
                orderTotalFee    += fee.TotalAmount;
                orderTotalFeeVat += fee.TotalVATAmount;
            }
            orderCarrier.TotalFee    = orderTotalFee;
            orderCarrier.TotalFeeVAT = orderTotalFeeVat;
        }
        /// <summary>
        ///     Validates the specified order carrier.
        /// </summary>
        /// <param name="orderCarrier">The order carrier.</param>
        /// <param name="checkoutFlowInfo">The checkout flow info.</param>
        public void Validate(OrderCarrier orderCarrier, CheckoutFlowInfo checkoutFlowInfo)
        {
            if (orderCarrier.OrderRows.Count != 0)
            {
                var personId  = orderCarrier.CustomerInfo?.PersonID ?? _securityToken.UserID;
                var orderRows = from orderRowCarrier in orderCarrier.OrderRows
                                let result = _orderRowFactory.Create(new ShoppingCartItemCarrier
                {
                    ArticleNumber = orderRowCarrier.ArticleNumber,
                    ProductID     = orderRowCarrier.ProductID,
                    CustomerID    = personId,
                    LanguageID    = FoundationContext.Current.LanguageID,
                    Quantity      = orderRowCarrier.Quantity,
                    Comments      = orderRowCarrier.Comments
                },
                                                                     orderCarrier.WebSiteID,
                                                                     orderCarrier.CurrencyID,
                                                                     personId,
                                                                     orderCarrier.CountryID,
                                                                     _securityToken)
                                             where result != null
                                             where Math.Round(orderRowCarrier.UnitListPrice, 2) != Math.Round(result.UnitListPrice, 2) ||
                                             Math.Round(orderRowCarrier.VATPercentage, 2) != Math.Round(result.VATPercentage, 2)
                                             select orderRowCarrier;

                if (orderRows.Any())
                {
                    throw new PreOrderValidationException("accelerator.validation.productprices.haschanged".AsAngularResourceString());
                }
            }
        }
        /// <summary>
        ///     Updates the data sent to klarna.
        ///     if the project has specific data to be sent to Klarna, outside the order carrier,
        ///     or has them as additional order info, and is not handled by the Klarna addOn, modify the klarnaCheckoutOrder
        ///     parameter.
        ///     it is the klarnaCheckoutOrder object which is a "KlarnaCheckoutOrder" that will be sent to Klarna checkout api at
        ///     Klarna.
        ///     the format of klarnaCheckoutOrder parameter is described in Klarna API documentation https://developers.klarna.com.
        /// </summary>
        /// <param name="orderCarrier">The order carrier.</param>
        /// <param name="klarnaCheckoutOrder">The data sent to klarna.</param>
        /// <exception cref="System.NotImplementedException"></exception>
#pragma warning disable IDE0060 // Remove unused parameter
        public void UpdateDataSentToKlarna(OrderCarrier orderCarrier, Dictionary <string, object> klarnaCheckoutOrder)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            //Example:
            //Following test code modify the Klarna article number.

            //if (klarnaCheckoutOrder.ContainsKey("cart"))
            //{
            //    var cart = klarnaCheckoutOrder["cart"] as Dictionary<string, object>;
            //    if (cart != null)
            //    {
            //        if (cart.ContainsKey("items"))
            //        {
            //            var klarnaCartItems = cart["items"] as List<Dictionary<string, object>>;
            //            if (klarnaCartItems != null)
            //            {
            //                foreach (var klarnaOrderRow in klarnaCartItems)
            //                {
            //                    klarnaOrderRow["reference"] = "U-" + klarnaOrderRow["reference"];
            //                }
            //            }
            //        }
            //    }
            //}
        }
            public KlarnaPaymentArgs CreatePaymentArgs(OrderCarrier order, string paymentAccountId)
            {
                var tlsUsage = _routeRequestLookupInfoAccessor.RouteRequestLookupInfo.IsSecureConnection;

                if (!tlsUsage)
                {
                    this.Log().Trace("Klarna Checkout Validation is disabled. To enable the validate you need to use https on the checkout page.");
                }

                var checkoutFlowInfo = Cart.CheckoutFlowInfo;

                checkoutFlowInfo.ExecutePaymentMode     = ExecutePaymentMode.Reserve;
                checkoutFlowInfo.RequireConsumerConfirm = false;

                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

                var checkoutPage             = _requestModelAccessor.RequestModel.WebsiteModel.Fields.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.CheckouPage);
                var checkoutPageUrl          = GetAbsolutePageUrl(checkoutPage);
                var checkoutPageEntity       = checkoutPage.EntitySystemId.MapTo <PageModel>();
                var termsAndConditionPage    = checkoutPageEntity.GetValue <PointerPageItem>(CheckoutPageFieldNameConstants.TermsAndConditionsPage);
                var termsAndConditionPageUrl = GetAbsolutePageUrl(termsAndConditionPage);

                var channelUri = new Uri(_urlService.GetUrl(_requestModelAccessor.RequestModel.ChannelModel.Channel, new ChannelUrlArgs()
                {
                    AbsoluteUrl = true
                }));
                var channelUrl      = channelUri.AbsoluteUri;
                var confirmationUrl = new Uri(channelUri, urlHelper
                                              .Action("Confirmation", "KlarnaPayment", new { AccountId = paymentAccountId, TransactionNumber = "{checkout.order.id}" }, Uri.UriSchemeHttps))?
                                      .AbsoluteUri
                                      .Replace("%7B", "{").Replace("%7D", "}");
                var validateUrl = new Uri(channelUri, urlHelper
                                          .Action("Validate", "KlarnaPayment", new { AccountId = paymentAccountId, TransactionNumber = "{checkout.order.id}" }, Uri.UriSchemeHttps))?
                                  .AbsoluteUri
                                  .Replace("%7B", "{").Replace("%7D", "}");
                var pushUrl = new Uri(channelUri, urlHelper
                                      .Action("PushNotification", "KlarnaPayment", new { TransactionNumber = "{checkout.order.id}" }, Uri.UriSchemeHttps))?
                              .AbsoluteUri
                              .Replace("%7B", "{").Replace("%7D", "}");

                var args = new KlarnaPaymentArgs
                {
                    CustomerPersonalNumber = string.Empty, //no ssn.
                    KlarnaCampaignCode     = -1,
                    ExecuteScript          = null,         //not used
                    TermsUrl              = termsAndConditionPageUrl,
                    ConfirmationUrl       = confirmationUrl,
                    PushNotificationUrl   = pushUrl,
                    CheckoutUrl           = checkoutPageUrl, //if cancelled, go back to checkout page.
                    ClientLanguage        = CultureInfo.CurrentUICulture.Name,
                    BackToStoreUrl        = channelUrl,
                    ValidationUrl         = tlsUsage ? validateUrl : null,
                    UserHostAddress       = StudioKlarnaApi.GetClientIP(),
                    PaymentMode           = ExecutePaymentMode.Reserve,
                    KlarnaCheckoutOptions = _paymentConfig.GetCheckoutOptions(order)
                };

                return(args);
            }
Exemple #25
0
            public OrderCarrierWrapper(OrderCarrier order)
            {
                previous = Thread.GetData(Thread.GetNamedDataSlot(slotKey)) as OrderCarrier;

                Thread.SetData(
                    Thread.GetNamedDataSlot(slotKey),
                    order);
            }
Exemple #26
0
        private void RemoveOrderViewModel(OrderCarrier order)
        {
            var orderToRemove = this.Orders.Where(x => x.Order.Id == order.Id).FirstOrDefault();

            if (orderToRemove != null)
            {
                this.Orders.Remove(orderToRemove);
            }
        }
        private void AddPendingOrder(OrderCarrier order)
        {
            if (this.PendingOrders != null && this.PendingOrders.All(x => x.Id != order.Id))
            {
                this.PendingOrders.Add(order);
                this.PendingOrdersUpdated?.Invoke(this, new ServiceEvent <CarrierOrdersEvents>(CarrierOrdersEvents.AddedOrder, order));
            }

            CrossLocalNotifications.Current.Show("Dodano zamówienie", String.Concat("Od: ", order.SalepointName, "\n", "Do miejsca: ", order.DestinationAddress), order.Id);
        }
        public async Task Accept(OrderCarrier order)
        {
            await this.carrierOrdersApi.AcceptOrder(order.Id);

            this.AcceptedOrders.Add(order);
            this.AcceptedOrdersUpdated?.Invoke(this, new ServiceEvent <CarrierOrdersEvents>(CarrierOrdersEvents.AddedOrder, order));

            this.PendingOrders.Remove(order);
            this.PendingOrdersUpdated?.Invoke(this, new ServiceEvent <CarrierOrdersEvents>(CarrierOrdersEvents.RemovedOrder, order));
        }
        public void IsSet()
        {
            var order = new OrderCarrier();

            using (CalculatorContext.Use(order))
            {
                Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier());
            }

            Assert.Null(CalculatorContext.GetCurrentOrderCarrier());
        }
Exemple #30
0
        public override void Calculate(OrderCarrier orderCarrier, SecurityToken securityToken)
        {
            base.Calculate(orderCarrier, securityToken);

            var vat = GetAverageVatPercentage(orderCarrier);

            if (vat != null)
            {
                orderCarrier.OverallVatPercentage = (decimal)vat;
            }
        }