public void ExecuteRequest_Post_Json()
        {
            MercadoPagoRestClient client = new MercadoPagoRestClient();

            JObject jsonObject = new JObject
            {
                { "firstName", "Clark" },
                { "lastName", "Kent" },
                { "year", 2018 }
            };
            DummyClass          dummy   = new DummyClass("Dummy description", DateTime.Now, 1000);
            WebHeaderCollection headers = new WebHeaderCollection
            {
                { "x-idempotency-key", dummy.GetType().GUID.ToString() }
            };

            MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "", PayloadType.JSON, jsonObject, headers, 0, 0);
            JObject jsonResponse            = JObject.Parse(response.StringResponse.ToString());

            List <JToken> lastName = MercadoPagoCoreUtils.FindTokens(jsonResponse, "lastName");

            Assert.AreEqual("Kent", lastName.First().ToString());

            List <JToken> year = MercadoPagoCoreUtils.FindTokens(jsonResponse, "year");

            Assert.AreEqual("2018", year.First().ToString());
        }
Пример #2
0
        public static string SingleUseCardToken(string publicKey, string status)
        {
            JObject payload = JObject.Parse(CardDummyWithSpecificStatus(status));
            MercadoPagoRestClient client = new MercadoPagoRestClient();

            MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.POST, $"https://api.mercadopago.com/v1/card_tokens?public_key={publicKey}", PayloadType.JSON, payload, null, 0, 1);

            JObject       jsonResponse = JObject.Parse(response.StringResponse.ToString());
            List <JToken> tokens       = MercadoPagoCoreUtils.FindTokens(jsonResponse, "id");

            return(tokens.First().ToString());
        }
        public void ExecuteRequest_Post()
        {
            MercadoPagoRestClient client = new MercadoPagoRestClient();

            JObject jsonObject = new JObject
            {
                { "firstName", "Clark" },
                { "lastName", "Kent" },
                { "year", 2018 }
            };

            MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "https://httpbin.org/post", PayloadType.X_WWW_FORM_URLENCODED, jsonObject, null, 0, 0);

            JObject       jsonResponse = JObject.Parse(response.StringResponse.ToString());
            List <JToken> contentType  = MercadoPagoCoreUtils.FindTokens(jsonResponse, "Content-Type");

            Assert.AreEqual("application/x-www-form-urlencoded", contentType.First().ToString());
        }
        public void ExecuteRequest_PostAndPutMustHavePayload()
        {
            MercadoPagoRestClient client = new MercadoPagoRestClient();

            try
            {
                MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "https://httpbin.org/post", PayloadType.X_WWW_FORM_URLENCODED, null, null, 0, 0);
            }
            catch (MercadoPagoRestException exception)
            {
                Assert.AreEqual("Must include payload for this method.", exception.Message);
            }

            try
            {
                MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.PUT, "https://httpbin.org/put", PayloadType.X_WWW_FORM_URLENCODED, null, null, 0, 0);
            }
            catch (MercadoPagoRestException exception)
            {
                Assert.AreEqual("Must include payload for this method.", exception.Message);
            }
        }
        public void ExecuteRequest_GetAndDeleteNustNotHavePayload()
        {
            MercadoPagoRestClient client = new MercadoPagoRestClient();

            try
            {
                MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.GET, "https://httpbin.org/get", PayloadType.X_WWW_FORM_URLENCODED, new JObject(), null, 0, 0);
            }
            catch (MercadoPagoRestException exception)
            {
                Assert.AreEqual("Payload not supported for this method.", exception.Message);
            }

            try
            {
                MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.DELETE, "https://httpbin.org/delete", PayloadType.X_WWW_FORM_URLENCODED, new JObject(), null, 0, 0);
            }
            catch (MercadoPagoRestException exception)
            {
                Assert.AreEqual("Payload not supported for this method.", exception.Message);
            }
        }
        public void ExecuteRequest_Get_ShortTimeoutWillFail()
        {
            MercadoPagoRestClient client = new MercadoPagoRestClient();

            JObject jsonObject = new JObject
            {
                { "firstName", "Comander" },
                { "lastName", "Shepard" },
                { "year", 2126 }
            };

            try
            {
                MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "https://httpbin.org/post", PayloadType.JSON, jsonObject, null, 5, 0);
            }
            catch (Exception)
            {
                Assert.Pass();
            }

            Assert.Fail();
        }
        public void ExecuteRequest_Get_ProperTimeoutWillWork()
        {
            MercadoPagoRestClient client = new MercadoPagoRestClient();

            JObject jsonObject = new JObject
            {
                { "firstName", "Comander" },
                { "lastName", "Shepard" },
                { "year", 2126 }
            };

            MercadoPagoAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "https://httpbin.org/post", PayloadType.JSON, jsonObject, null, 20000, 0);

            Assert.AreEqual(200, response.StatusCode);

            JObject       jsonResponse = response.JsonObjectResponse;
            List <JToken> lastName     = MercadoPagoCoreUtils.FindTokens(jsonResponse, "lastName");

            Assert.AreEqual("Shepard", lastName.First().ToString());

            List <JToken> year = MercadoPagoCoreUtils.FindTokens(jsonResponse, "year");

            Assert.AreEqual("2126", year.First().ToString());
        }