public void TestAmountWithRelativeDiscountWithDifferentVatRatesPresent()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountExVat(100.00M)
                                                    .SetVatPercent(25)
                                                    .SetQuantity(2))
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountExVat(100.00M)
                                                    .SetVatPercent(6)
                                                    .SetQuantity(1))
                                       .AddDiscount(Item.RelativeDiscount()
                                                    .SetDiscountPercent(25));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter <CreateOrderBuilder>();

            List <HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat    = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(3));
            // 5000*.25 = 1250
            // 600*.25 = 150
            // matches 1400 discount
            Assert.That(formattedTotalAmount, Is.EqualTo(26700)); // 35600 - 8900 discount
            Assert.That(formattedTotalVat, Is.EqualTo(4200));     //  5600 - 1400 discount (= 10000/35600 *5600) discount
        }
        public void TestAmountWithFixedDiscountIncVatOnlyWithDifferentVatRatesPresent()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountExVat(100.00M)
                                                    .SetVatPercent(25)
                                                    .SetQuantity(2))
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountExVat(100.00M)
                                                    .SetVatPercent(6)
                                                    .SetQuantity(1))
                                       .AddDiscount(Item.FixedDiscount()
                                                    .SetAmountIncVat(100.00M));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter <CreateOrderBuilder>();
            List <HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);

            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat    = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(3));
            // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
            // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
            // matches 15,73 discount (= 100/356 *56) discount
            Assert.That(formattedTotalAmount, Is.EqualTo(25600)); // 35600 - 10000 discount
            Assert.That(formattedTotalVat, Is.EqualTo(4027));     //  5600 -  1573 discount (= 10000/35600 *5600) discount
        }
示例#3
0
        public void TestGetTotalVatNegative()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountIncVat(-100L)
                                                    .SetVatPercent(25)
                                                    .SetQuantity(2));
            var formatter = new HostedRowFormatter <CreateOrderBuilder>();
            List <HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);

            Assert.That(formatter.GetTotalVat(), Is.EqualTo(-4000L));
        }
