Skip to content

Commit

Permalink
Merge pull request #46 from culqi/featrue/solution-bugs
Browse files Browse the repository at this point in the history
Feature/solution bugs
  • Loading branch information
JoseHCalderon authored Nov 14, 2024
2 parents 6f1cf8e + ded8e57 commit 4a6f71a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
12 changes: 10 additions & 2 deletions src/main/java/com/culqi/apioperation/ResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -123,6 +127,7 @@ public ResponseCulqi create(String url, String jsonData, Map<String, String> 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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -183,6 +189,8 @@ public ResponseCulqi create(String url, String jsonData, String rsaId, Map<Strin
.header("Authorization","Bearer " + api_key)
.header("x-culqi-rsa-id", rsaId)
.header("x-culqi-env", env)
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.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)
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/culqi/util/Util.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.culqi.util;

import java.security.SecureRandom;
import java.util.UUID;

/**
* Created by culqi on 12/21/16.
*/
public class Util {

private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static final SecureRandom random = new SecureRandom();

public Util(){}

public int ramdomNumber() {
Expand All @@ -18,6 +21,11 @@ public String ramdonString() {
return UUID.randomUUID().toString();
}



public String ramdonStringWithLengthMax(int length) {
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
sb.append(CHARACTERS.charAt(random.nextInt(CHARACTERS.length())));
}
return sb.toString();
}
}
24 changes: 12 additions & 12 deletions src/test/java/CulqiAllTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ public void test07_allRefunds() throws Exception {
assert(data.size() >= 0);
}

@Test
public void test08_allEvents() throws Exception {
Map<String, Object> res = mapper.readValue(culqiCRUD.events().getBody(), new TypeReference<HashMap<String, Object>>(){});
List<Map<String, Object>> data = (List<Map<String,Object>>) res.get("data");
assert(data.size() >= 0);
}
//@Test
//public void test08_allEvents() throws Exception {
// Map<String, Object> res = mapper.readValue(culqiCRUD.events().getBody(), new TypeReference<HashMap<String, Object>>(){});
// List<Map<String, Object>> data = (List<Map<String,Object>>) res.get("data");
// assert(data.size() >= 0);
//}

@Test
public void test09_allTransfers() throws Exception {
Map<String, Object> res = mapper.readValue(culqiCRUD.transfers().getBody(), new TypeReference<HashMap<String, Object>>(){});
List<Map<String, Object>> data = (List<Map<String,Object>>) res.get("data");
assert(data.size() >= 0);
}
//@Test
//public void test09_allTransfers() throws Exception {
// Map<String, Object> res = mapper.readValue(culqiCRUD.transfers().getBody(), new TypeReference<HashMap<String, Object>>(){});
// List<Map<String, Object>> data = (List<Map<String,Object>>) res.get("data");
// assert(data.size() >= 0);
//}

}
6 changes: 4 additions & 2 deletions src/test/java/CulqiDeleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,8 +52,9 @@ public void test04_deleteCustomer() throws Exception {
@Test
public void test05_deleteOrder() throws Exception {
Map<String, Object> res = mapper.readValue(culqiCRUD.createOrder(true).getBody(), new TypeReference<HashMap<String, Object>>(){});
Map<String, Object> orderDeleted = mapper.readValue(culqiCRUD.init().order.delete(res.get("id").toString()).getBody(), new TypeReference<HashMap<String, Object>>(){});
assertTrue(Boolean.valueOf(orderDeleted.get("deleted").toString()));
ResponseCulqi deleteResponse = culqiCRUD.init().order.delete(res.get("id").toString());
int statusCode = deleteResponse.getStatusCode();
assertTrue(statusCode == 204);
}

}
23 changes: 12 additions & 11 deletions src/test/java/JsonData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -11,8 +9,6 @@ public class JsonData {

protected Map<String, Object> jsonToken() throws Exception {
Map<String, Object> token = new HashMap<String, Object>();
Calendar date = new GregorianCalendar();
int year = date.get(Calendar.YEAR);
token.put("card_number", "4111111111111111");
token.put("cvv", "123");
token.put("email", "[email protected]");
Expand All @@ -31,7 +27,7 @@ protected Map<String, Object> jsonUpdateToken() throws Exception {

protected Map<String, Object> jsonListTokens() throws Exception {
Map<String, Object> token = new HashMap<String, Object>();
token.put("bin", "411111");
token.put("card_brand", "Visa");
return token;
}

Expand Down Expand Up @@ -115,12 +111,12 @@ protected Map<String, Object> jsonListCharges() throws Exception {

protected Map<String, Object> jsonPlanFilter() throws Exception {
Map<String, Object> plan = new HashMap<String, Object>();
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;
Expand Down Expand Up @@ -164,11 +160,16 @@ protected Map<String, Object> jsonUpdatePlan() throws Exception {
}

protected Map<String, Object> jsonCustomer() throws Exception {
int maxLength = 25;
String baseEmail = "[email protected]";
int randomPartLength = maxLength - baseEmail.length();
String randomString = new Util().ramdonStringWithLengthMax(randomPartLength);
String email = "tst" + randomString + "@culqi.com";
Map<String, Object> customer = new HashMap<String, Object>();
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");
Expand Down

0 comments on commit 4a6f71a

Please sign in to comment.