예제 #1
0
        public void PostFlightIntegrationTest()
        {
            Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");

            KondutoCustomer Customer = new KondutoCustomer
            {
                Id    = "28372",
                Name  = "KdtUser",
                Email = "*****@*****.**"
            };

            KondutoOrder order = new KondutoOrder
            {
                Id          = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(),
                Visitor     = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
                TotalAmount = 100.00,
                Customer    = Customer,
                Travel      = KondutoFlightFactory.CreateFlight(),
                Analyze     = true
            };

            try
            {
                konduto.Analyze(order);
                Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }
        }
예제 #2
0
        public void AnalyzeInvalidOrderTest()
        {
            var fakeResponseHandler = new FakeResponseHandler();
            var message             = new HttpResponseMessage(HttpStatusCode.OK);

            message.Content = new StringContent(ORDER_FROM_FILE.ToJson());

            fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
            konduto.__MessageHandler = fakeResponseHandler;

            KondutoOrder orderToSend = new KondutoOrder();

            try
            {
                orderToSend = konduto.Analyze(orderToSend); // do analyze
                Assert.Fail("KondutoInvalidEntityException should have been thrown");
            }
            catch (KondutoInvalidEntityException e)
            {
                //ok
            }
            catch (KondutoHTTPException e)
            {
                Assert.Fail("Expected KondutoInvalidEntityException, but got KondutoHTTPException");
            }
            catch (KondutoUnexpectedAPIResponseException e)
            {
                Assert.Fail("Expected KondutoInvalidEntityException, but got KondutoHTTPException");
            }
        }
