Ejemplo n.º 1
0
        public void Orders_CreateKlarnaOrder()
        {
            // Arrange
            var url     = ConfigurationManager.AppSettings["MultiSafepayAPI"];
            var apiKey  = ConfigurationManager.AppSettings["MultiSafepayAPIKey"];
            var client  = new MultiSafepayClient(apiKey, url);
            var orderId = Guid.NewGuid().ToString();

            var orderRequest = OrderRequest.CreateDirectKlarnaOrder(orderId, "product description", 1210, "EUR",
                                                                    new PaymentOptions("http://example.com/notify", "http://example.com/success", "http://example.com/failed"),
                                                                    GatewayInfo.Klarna(new DateTime(1970, 07, 10), "male", "+31 (0)20 8500 500", "*****@*****.**"),
                                                                    new ShoppingCart
            {
                Items = new[]
                {
                    new ShoppingCartItem("10001", "Test Product", 10.0, 1, "EUR")
                }
            },
                                                                    new CheckoutOptions()
            {
                TaxTables = new TaxTables()
                {
                    DefaultTaxTable = new TaxTable()
                    {
                        Name  = "Default",
                        Rules = new[] { new TaxRateRule()
                                        {
                                            Rate = 0.21
                                        } },
                        ShippingTaxed = false
                    }
                }
            },
                                                                    new Customer()
            {
                FirstName   = "Testperson-nl",
                LastName    = "Approved",
                HouseNumber = "1/XI",
                Address1    = "Neherkade",
                City        = "Gravenhage",
                Country     = "NL",
                PostCode    = "2521VA",
            },
                                                                    new DeliveryAddress()
            {
                FirstName   = "Testperson-nl",
                LastName    = "Approved",
                HouseNumber = "1/XI",
                Address1    = "Neherkade",
                City        = "Gravenhage",
                Country     = "NL",
                PostCode    = "2521VA",
            }
                                                                    );

            // Act
            var result = client.CreateOrder(orderRequest);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(orderRequest.OrderId, result.OrderId);
            Assert.IsTrue(result.PaymentUrl.StartsWith("http://example.com/success?transactionid=")); // redirect to success URL
        }
        public void Order_CreateDirectKlarna_SetsRequiredProperties()
        {
            // Act
            var order = OrderRequest.CreateDirectKlarnaOrder("orderid", "description", 1000, "EUR",
                                                             new PaymentOptions("notificationUrl", "successRedirectUrl", "cancelRedirectUrl"),
                                                             GatewayInfo.Klarna(new DateTime(1986, 08, 31), "male", "+31 (0)20 8500 500", "*****@*****.**"),
                                                             new ShoppingCart
            {
                Items = new[]
                {
                    new ShoppingCartItem("Test Product", 10, 2, "EUR"),
                }
            },
                                                             new CheckoutOptions()
            {
                TaxTables = new TaxTables()
                {
                    DefaultTaxTable = new TaxTable()
                    {
                        Name  = "Default",
                        Rules = new[] { new TaxRateRule()
                                        {
                                            Rate = 0.21
                                        } },
                        ShippingTaxed = false
                    }
                }
            },
                                                             new Customer
            {
                FirstName   = "John",
                LastName    = "Doe",
                HouseNumber = "39",
                Address1    = "Kraanspoor",
                City        = "Amsterdam",
                Country     = "NL",
                PostCode    = "1033SC"
            },
                                                             new DeliveryAddress
            {
                FirstName   = "John",
                LastName    = "Doe",
                HouseNumber = "39",
                Address1    = "Kraanspoor",
                City        = "Amsterdam",
                Country     = "NL",
                PostCode    = "1033SC"
            }
                                                             );

            // Assert
            Assert.IsNotNull(order.Type);
            Assert.IsNotNull(order.GatewayId);
            Assert.IsNotNull(order.OrderId);
            Assert.IsNotNull(order.CurrencyCode);
            Assert.IsNotNull(order.AmountInCents);
            Assert.IsNotNull(order.Description);
            Assert.IsNotNull(order.GatewayInfo);
            Assert.IsNotNull(order.GatewayInfo.Birthday);
            Assert.IsNotNull(order.GatewayInfo.Gender);
            Assert.IsNotNull(order.GatewayInfo.Phone);
            Assert.IsNotNull(order.GatewayInfo.Email);
            Assert.IsNotNull(order.PaymentOptions);
            Assert.IsNotNull(order.PaymentOptions.NotificationUrl);
            Assert.IsNotNull(order.PaymentOptions.SuccessRedirectUrl);
            Assert.IsNotNull(order.PaymentOptions.CancelRedirectUrl);
            Assert.IsNotNull(order.ShoppingCart);
            Assert.IsNotNull(order.ShoppingCart.Items);
            Assert.IsNotNull(order.ShoppingCart.Items[0]);
            Assert.IsNotNull(order.ShoppingCart.Items[0].Name);
            Assert.IsNotNull(order.ShoppingCart.Items[0].UnitPrice);
            Assert.IsNotNull(order.ShoppingCart.Items[0].Quantity);
            Assert.IsNotNull(order.CheckoutOptions.TaxTables.DefaultTaxTable);
            Assert.IsNotNull(order.Customer);
            Assert.IsNotNull(order.Customer.FirstName);
            Assert.IsNotNull(order.Customer.LastName);
            Assert.IsNotNull(order.Customer.Address1);
            Assert.IsNotNull(order.Customer.HouseNumber);
            Assert.IsNotNull(order.Customer.City);
            Assert.IsNotNull(order.Customer.Country);
            Assert.IsNotNull(order.DeliveryAddress);
            Assert.IsNotNull(order.DeliveryAddress.FirstName);
            Assert.IsNotNull(order.DeliveryAddress.LastName);
            Assert.IsNotNull(order.DeliveryAddress.Address1);
            Assert.IsNotNull(order.DeliveryAddress.HouseNumber);
            Assert.IsNotNull(order.DeliveryAddress.City);
            Assert.IsNotNull(order.DeliveryAddress.Country);


            Assert.AreEqual(OrderType.Direct, order.Type);
            Assert.AreEqual("KLARNA", order.GatewayId);
            Assert.AreEqual("orderid", order.OrderId);
            Assert.AreEqual("EUR", order.CurrencyCode);
            Assert.AreEqual(1000, order.AmountInCents);
            Assert.AreEqual("description", order.Description);
            Assert.AreEqual(new DateTime(1986, 8, 31), order.GatewayInfo.Birthday);
            Assert.AreEqual("male", order.GatewayInfo.Gender);
            Assert.AreEqual("+31 (0)20 8500 500", order.GatewayInfo.Phone);
            Assert.AreEqual("*****@*****.**", order.GatewayInfo.Email);
            Assert.AreEqual("notificationUrl", order.PaymentOptions.NotificationUrl);
            Assert.AreEqual("successRedirectUrl", order.PaymentOptions.SuccessRedirectUrl);
            Assert.AreEqual("cancelRedirectUrl", order.PaymentOptions.CancelRedirectUrl);
            Assert.AreEqual("Test Product", order.ShoppingCart.Items[0].Name);
            Assert.AreEqual(10, order.ShoppingCart.Items[0].UnitPrice);
            Assert.AreEqual(2, order.ShoppingCart.Items[0].Quantity);
            Assert.AreEqual("Default", order.CheckoutOptions.TaxTables.DefaultTaxTable.Name);
            Assert.AreEqual(0.21, order.CheckoutOptions.TaxTables.DefaultTaxTable.Rules[0].Rate);
            Assert.AreEqual("John", order.Customer.FirstName);
            Assert.AreEqual("Doe", order.Customer.LastName);
            Assert.AreEqual("Kraanspoor", order.Customer.Address1);
            Assert.AreEqual("39", order.Customer.HouseNumber);
            Assert.AreEqual("Amsterdam", order.Customer.City);
            Assert.AreEqual("NL", order.Customer.Country);
            Assert.AreEqual("John", order.DeliveryAddress.FirstName);
            Assert.AreEqual("Doe", order.DeliveryAddress.LastName);
            Assert.AreEqual("Kraanspoor", order.DeliveryAddress.Address1);
            Assert.AreEqual("39", order.DeliveryAddress.HouseNumber);
            Assert.AreEqual("Amsterdam", order.DeliveryAddress.City);
            Assert.AreEqual("NL", order.DeliveryAddress.Country);
        }