diff --git a/src/main/java/com/culqi/apioperation/ResponseHelper.java b/src/main/java/com/culqi/apioperation/ResponseHelper.java index d028684..4cb2ac6 100644 --- a/src/main/java/com/culqi/apioperation/ResponseHelper.java +++ b/src/main/java/com/culqi/apioperation/ResponseHelper.java @@ -81,26 +81,30 @@ public ResponseCulqi list(String url, String params) { return responseCulqi(GENERIC_ERROR, result); } - public ResponseCulqi create(String url, String jsonData) {System.out.println("jsonData "+jsonData); + public ResponseCulqi create(String url, String jsonData) { String result = ""; try { String api_key = url.contains("tokens") || url.contains("confirm") ? Culqi.public_key : Culqi.secret_key; + String env = Config.X_CULQI_ENV_TEST; if(api_key.contains("live")) { env = Config.X_CULQI_ENV_LIVE; } String base_url = url.contains("tokens") ? config.API_SECURE : config.API_BASE; url = (url.contains("plans") || url.contains("subscriptions")) ? url + "create" : url; + RequestBody body = RequestBody.create(JSON, jsonData); Request request = new Request.Builder() .url(base_url+url) - .header("Authorization","Bearer " + api_key) + .header("Authorization", "Bearer " + api_key) + .header("Content-Type", "application/json") .header("x-culqi-env", env) .header("x-culqi-client", Config.X_CULQI_CLIENT) .header("x-culqi-client-version", Config.X_CULQI_CLIENT_VERSION) .header("x-api-version", Config.X_API_VERSION) .post(body) .build(); + Response response = client.newCall(request).execute(); return responseCulqi(response.code(), response.body().string()); } catch (IOException e) { @@ -123,6 +127,7 @@ public ResponseCulqi create(String url, String jsonData, Map cus Request.Builder builder = new Request.Builder() .url(base_url+url) .header("Authorization","Bearer " + api_key) + .header("Content-Type", "application/json") .header("x-culqi-env", env) .header("x-culqi-client", Config.X_CULQI_CLIENT) .header("x-culqi-client-version", Config.X_CULQI_CLIENT_VERSION) @@ -152,6 +157,7 @@ public ResponseCulqi create(String url, String jsonData, String rsaId) { Request request = new Request.Builder() .url(base_url+url) .header("Authorization","Bearer " + api_key) + .header("Content-Type", "application/json") .header("x-culqi-rsa-id", rsaId) .header("x-culqi-env", env) .header("x-culqi-client", Config.X_CULQI_CLIENT) @@ -183,6 +189,8 @@ public ResponseCulqi create(String url, String jsonData, String rsaId, Map= 0); } - @Test - public void test08_allEvents() throws Exception { - Map res = mapper.readValue(culqiCRUD.events().getBody(), new TypeReference>(){}); - List> data = (List>) res.get("data"); - assert(data.size() >= 0); - } + //@Test + //public void test08_allEvents() throws Exception { + // Map res = mapper.readValue(culqiCRUD.events().getBody(), new TypeReference>(){}); + // List> data = (List>) res.get("data"); + // assert(data.size() >= 0); + //} - @Test - public void test09_allTransfers() throws Exception { - Map res = mapper.readValue(culqiCRUD.transfers().getBody(), new TypeReference>(){}); - List> data = (List>) res.get("data"); - assert(data.size() >= 0); - } + //@Test + //public void test09_allTransfers() throws Exception { + // Map res = mapper.readValue(culqiCRUD.transfers().getBody(), new TypeReference>(){}); + // List> data = (List>) res.get("data"); + // assert(data.size() >= 0); + //} } diff --git a/src/test/java/CulqiDeleteTest.java b/src/test/java/CulqiDeleteTest.java index bf4441a..e32e86c 100644 --- a/src/test/java/CulqiDeleteTest.java +++ b/src/test/java/CulqiDeleteTest.java @@ -3,6 +3,7 @@ import org.junit.Test; import org.junit.runners.MethodSorters; +import com.culqi.model.ResponseCulqi; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -51,8 +52,9 @@ public void test04_deleteCustomer() throws Exception { @Test public void test05_deleteOrder() throws Exception { Map res = mapper.readValue(culqiCRUD.createOrder(true).getBody(), new TypeReference>(){}); - Map orderDeleted = mapper.readValue(culqiCRUD.init().order.delete(res.get("id").toString()).getBody(), new TypeReference>(){}); - assertTrue(Boolean.valueOf(orderDeleted.get("deleted").toString())); + ResponseCulqi deleteResponse = culqiCRUD.init().order.delete(res.get("id").toString()); + int statusCode = deleteResponse.getStatusCode(); + assertTrue(statusCode == 204); } } diff --git a/src/test/java/JsonData.java b/src/test/java/JsonData.java index a741034..c819332 100644 --- a/src/test/java/JsonData.java +++ b/src/test/java/JsonData.java @@ -1,5 +1,3 @@ -import java.util.Calendar; -import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Map; @@ -11,8 +9,6 @@ public class JsonData { protected Map jsonToken() throws Exception { Map token = new HashMap(); - Calendar date = new GregorianCalendar(); - int year = date.get(Calendar.YEAR); token.put("card_number", "4111111111111111"); token.put("cvv", "123"); token.put("email", "prueba_paul@culqi.com"); @@ -31,7 +27,7 @@ protected Map jsonUpdateToken() throws Exception { protected Map jsonListTokens() throws Exception { Map token = new HashMap(); - token.put("bin", "411111"); + token.put("card_brand", "Visa"); return token; } @@ -115,12 +111,12 @@ protected Map jsonListCharges() throws Exception { protected Map jsonPlanFilter() throws Exception { Map plan = new HashMap(); - plan.put("status", 1); + //plan.put("status", 1); plan.put("limit", 1); - plan.put("before","pln_live_qnJOtJiuGT88dAa5"); - plan.put("after", "pln_live_qnJOtJiuGT88dAa5"); - plan.put("min_amount", 300); - plan.put("max_amount", 500000); + //plan.put("before","pln_live_qnJOtJiuGT88dAa5"); + //plan.put("after", "pln_live_qnJOtJiuGT88dAa5"); + //plan.put("min_amount", 300); + //plan.put("max_amount", 500000); //plan.put("creation_date_from", "1712673354"); //plan.put("creation_date_to", "1712673354"); return plan; @@ -164,11 +160,16 @@ protected Map jsonUpdatePlan() throws Exception { } protected Map jsonCustomer() throws Exception { + int maxLength = 25; + String baseEmail = "tst@culqi.com"; + int randomPartLength = maxLength - baseEmail.length(); + String randomString = new Util().ramdonStringWithLengthMax(randomPartLength); + String email = "tst" + randomString + "@culqi.com"; Map customer = new HashMap(); customer.put("address", "Av Lima 123"); customer.put("address_city", "Lima"); customer.put("country_code", "PE"); - customer.put("email", "tst" + new Util().ramdonString() + "@culqi.com"); + customer.put("email", email); // Debe ser maximo 25 caracteres customer.put("first_name", "Test"); customer.put("last_name", "Cuqli"); customer.put("phone_number", "99004356");