예제 #3
0
        /// <summary>
        /// Queries an order from Konduto's API.
        /// Syncronous
        /// @see <a href="http://docs.konduto.com">Konduto API Spec</a>
        /// </summary>
        /// <param name="orderId">the order identifier</param>
        /// <returns>a {@link KondutoOrder} instance</returns>
        /// <exception cref="KondutoHTTPException"></exception>
        /// <exception cref="KondutoUnexpectedAPIResponseException"></exception>
        public KondutoOrder GetOrder(String orderId)
        {
            HttpClient client = CreateHttpClient();

            this.requestBody = orderId;

            var response = client.GetAsync(KondutoGetOrderSuffix(orderId)).Result;

            if (response.IsSuccessStatusCode)
            {
                var responseContent = response.Content;

                String responseString = responseContent.ReadAsStringAsync().Result;
                this.responseBody = responseString;

                JObject getResponse = JsonConvert.DeserializeObject <JObject>(responseString);

                KondutoOrder order = null;

                JToken jt;
                if (getResponse.TryGetValue("order", out jt))
                {
                    order = KondutoModel.FromJson <KondutoOrder>(jt.ToString());
                }

                return(order);
            }
            else
            {
                throw KondutoHTTPExceptionFactory.buildException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
예제 #4
0
        public void GetFlightIntegrationTest()
        {
            Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");

            try
            {
                KondutoOrder order = konduto.GetOrder("1529744771");
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }
        }
예제 #5
0
        public void AnalyzeSuccessfullyTest()
        {
            var fakeResponseHandler = new FakeResponseHandler();
            var message             = new HttpResponseMessage(HttpStatusCode.OK);

            message.Content = new StringContent(ANALYZE_ORDER_RESPONSE.ToString());

            fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
            konduto.__MessageHandler = fakeResponseHandler;

            KondutoOrder orderToSend   = KondutoOrderFactory.basicOrder();
            String       s             = orderToSend.ToJson();
            KondutoOrder orderResponse = null;

            Assert.IsTrue(orderToSend.Recommendation == KondutoRecommendation.none, "basic order should have no recommendation");
            Assert.IsTrue(orderToSend.Score == null, "basic order should have no score");
            Assert.IsNull(orderToSend.Geolocation, "basic order should have no geolocation");
            Assert.IsNull(orderToSend.Device, "basic order should have no device");
            Assert.IsNull(orderToSend.NavigationInfo, "basic order should have no navigation info");
            Assert.IsTrue(orderToSend.Analyze, "basic order should have analyze set to true");

            try
            {
                orderResponse = konduto.Analyze(orderToSend); // do analyze
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be valid");
            }
            catch (KondutoUnexpectedAPIResponseException e)
            {
                Assert.Fail("server should respond with status 200");
            }
            catch (KondutoHTTPException e)
            {
                Assert.Fail("server should respond with status 200");
            }

            Double?actualScore = ORDER_FROM_FILE.Score;
            KondutoRecommendation?actualRecommendation = ORDER_FROM_FILE.Recommendation;
            KondutoGeolocation    actualGeolocation    = ORDER_FROM_FILE.Geolocation;
            KondutoDevice         actualDevice         = ORDER_FROM_FILE.Device;
            KondutoNavigationInfo actualNavigationInfo = ORDER_FROM_FILE.NavigationInfo;

            Assert.IsTrue(orderResponse.Geolocation.Equals(actualGeolocation));
            Assert.AreEqual(orderResponse.Recommendation, actualRecommendation);
            Assert.AreEqual(orderResponse.Device, actualDevice);
            Assert.AreEqual(orderResponse.NavigationInfo, actualNavigationInfo);
            Assert.AreEqual(orderResponse.Score, actualScore);
        }
예제 #6
0
        public void GetIntegrationTest()
        {
            //Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
            Konduto konduto = new Konduto(API_KEY);

            try
            {
                //KondutoOrder order = konduto.GetOrder("1429744771");
                KondutoOrder order = konduto.GetOrder(ORDER_ID);
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }
        }
예제 #7
0
        public void IsValidTest()
        {
            KondutoOrder order = new KondutoOrder();

            Assert.IsFalse(order.IsValid(), "order should be invalid without id");

            order.Id = "order1";
            Assert.IsFalse(order.IsValid(), "order should be invalid without total amount");

            order.TotalAmount = 120.1;
            Assert.IsFalse(order.IsValid(), "order should be invalid without customer");

            order.Customer = KondutoCustomerFactory.BasicCustomer();
            Assert.IsTrue(order.IsValid(), "order should be valid");
            Assert.IsTrue(order.GetError() == null, "order errors should be empty");
        }
예제 #8
0
        public void Setup()
        {
            konduto = new Konduto(API_KEY);

            ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject <JObject>(
                Properties.Resources.konduto_order);

            JToken jt;

            ANALYZE_ORDER_RESPONSE.TryGetValue("order", out jt);
            ORDER_FROM_FILE = KondutoModel.FromJson <KondutoOrder>(jt.ToString());
            ORDER_ID        = ORDER_FROM_FILE.Id;

            NOT_ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject <JObject>(
                Properties.Resources.konduto_order_not_analyzed);
        }
예제 #9
0
        public void SerializationTestWithSeller()
        {
            KondutoOrder order = KondutoOrderFactory.completeOrder();

            order.Seller = KondutoSellerFactory.Create();

            try
            {
                order.ToJson();
                //ok
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be invalid");
            }
        }
예제 #10
0
        public void SerializationTest()
        {
            KondutoOrder order     = KondutoOrderFactory.completeOrder();
            String       orderJSON = KondutoUtils.LoadJson <KondutoOrder>(Properties.Resources.order).ToJson();

            try
            {
                Assert.AreEqual(orderJSON, order.ToJson(), "serialization failed");
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be valid");
            }

            KondutoOrder deserializedOrder = KondutoModel.FromJson <KondutoOrder>(orderJSON);

            Assert.IsTrue(order.Equals(deserializedOrder), "deserialization failed");
        }
예제 #11
0
        public void SerializationTestWithShoppingAndFlight()
        {
            KondutoOrder order = KondutoOrderFactory.completeOrder();

            order.Travel = KondutoFlightFactory.CreateFlight();

            try
            {
                order.ToJson();
                Assert.Fail("order should be invalid");
            }
            catch (KondutoInvalidEntityException e)
            {
                //ok
            }

            order              = KondutoOrderFactory.completeOrder();
            order.Travel       = KondutoFlightFactory.CreateFlight();
            order.ShoppingCart = null;
            //ok
        }
예제 #12
0
        /// <summary>
        /// Sends an order for Konduto and gets it analyzed
        /// (i.e with recommendation, score, device, geolocation and navigation info).
        /// @see <a href="http://docs.konduto.com">Konduto API Spec</a>
        /// </summary>
        /// <param name="order">a {@link KondutoOrder} instance</param>
        /// <exception cref="KondutoInvalidEntityException"></exception>
        /// <exception cref="KondutoHTTPException"></exception>
        /// <exception cref="KondutoUnexpectedAPIResponseException"></exception>
        public KondutoOrder Analyze(KondutoOrder order)
        {
            HttpClient httpClient = CreateHttpClient();

            var x = order.ToJson();

            var response = httpClient.PostAsync(KondutoPostOrderUrl(),
                                                new StringContent(order.ToJson(),
                                                                  Encoding.UTF8,
                                                                  "application/json"));

            this.requestBody = order.ToJson();

            if (response.Result.IsSuccessStatusCode)
            {
                // by calling. Result you are performing a synchronous call
                var responseContent = response.Result.Content;

                // by calling. Result you are synchronously reading the result
                String responseString = responseContent.ReadAsStringAsync().Result;

                this.responseBody = responseString;

                if (order.Analyze)
                {
                    order.MergeKondutoOrderResponse(KondutoAPIFullResponse.FromJson <KondutoAPIFullResponse>(responseString).Order);
                }

                return(order);
            }
            else
            {
                var responseContentError = response.Result.Content != null?response.Result.Content.ReadAsStringAsync().Result : "Error with response";

                throw KondutoHTTPExceptionFactory.buildException((int)response.Result.StatusCode,
                                                                 responseContentError);
            }
        }
예제 #13
0
        public void SendOrderToKondutoButDoNotAnalyzeTest()
        {
            var fakeResponseHandler = new FakeResponseHandler();
            var message             = new HttpResponseMessage(HttpStatusCode.OK);

            message.Content = new StringContent(NOT_ANALYZE_ORDER_RESPONSE.ToString());

            fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
            konduto.__MessageHandler = fakeResponseHandler;

            KondutoOrder orderToSend = KondutoOrderFactory.basicOrder();

            orderToSend.Analyze = false;

            Assert.IsFalse(orderToSend.Analyze, "order analyze should be false");

            try
            {
                orderToSend = konduto.Analyze(orderToSend); // do analyze
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be valid");
            }
            catch (KondutoHTTPException e)
            {
                Assert.Fail("server should respond with status 200");
            }
            catch (KondutoUnexpectedAPIResponseException e)
            {
                Assert.Fail("server should respond with status 200");
            }

            Assert.IsTrue(orderToSend.Score == null);
            Assert.IsTrue(orderToSend.Recommendation == KondutoRecommendation.none);
        }
예제 #14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start Konduto SDK");
            Konduto      konduto = new Konduto("T1234567890ABCDEFGHIJ");
            KondutoOrder order   = new KondutoOrder
            {
                Id             = "orderID",
                Visitor        = "",
                TotalAmount    = 123.4,
                ShippingAmount = 12.23,
                TaxAmount      = 1.23,
                Currency       = "BRL",
                Installments   = 3,
                Ip             = "192.0.0.1",
                Analyze        = true,
                Customer       = new KondutoCustomer
                {
                    Id     = "DotnetCustomer",
                    Name   = "Bill Gates",
                    Email  = "*****@*****.**",
                    TaxId  = "12345678990",
                    Phone1 = "(11)912345678",
                    Phone2 = "(12)998765432",
                    IsNew  = true,
                    IsVip  = true
                },
                Payments = new List <KondutoPayment> {
                    new KondutoCreditCardPayment {
                        Status         = KondutoCreditCardPaymentStatus.approved,
                        Bin            = "123445",
                        Last4          = "1234",
                        ExpirationDate = "022020"
                    }
                }
            };

            if (!order.IsValid())
            {
                Console.WriteLine(order.GetError());
            }
            try
            {
                konduto.Analyze(order);

                Console.WriteLine("Order Recommendation: " + order.Recommendation);
                Console.WriteLine("Order Score: " + order.Score);

                if (order.TriggeredRules != null && order.TriggeredRules.Count > 0)
                {
                    Console.WriteLine("Triggered Rules:");
                    foreach (KondutoTriggeredRules TriggeredRule in order.TriggeredRules)
                    {
                        Console.WriteLine(" " + TriggeredRule.Name);
                    }
                }
                else
                {
                    Console.WriteLine("Order has no triggered rules");
                }

                if (order.TriggeredDecisionList != null && order.TriggeredDecisionList.Count > 0)
                {
                    Console.WriteLine("Triggered DecisionList:");
                    foreach (KondutoTriggeredDecisionList TriggeredDecisionList in order.TriggeredDecisionList)
                    {
                        Console.WriteLine(" " + TriggeredDecisionList.Type + " Decision:" + TriggeredDecisionList.Decision);
                    }
                }
                else
                {
                    Console.WriteLine("Order has no triggered decision list");
                }

                if (order.BureauxQueries != null && order.BureauxQueries.Count > 0)
                {
                    Console.WriteLine("Bureaux Queries:");
                    foreach (KondutoBureauxQueries BureauxQuery in order.BureauxQueries)
                    {
                        Console.WriteLine(" " + BureauxQuery.Service + " response:" + BureauxQuery.Response);
                    }
                }
                else
                {
                    Console.WriteLine("Order has no bureaux queries");
                }

                Console.WriteLine("Order JSON: " + JsonConvert.SerializeObject(order));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            _ = Console.Read();
        }
예제 #15
0
        public void FullJsonIntegrationTest()
        {
            Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");

            KondutoCustomer Customer = new KondutoCustomer
            {
                Id        = "28372",
                Name      = "KdtUser",
                Email     = "*****@*****.**",
                TaxId     = "613.815.776-10",
                Phone1    = "+559912345678",
                Phone2    = "(11)1234-5678",
                IsNew     = false,
                IsVip     = false,
                CreatedAt = "2014-12-21"
            };

            KondutoPayment payment = new KondutoCreditCardPayment
            {
                Type           = KondutoPaymentType.credit,
                Status         = KondutoCreditCardPaymentStatus.approved,
                Bin            = "490172",
                Last4          = "0012",
                ExpirationDate = "052026"
            };

            KondutoAddress billing = new KondutoAddress
            {
                Name     = "Mark Thompson",
                Address1 = "101 Maple Road",
                Address2 = "Apto 33",
                City     = "Mato Grosso",
                State    = "Cuiabá",
                Zip      = "302798",
                Country  = "BR"
            };

            KondutoAddress shipping = new KondutoAddress
            {
                Name     = "Mark Thompson",
                Address1 = "101 Maple Road",
                Address2 = "Apto 33",
                City     = "Mato Grosso",
                State    = "Cuiabá",
                Zip      = "302798",
                Country  = "BR"
            };

            List <KondutoPayment> payments = new List <KondutoPayment> {
                payment
            };

            KondutoItem item1 = new KondutoItem
            {
                Sku         = "9919023",
                ProductCode = "123456789999",
                Category    = 100,
                Name        = "Xbox One",
                Description = "Xbox One Promoção Com 2 Controles",
                UnitCost    = 1999.99,
                Quantity    = 1,
                CreatedAt   = "2014-12-21"
            };

            KondutoItem item2 = new KondutoItem
            {
                Sku         = "0017273",
                Category    = 201,
                Name        = "CD Nirvana Nevermind",
                Description = "CD Nirvana Nevermind",
                UnitCost    = 29.90,
                Quantity    = 2,
                Discount    = 5.00
            };

            KondutoSeller seller = new KondutoSeller
            {
                Id        = "seller",
                Name      = "SampleSeller",
                CreatedAt = "2017-01-01"
            };

            KondutoOrder order = new KondutoOrder
            {
                Id                = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(),
                Visitor           = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
                TotalAmount       = 100.00,
                ShippingAmount    = 6.00,
                TaxAmount         = 12.00,
                Ip                = "201.27.127.73",
                Currency          = "BRL",
                Customer          = Customer,
                Payments          = payments,
                BillingAddress    = billing,
                ShippingAddress   = shipping,
                MessagesExchanged = 2,
                PurchasedAt       = "2014-12-31T13:00:00Z",
                FirstMessage      = "2014-12-31T13:00:00Z",
                Seller            = seller,
                ShoppingCart      = new List <KondutoItem> {
                    item1,
                    item2
                },
                Analyze = true
            };

            try
            {
                konduto.Analyze(order);
                Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }

            try
            {
                KondutoOrder getOrder = konduto.GetOrder(order.Id);
                Assert.IsNotNull(getOrder);
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }
        }
예제 #16
0
        public void invalidOrderSerializationThrowsExceptionTest()
        {
            KondutoOrder order = new KondutoOrder();

            order.ToJson();         // triggers invalid customer exception
        }
예제 #17
0
        public void PutIntegrationTest()
        {
            String id = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();

            Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");

            KondutoCustomer Customer = new KondutoCustomer
            {
                Id    = "28372",
                Name  = "KdtUser",
                Email = "*****@*****.**"
            };

            KondutoOrder order = new KondutoOrder
            {
                Id          = id,
                Visitor     = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
                TotalAmount = 100.00,
                Customer    = Customer,
                Analyze     = true
            };

            try
            {
                konduto.Analyze(order);
                Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }

            try
            {
                konduto.UpdateOrderStatus(id, KondutoOrderStatus.fraud, "Manual Review");
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }

            try
            {
                konduto.UpdateOrderStatus(id, KondutoOrderStatus.not_authorized, "Manual Review");
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }
            catch (Exception e)
            {
                Assert.Fail("Exception: " + e.ToString());
            }

            try
            {
                KondutoOrder updatedOrder = konduto.GetOrder(id);
            }
            catch (KondutoException ex)
            {
                Assert.Fail("Konduto exception shouldn't happen here.");
            }
        }