Sample code for 30+ languages & platforms
Rust 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 Rust Downloads

Rust

// 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.
let http = chilkat::Http::new();
http.set_auth_token("SANDBOX_ACCESS_TOKEN");
let resp = chilkat::HttpResponse::new();

let _ = http.set_url_var("id", "DISPUTE_ID");

if http.http_no_body("GET", "https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}", &resp).is_err() {
    println!("No HTTP response: {}", http.last_error_text());
    return;
}

if (resp.status_code() < 200) || (resp.status_code() >= 300) {
    let error_info = chilkat::JsonObject::new();
    let _ = error_info.load(&resp.body_str());
    println!("HTTP {} {} {}", resp.status_code(), error_info.string_of("name").unwrap_or_default(), error_info.string_of("details[0].issue").unwrap_or_default());
    println!("PayPal debug ID: {}", error_info.string_of("debug_id").unwrap_or_default());
    return;
}

let result = chilkat::JsonObject::new();
if result.load(&resp.body_str()).is_err() {
    println!("Expected a JSON response; HTTP {}", resp.status_code());
    return;
}

let mut can_submit = false;
let mut link_index = 0;
while link_index < result.size_of_array("links") {
    result.set_i(link_index);
    if result.string_of_equals("links[i].rel", "provide_evidence", true) {
        can_submit = true;
    }

    link_index = link_index + 1;
}

let mut requested = false;
let mut i = 0;
while i < result.size_of_array("evidences") {
    result.set_i(i);
    if (result.string_of_equals("evidences[i].evidence_type", "PROOF_OF_FULFILLMENT", true)) && (result.string_of_equals("evidences[i].source", "REQUESTED_FROM_SELLER", true)) {
        requested = true;
    }

    i = i + 1;
}

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

let body = chilkat::JsonObject::new();
let _ = body.update_string("evidences[0].evidence_type", "PROOF_OF_FULFILLMENT");
let _ = body.update_string("evidences[0].evidence_info.tracking_info[0].carrier_name", "FEDEX");
let _ = body.update_string("evidences[0].evidence_info.tracking_info[0].tracking_number", "123456789012");
let _ = body.update_string("evidences[0].notes", "The attached carrier receipt corresponds to this shipment.");
let upload = chilkat::HttpRequest::new();
upload.set_http_verb("POST");
upload.set_content_type("multipart/form-data");
if upload.add_string_for_upload2("input", "", &body.emit().unwrap_or_default(), "utf-8", "application/json").is_err() {
    println!("{}", upload.last_error_text());
    return;
}

if upload.add_file_for_upload2("file1", "carrier-receipt.pdf", "application/pdf").is_err() {
    println!("{}", upload.last_error_text());
    return;
}

if http.http_req("https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence", &upload, &resp).is_err() {
    println!("No HTTP response: {}", http.last_error_text());
    return;
}

if (resp.status_code() < 200) || (resp.status_code() >= 300) {
    let submit_error = chilkat::JsonObject::new();
    let _ = submit_error.load(&resp.body_str());
    println!("HTTP {} {} {}", resp.status_code(), submit_error.string_of("name").unwrap_or_default(), submit_error.string_of("details[0].issue").unwrap_or_default());
    println!("PayPal debug ID: {}", submit_error.string_of("debug_id").unwrap_or_default());
    return;
}

println!("PayPal accepted the evidence.");