44 lines
1.6 KiB
Java
44 lines
1.6 KiB
Java
package com.paypal;
|
|
|
|
import com.paypal.core.PayPalEnvironment;
|
|
import com.paypal.core.PayPalHttpClient;
|
|
import java.util.Iterator;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.json.JSONObject;
|
|
|
|
public class PayPalClient {
|
|
private PayPalEnvironment environment = new PayPalEnvironment.Sandbox(
|
|
(System.getProperty("PAYPAL_CLIENT_ID") != null) ? System.getProperty("PAYPAL_CLIENT_ID") :
|
|
"<<PAYPAL-CLIENT-ID>>",
|
|
(System.getProperty("PAYPAL_CLIENT_SECRET") != null) ? System.getProperty("PAYPAL_CLIENT_SECRET") :
|
|
"<<PAYPAL-CLIENT-SECRET>>");
|
|
|
|
PayPalHttpClient client = new PayPalHttpClient(this.environment);
|
|
|
|
public PayPalHttpClient client() {
|
|
return this.client;
|
|
}
|
|
|
|
public String prettyPrint(JSONObject jo, String pre) {
|
|
Iterator<?> keys = jo.keys();
|
|
StringBuilder pretty = new StringBuilder();
|
|
while (keys.hasNext()) {
|
|
String key = (String)keys.next();
|
|
pretty.append(String.format("%s%s: ", pre, StringUtils.capitalize(key)));
|
|
if (jo.get(key) instanceof JSONObject) {
|
|
pretty.append(prettyPrint(jo.getJSONObject(key), pre + "\t"));
|
|
continue;
|
|
}
|
|
if (jo.get(key) instanceof org.json.JSONArray) {
|
|
int sno = 1;
|
|
for (Object jsonObject : (Iterable<Object>)jo.getJSONArray(key)) {
|
|
pretty.append(String.format("\n%s\t%d:\n", pre, sno++));
|
|
pretty.append(prettyPrint((JSONObject)jsonObject, pre + "\t\t"));
|
|
}
|
|
continue;
|
|
}
|
|
pretty.append(String.format("%s\n", jo.getString(key)));
|
|
}
|
|
return pretty.toString();
|
|
}
|
|
}
|