Java Requires Chilkat v11.0.0+
Java
PayPal: Find disputes awaiting a seller response
See more PayPal Examples
Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
// See Unlock Chilkat before making requests.
// For the merchant's internal backoffice application. Load the sandbox token
// from the merchant's credential store. Keep it out of publicly distributed apps.
// See Get a PayPal access token.
Http http = new Http();
http.setAuthToken("SANDBOX_ACCESS_TOKEN");
HttpResponse resp = new HttpResponse();
DateTime since = new DateTime();
since.setFromCurrentSystemTime();
since.addDays(-30);
JsonObject query = new JsonObject();
query.updateString("update_time_after", since.getAsTimestamp(false));
query.updateInt("page_size", 50);
int page = 1;
boolean more = true;
while (more) {
query.updateInt("page", page);
try {
http.httpParams("GET", "https://api-m.sandbox.paypal.com/v1/customer/disputes", query, resp);
} catch (ChilkatException e) {
System.out.println("No HTTP response: " + e.getLastErrorText());
return;
}
if ((resp.getStatusCode() < 200) || (resp.getStatusCode() >= 300)) {
JsonObject errorInfo = new JsonObject();
errorInfo.load(resp.getBodyStr());
System.out.println("HTTP " + resp.getStatusCode() + " " + errorInfo.stringOf("name") + " " + errorInfo.stringOf("details[0].issue"));
System.out.println("PayPal debug ID: " + errorInfo.stringOf("debug_id"));
return;
}
JsonObject result = new JsonObject();
try {
result.load(resp.getBodyStr());
} catch (ChilkatException e) {
System.out.println("Expected a JSON response; HTTP " + resp.getStatusCode());
return;
}
int i = 0;
while (i < result.sizeOfArray("items")) {
result.setI(i);
if (result.stringOfEquals("items[i].status", "WAITING_FOR_SELLER_RESPONSE", true)) {
System.out.println(result.stringOf("items[i].dispute_id") + " " + result.stringOf("items[i].reason"));
if (result.hasMember("items[i].seller_response_due_date")) {
System.out.println("Respond by " + result.stringOf("items[i].seller_response_due_date"));
}
}
i = i + 1;
}
boolean hasNext = false;
int linkIndex = 0;
while (linkIndex < result.sizeOfArray("links")) {
result.setI(linkIndex);
if (result.stringOfEquals("links[i].rel", "next", true)) {
hasNext = true;
}
linkIndex = linkIndex + 1;
}
more = hasNext;
page = page + 1;
}
}
}