public void ExecuteRequest_Post_Json() { MPRESTClient client = new MPRESTClient(); var jsonObject = new JObject(); jsonObject.Add("firstName", "Clark"); jsonObject.Add("lastName", "Kent"); jsonObject.Add("year", 2018); DummyClass dummy = new DummyClass("Dummy description", DateTime.Now, 1000); WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("x-idempotency-key", dummy.GetType().GUID.ToString()); MPAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "https://httpbin.org/post", PayloadType.JSON, jsonObject, headers, 0, 0); JObject jsonResponse = JObject.Parse(response.StringResponse.ToString()); List <JToken> lastName = MPCoreUtils.FindTokens(jsonResponse, "lastName"); Assert.AreEqual("Kent", lastName.First().ToString()); List <JToken> year = MPCoreUtils.FindTokens(jsonResponse, "year"); Assert.AreEqual("2018", year.First().ToString()); }
private Card NewCard() { var payload = new JObject { { "card_number", "4074090000000004" }, { "security_code", "123" }, { "expiration_month", "11" }, { "expiration_year", DateTime.Now.AddYears(5).Year.ToString() }, { "cardholder", new JObject { { "name", "APRO" }, { "identification", new JObject { { "type", "CPF" }, { "Number", "19119119100" }, } }, } }, }; var url = String.Format("https://api.mercadopago.com/v1/card_tokens?public_key={0}", PublicKey); var response = _client.ExecuteRequest(HttpMethod.POST, url, PayloadType.JSON, payload); var jsonResponse = JObject.Parse(response.StringResponse.ToString()); var token = jsonResponse.GetValue("id").ToString(); return(new Card { CustomerId = "649457098-FybpOkG6zH8QRm", Token = token, }); }
public void ExecuteRequest_Get() { MPRESTClient client = new MPRESTClient(); MPAPIResponse response = client.ExecuteRequest(HttpMethod.GET, "https://httpbin.org/get", PayloadType.X_WWW_FORM_URLENCODED, null, null, 0, 0); JObject jsonResponse = JObject.Parse(response.StringResponse.ToString()); JProperty prop = jsonResponse.Properties().FirstOrDefault(p => p.Name.Contains("url")); string url = prop != null?prop.Value.ToString() : string.Empty; Assert.AreEqual("https://httpbin.org/get", url); }
public static string SingleUseCardToken(string PublicKey, string Status) { JObject payload = JObject.Parse(CardDummyWithSpecificStatus(Status)); MPRESTClient client = new MPRESTClient(); String path = "https://api.mercadopago.com/v1/card_tokens?public_key=" + PublicKey; MPAPIResponse responseCardToken = client.ExecuteRequest(HttpMethod.POST, path, PayloadType.JSON, payload, null, 0, 1); JObject jsonResponse = JObject.Parse(responseCardToken.StringResponse.ToString()); List <JToken> tokens = MPCoreUtils.FindTokens(jsonResponse, "id"); return(tokens.First().ToString()); }
public void ExecuteRequest_PostAndPutMustHavePayload() { MPRESTClient client = new MPRESTClient(); try { MPAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "https://httpbin.org/post", PayloadType.X_WWW_FORM_URLENCODED, null, null, 0, 0); } catch (MPRESTException ex) { Assert.AreEqual("Must include payload for this method.", ex.Message); } try { MPAPIResponse response = client.ExecuteRequest(HttpMethod.PUT, "https://httpbin.org/put", PayloadType.X_WWW_FORM_URLENCODED, null, null, 0, 0); } catch (MPRESTException ex) { Assert.AreEqual("Must include payload for this method.", ex.Message); } }
public void ExecuteRequest_GetAndDeleteNustNotHavePayload() { MPRESTClient client = new MPRESTClient(); try { MPAPIResponse response = client.ExecuteRequest(HttpMethod.GET, "https://httpbin.org/get", PayloadType.X_WWW_FORM_URLENCODED, new JObject(), null, 0, 0); } catch (MPRESTException ex) { Assert.AreEqual("Payload not supported for this method.", ex.Message); } try { MPAPIResponse response = client.ExecuteRequest(HttpMethod.DELETE, "https://httpbin.org/delete", PayloadType.X_WWW_FORM_URLENCODED, new JObject(), null, 0, 0); } catch (MPRESTException ex) { Assert.AreEqual("Payload not supported for this method.", ex.Message); } }
public void ExecuteRequest_Post() { MPRESTClient client = new MPRESTClient(); var jsonObject = new JObject(); jsonObject.Add("firstName", "Clark"); jsonObject.Add("lastName", "Kent"); jsonObject.Add("year", 2018); MPAPIResponse 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 = MPCoreUtils.FindTokens(jsonResponse, "Content-Type"); Assert.AreEqual("application/x-www-form-urlencoded", contentType.First().ToString()); }
public string GenerateSingleUseCardToken() { JObject payload = JObject.Parse("{ \"card_number\": \"4544610257481730\", \"security_code\": \"122\", \"expiration_month\": \"7\", \"expiration_year\": \"2030\", \"cardholder\": { \"name\": \"Test test\", \"identification\": { \"type\": \"DNI\", \"number\": \"12345678\" } } }"); MPRESTClient client = new MPRESTClient(); MPAPIResponse responseCardToken = client.ExecuteRequest( HttpMethod.POST, "https://api.mercadopago.com/v1/card_tokens?public_key=" + Environment.GetEnvironmentVariable("PUBLIC_KEY"), PayloadType.JSON, payload, null, 0, 1); JObject jsonResponse = JObject.Parse(responseCardToken.StringResponse.ToString()); List <JToken> tokens = MPCoreUtils.FindTokens(jsonResponse, "id"); return(tokens.First().ToString()); }
public void ExecuteRequest_Get_ShortTimeoutWillFail() { MPRESTClient client = new MPRESTClient(); var jsonObject = new JObject(); jsonObject.Add("firstName", "Comander"); jsonObject.Add("lastName", "Shepard"); jsonObject.Add("year", 2126); try { MPAPIResponse response = client.ExecuteRequest(HttpMethod.POST, "https://httpbin.org/post", PayloadType.JSON, jsonObject, null, 5, 0); } catch { Assert.Pass(); } Assert.Fail(); }
public void ExecuteRequest_Get_ProperTimeoutWillWork() { MPRESTClient client = new MPRESTClient(); var jsonObject = new JObject(); jsonObject.Add("firstName", "Comander"); jsonObject.Add("lastName", "Shepard"); jsonObject.Add("year", 2126); MPAPIResponse 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 = MPCoreUtils.FindTokens(jsonResponse, "lastName"); Assert.AreEqual("Shepard", lastName.First().ToString()); List <JToken> year = MPCoreUtils.FindTokens(jsonResponse, "year"); Assert.AreEqual("2126", year.First().ToString()); }