Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

PayPal: Reconcile a transaction ID in a reporting window

See more PayPal Examples

Supply the reporting transaction ID and a window containing the activity. Return all matches: transaction IDs are not necessarily unique in the report. Include non-balance-affecting records when reconciling an event.

PayPal documentation

Chilkat Java Downloads

Java
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_id", "REPORT_TRANSACTION_ID");
        query.updateString("balance_affecting_records_only", "N");
        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;
        }
    }
}