Rust Requires Chilkat v11.0.0+
Rust
CardConnect Signature Capture
See more CardConnect Examples
Demonstrates how to upload a BMP image of a handwritten signature.This signature capture service augments an existing authorization record with the provided signature data. ...
See https://developer.cardconnect.com/cardconnect-api?lang=json#signature-capture
Chilkat Rust Downloads
// 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:
// {
// "merchid": "MERCHANT_ID",
// "retref": "112989260941",
// "signature": "BASE64_GZIPPED_BMP_DATA"
// }
let json = chilkat::JsonObject::new();
let _ = json.update_string("merchid", "MERCHANT_ID");
let _ = json.update_string("retref", "106631225001");
// Load the .bmp containing a 200px x 100px signature.
let bd = chilkat::BinData::new();
let _ = bd.load_file("qa_data/bmp/signature.bmp").is_ok();
// Gzip compress.
let gzip = chilkat::Gzip::new();
let _ = gzip.compress_bd(&bd).is_ok();
// Add to the JSON in base64 format
let _ = json.update_string("signature", &bd.get_encoded("base64").unwrap_or_default());
let url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/sigcap".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:
// {
// "resptext": "signature stored",
// "retref": "106631225001",
// "respcode": "02",
// "merchid": "MERCHANT_ID"
// }