Zig Requires Chilkat v11.0.0+
Zig
CardConnect Authorization
See more CardConnect Examples
Demonstrates how to send an Authorization request.Authorization is the initial step in accepting payment from a cardholder. This action "authorizes" or requests permission from the bank to transfer money from the cardholder to the merchant.
See https://developer.cardconnect.com/cardconnect-api#authorization
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:
// Note: The CardConnect online documentation might use an expiry that is in the past, such as "1218".
// This causes the request to fail. Use a month/year that is in the future..
// (Likewise, this example will have an invalid month/year after Dec 2021)
// {
// "merchid": "MERCHANT_ID",
// "accttype": "VISA",
// "orderid": "AB-11-9876",
// "account": "4111111111111111",
// "expiry": "1221",
// "amount": "0",
// "currency": "USD",
// "name": "TOM JONES",
// "address": "123 MAIN STREET",
// "city": "anytown",
// "region": "NY",
// "country": "US",
// "postal": "55555",
// "profile": "Y",
// "ecomind": "E",
// "cvv2": "123",
// "track": null,
// "capture": "Y"
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("merchid", "MERCHANT_ID") catch {};
json.updateString("accttype", "VISA") catch {};
json.updateString("orderid", "AB-11-9876") catch {};
json.updateString("account", "4111111111111111") catch {};
json.updateString("expiry", "1221") catch {};
json.updateString("amount", "20") catch {};
json.updateString("currency", "USD") catch {};
json.updateString("name", "TOM JONES") catch {};
json.updateString("address", "123 MAIN STREET") catch {};
json.updateString("city", "anytown") catch {};
json.updateString("region", "NY") catch {};
json.updateString("country", "US") catch {};
json.updateString("postal", "55555") catch {};
json.updateString("profile", "Y") catch {};
json.updateString("ecomind", "E") catch {};
json.updateString("cvv2", "123") catch {};
json.updateNull("track") catch {};
json.updateString("capture", "Y") catch {};
const url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/auth";
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)});
// Sample error:
// {
// "respproc": "PPS",
// "amount": "0.00",
// "resptext": "Invalid amount",
// "cardproc": "FNOR",
// "acctid": "1",
// "retref": "112804260418",
// "respstat": "C",
// "respcode": "43",
// "account": "41XXXXXXXXXX1111",
// "defaultacct": "Y",
// "merchid": "MERCHANT_ID",
// "token": "9418594164541111"
// }
// A successful response looks like this:
// {
// "amount": "0.20",
// "resptext": "Approval",
// "acctid": "1",
// "commcard": " C ",
// "cvvresp": "M",
// "respcode": "00",
// "batchid": "1900942291",
// "avsresp": "Z",
// "entrymode": "ECommerce",
// "defaultacct": "Y",
// "merchid": "MERCHANT_ID",
// "token": "9418594164541111",
// "authcode": "PPS158",
// "respproc": "FNOR",
// "bintype": "",
// "profileid": "16618402968441604028",
// "retref": "112989260941",
// "respstat": "A",
// "account": "41XXXXXXXXXX1111"
// }
// 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, "acctid");
_ = try json_resp.stringOf(alloc, "commcard");
_ = try json_resp.stringOf(alloc, "cvvresp");
_ = try json_resp.stringOf(alloc, "respcode");
_ = try json_resp.stringOf(alloc, "batchid");
_ = try json_resp.stringOf(alloc, "avsresp");
_ = try json_resp.stringOf(alloc, "entrymode");
_ = try json_resp.stringOf(alloc, "defaultacct");
_ = 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, "bintype");
_ = try json_resp.stringOf(alloc, "profileid");
_ = try json_resp.stringOf(alloc, "retref");
_ = try json_resp.stringOf(alloc, "respstat");
_ = try json_resp.stringOf(alloc, "account");
}