Rust Requires Chilkat v11.0.0+
Rust
PayPal: Suspend an active subscription
See more PayPal Examples
Pause future billing after checking that the subscription is active. Save the reason with the customer support record.
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();
let _ = http.set_url_var("id", "SUBSCRIPTION_ID");
if http.http_no_body("GET", "https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$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.string_of_equals("status", "ACTIVE", true) {
println!("Subscription status is {}. No change made.", result.string_of("status").unwrap_or_default());
return;
}
let body = chilkat::JsonObject::new();
let _ = body.update_string("reason", "Customer requested a billing pause.");
if http.http_json("POST", "https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}/suspend", &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 change_error = chilkat::JsonObject::new();
let _ = change_error.load(&resp.body_str());
println!("HTTP {} {} {}", resp.status_code(), change_error.string_of("name").unwrap_or_default(), change_error.string_of("details[0].issue").unwrap_or_default());
println!("PayPal debug ID: {}", change_error.string_of("debug_id").unwrap_or_default());
return;
}
println!("PayPal accepted the subscription change.");