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

PayPal: Submit proof of fulfillment for a dispute

See more PayPal Examples

Inspect the actions and evidence requested for a selected dispute. When PayPal requests proof of fulfillment from the seller, attach the matching carrier receipt PDF with tracking details in a multipart request. Replace the file and tracking number with those for this case.

PayPal documentation

Chilkat Java Downloads

Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpRequest;
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();

        http.setUrlVar("id", "DISPUTE_ID");

        try {
            http.httpNoBody("GET", "https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}", 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;
        }

        boolean canSubmit = false;
        int linkIndex = 0;
        while (linkIndex < result.sizeOfArray("links")) {
            result.setI(linkIndex);
            if (result.stringOfEquals("links[i].rel", "provide_evidence", true)) {
                canSubmit = true;
            }

            linkIndex = linkIndex + 1;
        }

        boolean requested = false;
        int i = 0;
        while (i < result.sizeOfArray("evidences")) {
            result.setI(i);
            if ((result.stringOfEquals("evidences[i].evidence_type", "PROOF_OF_FULFILLMENT", true)) && (result.stringOfEquals("evidences[i].source", "REQUESTED_FROM_SELLER", true))) {
                requested = true;
            }

            i = i + 1;
        }

        if ((!canSubmit) || (!requested)) {
            System.out.println("PayPal is not requesting seller fulfillment evidence for this case.");
            return;
        }

        JsonObject body = new JsonObject();
        body.updateString("evidences[0].evidence_type", "PROOF_OF_FULFILLMENT");
        body.updateString("evidences[0].evidence_info.tracking_info[0].carrier_name", "FEDEX");
        body.updateString("evidences[0].evidence_info.tracking_info[0].tracking_number", "123456789012");
        body.updateString("evidences[0].notes", "The attached carrier receipt corresponds to this shipment.");
        HttpRequest upload = new HttpRequest();
        upload.setHttpVerb("POST");
        upload.setContentType("multipart/form-data");
        try {
            upload.addStringForUpload2("input", "", body.emit(), "utf-8", "application/json");

            upload.addFileForUpload2("file1", "carrier-receipt.pdf", "application/pdf");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        try {
            http.httpReq("https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence", upload, resp);
        } catch (ChilkatException e) {
            System.out.println("No HTTP response: " + e.getLastErrorText());
            return;
        }

        if ((resp.getStatusCode() < 200) || (resp.getStatusCode() >= 300)) {
            JsonObject submitError = new JsonObject();
            submitError.load(resp.getBodyStr());
            System.out.println("HTTP " + resp.getStatusCode() + " " + submitError.stringOf("name") + " " + submitError.stringOf("details[0].issue"));
            System.out.println("PayPal debug ID: " + submitError.stringOf("debug_id"));
            return;
        }

        System.out.println("PayPal accepted the evidence.");
    }
}