public string GenerateSingleUseCardToken() { var publicKey = Guid.NewGuid().ToString(); 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=" + publicKey, 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_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_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()); }
public void Init() { _client = new MPRESTClient(); }