Я решил ваш запрос.Вот ответ
Функция для получения сведений о карте.
public Map<String, Object> getCardDetails() throws PayPalRESTException {
Map<String, Object> response = new HashMap<String, Object>();
try {
APIContext context = new APIContext(clientId, clientSecret, "sandbox");
CreditCard creditCard = CreditCard.get(context, "CARD-9D2462350Y753123NLS4YVTY");
response.put("status", "sucsess");
response.put("Details", creditCard);
return response;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
API для получения сведений о карте
@RequestMapping(value = "cardDetails", method = RequestMethod.GET)
public ResponseEntity<Map<String, Object>> cardDetails() {
Map<String, Object> response = new HashMap<String, Object>();
Map<String, Object> data = new HashMap<String, Object>();
try {
Map<String, Object> cardResponse = paypalVaultPaymentService.getCardDetails();
String json = cardResponse.get("Details").toString();
Map<String, Object> map = toMap(new JSONObject(json));
data.put("cardDetails", map);
response.put("data", data);
response.put("status", "OK");
response.put("code", "200");
response.put("message", "Card Details Found successfully.");
return new ResponseEntity<Map<String, Object>>(response, HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
response.put("status", "ERROR");
response.put("code", "500");
response.put("message", "Something went wrong");
return new ResponseEntity<Map<String, Object>>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
public static Map<String, Object> toMap(JSONObject object) throws JSONException {
Map<String, Object> map = new HashMap<String, Object>();
Iterator<String> keysItr = object.keys();
while (keysItr.hasNext()) {
String key = keysItr.next();
Object value = object.get(key);
if (value instanceof JSONArray) {
value = toList((JSONArray) value);
}
else if (value instanceof JSONObject) {
value = toMap((JSONObject) value);
}
map.put(key, value);
}
return map;
}
public static List<Object> toList(JSONArray array) throws JSONException {
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.length(); i++) {
Object value = array.get(i);
if (value instanceof JSONArray) {
value = toList((JSONArray) value);
}
else if (value instanceof JSONObject) {
value = toMap((JSONObject) value);
}
list.add(value);
}
return list;
}