Zig
Zig
CardConnect Inquire
See more CardConnect Examples
Demonstrates how to get information for an individual transaction, including its settlement status (setlstat) and the response codes from the initial authorization.See https://developer.cardconnect.com/cardconnect-api?lang=json#inquire
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");
const url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/inquire/<retref>/<merchid>";
const response_str = http.quickGetStr(alloc, url) 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", .{http.getLastStatus()});
const json_resp = try chilkat.JsonObject.init();
defer json_resp.deinit();
json_resp.load(response_str) 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.00",
// "resptext": "Approval",
// "setlstat": "Voided",
// "capturedate": "20190422180044",
// "acctid": "1",
// "respcode": "00",
// "entrymode": "ECommerce",
// "merchid": "MERCHANT_ID",
// "token": "9418594164541111",
// "authcode": "PPS158",
// "respproc": "FNOR",
// "authdate": "20190422",
// "bintype": "",
// "profileid": "16618402968441604028",
// "lastfour": "1111",
// "name": "TOM JONES",
// "currency": "USD",
// "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, "capturedate");
_ = try json_resp.stringOf(alloc, "acctid");
_ = try json_resp.stringOf(alloc, "respcode");
_ = try json_resp.stringOf(alloc, "entrymode");
_ = 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, "authdate");
_ = try json_resp.stringOf(alloc, "bintype");
_ = try json_resp.stringOf(alloc, "profileid");
_ = try json_resp.stringOf(alloc, "lastfour");
_ = try json_resp.stringOf(alloc, "name");
_ = try json_resp.stringOf(alloc, "currency");
_ = try json_resp.stringOf(alloc, "retref");
_ = try json_resp.stringOf(alloc, "respstat");
_ = try json_resp.stringOf(alloc, "account");
}