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

PayPal: Add shipment tracking to a captured order

See more PayPal Examples

Use the order ID in the URL and the capture ID for this shipment in the body. Send the carrier and tracking number from your shipping record. Set notify_payer according to how your business sends shipping notices.

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();

// Replace both PayPal IDs and the sample tracking number with values from the same
// shipped order.
let _ = http.set_url_var("id", "ORDER_ID");
let body = chilkat::JsonObject::new();
let _ = body.update_string("capture_id", "CAPTUREID");
let _ = body.update_string("tracking_number", "1Z999AA10123456784");
let _ = body.update_string("carrier", "UPS");
let _ = body.update_bool("notify_payer", false);

if http.http_json("POST", "https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}/track", &body, "application/json", &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;
}

println!("PayPal accepted tracking for this order. HTTP {}", resp.status_code());