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

PayPal: Update the price on a reusable payment link

See more PayPal Examples

Retrieve the simple USD inspection link from the create example. Check its item and currency, retain its configuration, and replace the price with USD 95. PUT sends the complete editable definition.

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", "PAYMENT_RESOURCE_ID");

if http.http_no_body("GET", "https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$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;
}

if (result.size_of_array("line_items") != 1) || ((!result.string_of_equals("line_items[0].name", "Annual inspection", true)) || (!result.string_of_equals("line_items[0].unit_amount.currency_code", "USD", true))) {
    println!("Select the USD inspection link from your catalog.");
    return;
}

// Preserve line items, taxes, shipping and checkout settings from the retrieved link.
// Remove the resource metadata PayPal added to the GET response.
if result.has_member("id") {
    let _ = result.delete("id");
}

if result.has_member("create_time") {
    let _ = result.delete("create_time");
}

if result.has_member("update_time") {
    let _ = result.delete("update_time");
}

if result.has_member("status") {
    let _ = result.delete("status");
}

if result.has_member("links") {
    let _ = result.delete("links");
}

if result.has_member("payment_link") {
    let _ = result.delete("payment_link");
}

let _ = result.update_string("line_items[0].unit_amount.value", "95.00");
if http.http_json("PUT", "https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}", &result, "application/json", &resp).is_err() {
    println!("No HTTP response: {}", http.last_error_text());
    return;
}

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

println!("The inspection price is now USD 95.00.");