Rust Requires Chilkat v11.0.0+
Rust
PayPal: Void an unused authorization
See more PayPal Examples
Release an unused hold with the authorization ID. A fully captured authorization cannot be voided; refund its capture instead. A successful void can have an empty response body.
Chilkat Rust Downloads
// 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();
// Use the original authorization ID to release the hold; do not send an amount.
let _ = http.set_url_var("id", "AUTHORIZATION_ID");
// Create and persist this key once per business operation. On a timeout,
// retry the same request with its saved key, not a newly generated one.
let crypt = chilkat::Crypt2::new();
let request_id = crypt.generate_uuid().unwrap_or_default();
http.set_request_header("PayPal-Request-Id", &request_id);
if http.http_no_body("POST", "https://api-m.sandbox.paypal.com/v2/payments/authorizations/{$id}/void", &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!("Authorization void accepted; HTTP {}", resp.status_code());