Zig Requires Chilkat v11.0.0+
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
http.setBasicAuth(true);
http.setLogin("API_USERNAME");
http.setPassword("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"
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("retref", "112989260941") catch {};
json.updateString("merchid", "MERCHANT_ID") catch {};
const url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/capture";
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpStr("PUT", url, try json.emit(alloc), "utf-8", "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
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.
std.debug.print("response status code = {d}\n", .{resp.getStatusCode()});
const json_resp = try chilkat.JsonObject.init();
defer json_resp.deinit();
json_resp.load(try resp.getBodyStr(alloc)) catch {};
json_resp.setEmitCompact(false);
std.debug.print("response JSON:\n", .{});
std.debug.print("{s}\n", .{try json_resp.emit(alloc)});
// 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
_ = try json_resp.stringOf(alloc, "amount");
_ = try json_resp.stringOf(alloc, "resptext");
_ = try json_resp.stringOf(alloc, "setlstat");
_ = try json_resp.stringOf(alloc, "commcard");
_ = try json_resp.stringOf(alloc, "respcode");
_ = try json_resp.stringOf(alloc, "batchid");
_ = try json_resp.stringOf(alloc, "merchid");
_ = try json_resp.stringOf(alloc, "token");
_ = try json_resp.stringOf(alloc, "authcode");
_ = try json_resp.stringOf(alloc, "respproc");
_ = try json_resp.stringOf(alloc, "retref");
_ = try json_resp.stringOf(alloc, "respstat");
_ = try json_resp.stringOf(alloc, "account");
}