示例#4
0
        protected void FormatRequestValues()
        {
            var errors = ValidateOrder();

            if (errors.Length > 0)
            {
                throw new SveaWebPayValidationException(errors);
            }

            var formatter = new HostedRowFormatter <CreateOrderBuilder>();

            HrowBuilder = formatter.FormatRows(CrOrderBuilder);
            Amount      = formatter.GetTotalAmount();
            Vat         = formatter.GetTotalVat();
        }
        public void TestAmountFromMultipleItemsWithRelativeDiscountWithDifferentVatRatesPresent2()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountExVat(69.99M)
                                                    .SetVatPercent(25)
                                                    .SetQuantity(1))
                                       .AddDiscount(Item.RelativeDiscount()
                                                    .SetDiscountPercent(25));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter <CreateOrderBuilder>();

            List <HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat    = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(2));
            Assert.That(formattedTotalAmount, Is.EqualTo(6562)); // 8748,75 - 2187,18 discount rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(1312));    // 1749,75 - 437,5 discount (1750*.25) rounded half-to-even
        }
        public void TestAmountFromMultipleItemsWithRelativeDiscountWithDifferentVatRatesPresent()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountExVat(69.99M)
                                                    .SetVatPercent(25)
                                                    .SetQuantity(30))
                                       .AddDiscount(Item.RelativeDiscount()
                                                    .SetDiscountPercent(25));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter <CreateOrderBuilder>();

            List <HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat    = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(2));
            Assert.That(formattedTotalAmount, Is.EqualTo(196847)); // (262462,5  - 65615,625 discount (25%) rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(39369));     //  52492,5  - 13123,125 discount (25%) rounded half-to-even
        }
        public void TestAmountFromMultipleItemsWithFixedDiscountIncVatOnly()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetAmountExVat(69.99M)
                                                    .SetVatPercent(25)
                                                    .SetQuantity(30))
                                       .AddDiscount(Item.FixedDiscount()
                                                    .SetAmountIncVat(10.00M));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter <CreateOrderBuilder>();

            List <HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat    = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(2));
            Assert.That(formattedTotalAmount, Is.EqualTo(261462)); // 262462,5 - 1000 discount rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(52292));     // 52492,5  -  200 discount (= 10/2624,62*524,92) rounded half-to-even
        }
        public void TestAmountFromMultipleItemsDefinedWithExVatAndVatPercent()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetArticleNumber("0")
                                                                        .SetName("testCalculateRequestValuesCorrectTotalAmountFromMultipleItems")
                                                                        .SetDescription("testCalculateRequestValuesCorrectTotalAmountFromMultipleItems")
                                                                        .SetAmountExVat(69.99M)
                                                                        .SetVatPercent(25)
                                                                        .SetQuantity(30)
                                                                        .SetUnit("st"));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter<CreateOrderBuilder>();

            List<HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(1));
            Assert.That(formattedTotalAmount, Is.EqualTo(262462)); // 262462,5 rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(52492)); // 52492,5 rounded half-to-even
        }
        public void TestAmountFromMultipleItemsDefinedWithExVatAndIncVat()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                       .AddOrderRow(Item.OrderRow()
                                                    .SetArticleNumber("0")
                                                    .SetName("testCalculateRequestValuesCorrectTotalAmountFromMultipleItems")
                                                    .SetDescription("testCalculateRequestValuesCorrectTotalAmountFromMultipleItems")
                                                    .SetAmountExVat(69.99M)
                                                    .SetAmountIncVat(87.4875M)                     // if low precision here, i.e. 87.49, we'll get a cumulative rounding error
                                                    .SetQuantity(30)
                                                    .SetUnit("st"));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter <CreateOrderBuilder>();

            List <HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat    = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(1));
            Assert.That(formattedTotalAmount, Is.EqualTo(262462)); // 262462,5 rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(52492));     // 52492,5 rounded half-to-even
        }
        protected void FormatRequestValues()
        {
            var errors = ValidateOrder();
            if (errors.Length > 0)
            {
                throw new SveaWebPayValidationException(errors);
            }

            var formatter = new HostedRowFormatter<CreateOrderBuilder>();

            HrowBuilder = formatter.FormatRows(CrOrderBuilder);
            Amount = formatter.GetTotalAmount();
            Vat = formatter.GetTotalVat();
        }
        public void TestAmountWithRelativeDiscountWithDifferentVatRatesPresent()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetAmountExVat(100.00M)
                                                                        .SetVatPercent(25)
                                                                        .SetQuantity(2))
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetAmountExVat(100.00M)
                                                                        .SetVatPercent(6)
                                                                        .SetQuantity(1))
                                                       .AddDiscount(Item.RelativeDiscount()
                                                                        .SetDiscountPercent(25));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter<CreateOrderBuilder>();

            List<HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(3));
            // 5000*.25 = 1250
            // 600*.25 = 150
            // matches 1400 discount
            Assert.That(formattedTotalAmount, Is.EqualTo(26700)); // 35600 - 8900 discount
            Assert.That(formattedTotalVat, Is.EqualTo(4200)); //  5600 - 1400 discount (= 10000/35600 *5600) discount
        }
        public void TestAmountWithFixedDiscountIncVatOnlyWithDifferentVatRatesPresent()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetAmountExVat(100.00M)
                                                                        .SetVatPercent(25)
                                                                        .SetQuantity(2))
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetAmountExVat(100.00M)
                                                                        .SetVatPercent(6)
                                                                        .SetQuantity(1))
                                                       .AddDiscount(Item.FixedDiscount()
                                                                        .SetAmountIncVat(100.00M));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter<CreateOrderBuilder>();
            List<HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);

            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(3));
            // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
            // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
            // matches 15,73 discount (= 100/356 *56) discount
            Assert.That(formattedTotalAmount, Is.EqualTo(25600)); // 35600 - 10000 discount
            Assert.That(formattedTotalVat, Is.EqualTo(4027)); //  5600 -  1573 discount (= 10000/35600 *5600) discount
        }
        public void TestAmountFromMultipleItemsWithRelativeDiscountWithDifferentVatRatesPresent2()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetAmountExVat(69.99M)
                                                                        .SetVatPercent(25)
                                                                        .SetQuantity(1))
                                                       .AddDiscount(Item.RelativeDiscount()
                                                                        .SetDiscountPercent(25));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter<CreateOrderBuilder>();

            List<HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(2));
            Assert.That(formattedTotalAmount, Is.EqualTo(6562)); // 8748,75 - 2187,18 discount rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(1312)); // 1749,75 - 437,5 discount (1750*.25) rounded half-to-even
        }
        public void TestAmountFromMultipleItemsWithRelativeDiscountWithDifferentVatRatesPresent()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetAmountExVat(69.99M)
                                                                        .SetVatPercent(25)
                                                                        .SetQuantity(30))
                                                       .AddDiscount(Item.RelativeDiscount()
                                                                        .SetDiscountPercent(25));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter<CreateOrderBuilder>();

            List<HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(2));
            Assert.That(formattedTotalAmount, Is.EqualTo(196847)); // (262462,5  - 65615,625 discount (25%) rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(39369)); //  52492,5  - 13123,125 discount (25%) rounded half-to-even
        }
        public void TestAmountFromMultipleItemsWithFixedDiscountIncVatOnly()
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig())
                                                       .AddOrderRow(Item.OrderRow()
                                                                        .SetAmountExVat(69.99M)
                                                                        .SetVatPercent(25)
                                                                        .SetQuantity(30))
                                                       .AddDiscount(Item.FixedDiscount()
                                                                        .SetAmountIncVat(10.00M));

            // follows HostedPayment calculateRequestValues() outline:
            var formatter = new HostedRowFormatter<CreateOrderBuilder>();

            List<HostedOrderRowBuilder> formatRowsList = formatter.FormatRows(order);
            long formattedTotalAmount = formatter.GetTotalAmount();
            long formattedTotalVat = formatter.GetTotalVat();

            Assert.That(formatRowsList.Count, Is.EqualTo(2));
            Assert.That(formattedTotalAmount, Is.EqualTo(261462)); // 262462,5 - 1000 discount rounded half-to-even
            Assert.That(formattedTotalVat, Is.EqualTo(52292)); // 52492,5  -  200 discount (= 10/2624,62*524,92) rounded half-to-even
        }