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

Stripe: Identify the payment for a paid invoice

See more Stripe Examples

List the payments allocated to an invoice and identify a paid charge or PaymentIntent for refund.

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

let curl = chilkat::HttpCurl::new();
let cmd = chilkat::StringBuilder::new();
let json = chilkat::JsonObject::new();

let invoice_id = "in_FROM_BILLING_RECORD".to_string();

let page_suffix = chilkat::StringBuilder::new();
let mut more = true;
let mut cursor = String::new();
while more {
    // curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice={invoiceId}&limit=100" \
    //   -u "$STRIPE_API_KEY:" \
    //   -H "Stripe-Version: 2026-10-28.endive"
    let _ = cmd.set_string("curl -X GET \"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@\"");
    let _ = cmd.append(" -u \"@KEY@:\"");
    let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
    let _ = cmd.replace("@CURSOR@", &page_suffix.get_as_string().unwrap_or_default());
    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;
    }

    let mut i = 0;
    let count = json.size_of_array("data");
    while i < count {
        json.set_i(i);
        println!("{} | {} | {} | {} | {}", json.string_of("data[i].id").unwrap_or_default(), json.string_of("data[i].status").unwrap_or_default(), json.string_of("data[i].amount_paid").unwrap_or_default(), json.string_of("data[i].currency").unwrap_or_default(), json.string_of("data[i].payment.type").unwrap_or_default());
        if json.string_of("data[i].payment.type").unwrap_or_default() == "payment_intent" {
            println!("  PaymentIntent: {}", json.string_of("data[i].payment.payment_intent").unwrap_or_default());
        }

        if json.string_of("data[i].payment.type").unwrap_or_default() == "charge" {
            println!("  Charge: {}", json.string_of("data[i].payment.charge").unwrap_or_default());
        }

        i = i + 1;
    }

    more = json.bool_of("has_more");
    if more {
        let next = json.string_of("data[i].id").unwrap_or_default();
        if (count < 1) || ((next == "") || (next == cursor)) {
            println!("Invalid pagination cursor.");
            return;
        }

        cursor = next.clone();
        let _ = page_suffix.set_string("&starting_after=");
        let _ = page_suffix.append(&cursor);
    }

}

// Select the paid allocation belonging to the order before issuing its refund.