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

CardConnect Capture

See more CardConnect Examples

Demonstrates how to send a CardConnect Capture request.
The capture service queues the transaction amount for settlement. Capture can occur within the authorization request or subsequently. ...

See https://developer.cardconnect.com/cardconnect-api#capture

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

http.set_basic_auth(true);
http.set_login("API_USERNAME");
http.set_password("API_PASSWORD");

// Build and send the following JSON:

// The "retref" is the value returned in the JSON response for the Authorization request.

// {
//     "retref":"112989260941",
//     "merchid":"MERCHANT_ID"
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("retref", "112989260941");
let _ = json.update_string("merchid", "MERCHANT_ID");

let url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/capture".to_string();

let resp = chilkat::HttpResponse::new();
if http.http_str("PUT", &url, &json.emit().unwrap_or_default(), "utf-8", "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

// A response status of 200 indicates potential success.  The JSON response body
// must be examined to determine if it was truly successful or an error.
println!("response status code = {}", resp.status_code());

let json_resp = chilkat::JsonObject::new();
let _ = json_resp.load(&resp.body_str());
json_resp.set_emit_compact(false);

println!("response JSON:");
println!("{}", json_resp.emit().unwrap_or_default());

// A successful response looks like this:

// {
//   "amount": "0.20",
//   "resptext": "Approval",
//   "setlstat": "Queued for Capture",
//   "commcard": " C ",
//   "respcode": "00",
//   "batchid": "1900942291",
//   "merchid": "MERCHANT_ID",
//   "token": "9418594164541111",
//   "authcode": "PPS158",
//   "respproc": "FNOR",
//   "retref": "112989260941",
//   "respstat": "A",
//   "account": "9418594164541111"
// }

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

let amount = json_resp.string_of("amount").unwrap_or_default();
let resptext = json_resp.string_of("resptext").unwrap_or_default();
let setlstat = json_resp.string_of("setlstat").unwrap_or_default();
let commcard = json_resp.string_of("commcard").unwrap_or_default();
let respcode = json_resp.string_of("respcode").unwrap_or_default();
let batchid = json_resp.string_of("batchid").unwrap_or_default();
let merchid = json_resp.string_of("merchid").unwrap_or_default();
let token = json_resp.string_of("token").unwrap_or_default();
let authcode = json_resp.string_of("authcode").unwrap_or_default();
let respproc = json_resp.string_of("respproc").unwrap_or_default();
let retref = json_resp.string_of("retref").unwrap_or_default();
let respstat = json_resp.string_of("respstat").unwrap_or_default();
let account = json_resp.string_of("account").unwrap_or_default();