Rust Requires Chilkat v11.7.0+
Rust
Stripe: Finalize and email a reviewed invoice
See more Stripe Examples
Finalize a reviewed draft and send the open invoice by email. Stripe test mode returns the API result without delivering an email.
Stripe documentation and cURL example
Chilkat Rust Downloads
let mut success = false;
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
let api_key = "YOUR_STRIPE_TEST_KEY".to_string();
// Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
let operation_id = "YOUR_SAVED_OPERATION_UUID".to_string();
let curl = chilkat::HttpCurl::new();
let cmd = chilkat::StringBuilder::new();
let json = chilkat::JsonObject::new();
let invoice_id = "in_FROM_BILLING_RECORD".to_string();
// curl -X GET "https://api.stripe.com/v1/invoices/{invoiceId}" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive"
let _ = cmd.set_string("curl -X GET \"https://api.stripe.com/v1/invoices/@ID@\"");
let _ = cmd.append(" -u \"@KEY@:\"");
let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
let _ = cmd.replace("@ID@", &invoice_id);
let _ = cmd.replace("@KEY@", &api_key);
success = curl.do_your_thing(&cmd.get_as_string().unwrap_or_default()).is_ok();
if !success {
println!("No HTTP response. Chilkat failure code: {}", curl.fail_reason());
return;
}
success = curl.get_response_json(&json).is_ok();
if (curl.status_code() != 200) || (!success) {
println!("Stripe HTTP {} Request-Id: {}", curl.status_code(), curl.get_response_header_field("Request-Id").unwrap_or_default());
if success {
println!("{}", json.string_of("error.message").unwrap_or_default());
}
return;
}
if json.string_of("collection_method").unwrap_or_default() != "send_invoice" {
println!("Select an invoice intended for email collection.");
return;
}
if json.string_of("status").unwrap_or_default() == "draft" {
// curl -X POST "https://api.stripe.com/v1/invoices/{invoiceId}/finalize" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -H "Idempotency-Key: {operationId}-finalize" \
// -d "auto_advance=false"
let _ = cmd.set_string("curl -X POST \"https://api.stripe.com/v1/invoices/@ID@/finalize\"");
let _ = cmd.append(" -u \"@KEY@:\"");
let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
let _ = cmd.append(" -H \"Idempotency-Key: @OP@-finalize\"");
let _ = cmd.append(" -d \"auto_advance=false\"");
let _ = cmd.replace("@ID@", &invoice_id);
let _ = cmd.replace("@OP@", &operation_id);
let _ = cmd.replace("@KEY@", &api_key);
success = curl.do_your_thing(&cmd.get_as_string().unwrap_or_default()).is_ok();
if !success {
println!("No HTTP response. Chilkat failure code: {}", curl.fail_reason());
return;
}
success = curl.get_response_json(&json).is_ok();
if (curl.status_code() != 200) || (!success) {
println!("Stripe HTTP {} Request-Id: {}", curl.status_code(), curl.get_response_header_field("Request-Id").unwrap_or_default());
if success {
println!("{}", json.string_of("error.message").unwrap_or_default());
}
return;
}
}
if json.string_of("status").unwrap_or_default() != "open" {
println!("Invoice is not open for collection: {}", json.string_of("status").unwrap_or_default());
return;
}
// Retry a send using the same saved operation UUID. Test mode sends no email.
// curl -X POST "https://api.stripe.com/v1/invoices/{invoiceId}/send" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -H "Idempotency-Key: {operationId}-send"
let _ = cmd.set_string("curl -X POST \"https://api.stripe.com/v1/invoices/@ID@/send\"");
let _ = cmd.append(" -u \"@KEY@:\"");
let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
let _ = cmd.append(" -H \"Idempotency-Key: @OP@-send\"");
let _ = cmd.replace("@ID@", &invoice_id);
let _ = cmd.replace("@OP@", &operation_id);
let _ = cmd.replace("@KEY@", &api_key);
success = curl.do_your_thing(&cmd.get_as_string().unwrap_or_default()).is_ok();
if !success {
println!("No HTTP response. Chilkat failure code: {}", curl.fail_reason());
return;
}
success = curl.get_response_json(&json).is_ok();
if (curl.status_code() != 200) || (!success) {
println!("Stripe HTTP {} Request-Id: {}", curl.status_code(), curl.get_response_header_field("Request-Id").unwrap_or_default());
if success {
println!("{}", json.string_of("error.message").unwrap_or_default());
}
return;
}
println!("number = {}", json.string_of("number").unwrap_or_default());
println!("status = {}", json.string_of("status").unwrap_or_default());
println!("hosted_invoice_url = {}", json.string_of("hosted_invoice_url").unwrap_or_default());