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

Stripe: Create a Stripe Customer for an Existing Billing Account

See more Stripe Examples

Create a Stripe Customer for a local billing account. Send its internal reference in metadata and read the customer ID to save with that account.

Stripe documentation and cURL example

Chilkat Rust Downloads

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

// For an account already linked to Stripe, reuse its saved customer ID.

let business_name = chilkat::StringBuilder::new();
let _ = business_name.set_string("Acme & Sons");

let email = chilkat::StringBuilder::new();
let _ = email.set_string("billing+east@example.com");

let account_ref = "ACME-1042".to_string();

// curl -X POST "https://api.stripe.com/v1/customers" \
//   -u "$STRIPE_API_KEY:" \
//   -H "Stripe-Version: 2026-10-28.endive" \
//   -H "Idempotency-Key: {operationId}-customer" \
//   -d "name={businessName}" \
//   -d "email={email}" \
//   -d "metadata[account_ref]={accountRef}"
let _ = cmd.set_string("curl -X POST \"https://api.stripe.com/v1/customers\"");
let _ = cmd.append(" -u \"@KEY@:\"");
let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
let _ = cmd.append(" -H \"Idempotency-Key: @OP@-customer\"");
let _ = cmd.append(" -d \"name=@NAME@\"");
let _ = cmd.append(" -d \"email=@EMAIL@\"");
let _ = cmd.append(" -d \"metadata[account_ref]=@REF@\"");
let _ = cmd.replace("@NAME@", &business_name.get_encoded("url_rfc3986", "utf-8").unwrap_or_default());
let _ = cmd.replace("@EMAIL@", &email.get_encoded("url_rfc3986", "utf-8").unwrap_or_default());
let _ = cmd.replace("@REF@", &account_ref);
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;
}

// Save this string on the existing billing account after a successful create.
let customer_id = json.string_of("id").unwrap_or_default();
println!("Stripe customer: {}", customer_id);