Java Requires Chilkat v11.0.0+
Java
PayPal: Find successful Express Checkout transactions
See more PayPal Examples
Filter a reporting window by T0006 (Express Checkout) and S (success). The signed amount distinguishes money received from money sent. This is one transaction class, not all merchant sales; reporting access is required.
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();
// Use the UTC window containing the transaction (at most 31 days per request).
DateTime dt = new DateTime();
dt.setFromCurrentSystemTime();
JsonObject query = new JsonObject();
query.updateString("end_date", dt.getAsTimestamp(false));
dt.addDays(-1);
query.updateString("start_date", dt.getAsTimestamp(false));
query.updateString("fields", "transaction_info");
query.updateInt("page_size", 100);
query.updateString("transaction_type", "T0006");
query.updateString("transaction_status", "S");
int page = 1;
int lastPage = 1;
while (page <= lastPage) {
query.updateInt("page", page);
try {
http.httpParams("GET", "https://api-m.sandbox.paypal.com/v1/reporting/transactions", 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;
int count = result.sizeOfArray("transaction_details");
while (i < count) {
result.setI(i);
System.out.println(result.stringOf("transaction_details[i].transaction_info.transaction_id") + " " + result.stringOf("transaction_details[i].transaction_info.transaction_event_code") + " " + result.stringOf("transaction_details[i].transaction_info.transaction_status"));
System.out.println(" " + result.stringOf("transaction_details[i].transaction_info.transaction_amount.value") + " " + result.stringOf("transaction_details[i].transaction_info.transaction_amount.currency_code"));
i = i + 1;
}
lastPage = result.intOf("total_pages");
page = page + 1;
}
}
}