Zig Requires Chilkat v11.0.0+
Zig
CardConnect Create Profile
See more CardConnect Examples
Demonstrates how to create a profile.A PUT call to the profile endpoint creates a new profile or adds a new account to an existing profile. ...
See https://developer.cardconnect.com/cardconnect-api?lang=json#create-update-profile-request
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:
// {
// "region": "AK",
// "phone": "7778789999",
// "accttype": "VISA",
// "postal": "19090",
// "ssnl4": "3655",
// "expiry": "0214",
// "city": "ANYTOWN",
// "country": "US",
// "address": "123 MAIN STREET",
// "merchid": "496400000840",
// "name": "TOM JONES",
// "account": "4444333322221111",
// "license": "123451254",
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("region", "AK") catch {};
json.updateString("phone", "7778789999") catch {};
json.updateString("accttype", "VISA") catch {};
json.updateString("postal", "19090") catch {};
json.updateString("ssnl4", "3655") catch {};
json.updateString("expiry", "0214") catch {};
json.updateString("city", "ANYTOWN") catch {};
json.updateString("country", "US") catch {};
json.updateString("address", "123 MAIN STREET") catch {};
json.updateString("merchid", "MERCHANT_ID") catch {};
json.updateString("name", "TOM JONES") catch {};
json.updateString("account", "4444333322221111") catch {};
json.updateString("license", "123451254") catch {};
const url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/profile";
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:
// {
// "country": "US",
// "address": "123 MAIN STREET",
// "resptext": "Profile Saved",
// "city": "ANYTOWN",
// "acctid": "1",
// "respcode": "09",
// "defaultacct": "Y",
// "accttype": "VISA",
// "token": "9441149619831111",
// "license": "123451254",
// "respproc": "PPS",
// "phone": "7778789999",
// "profileid": "16392957457306633141",
// "name": "TOM JONES",
// "auoptout": "N",
// "postal": "19090",
// "expiry": "0214",
// "region": "AK",
// "ssnl4": "3655",
// "respstat": "A"
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
_ = try json_resp.stringOf(alloc, "country");
_ = try json_resp.stringOf(alloc, "address");
_ = try json_resp.stringOf(alloc, "resptext");
_ = try json_resp.stringOf(alloc, "city");
_ = try json_resp.stringOf(alloc, "acctid");
_ = try json_resp.stringOf(alloc, "respcode");
_ = try json_resp.stringOf(alloc, "defaultacct");
_ = try json_resp.stringOf(alloc, "accttype");
_ = try json_resp.stringOf(alloc, "token");
_ = try json_resp.stringOf(alloc, "license");
_ = try json_resp.stringOf(alloc, "respproc");
_ = try json_resp.stringOf(alloc, "phone");
_ = try json_resp.stringOf(alloc, "profileid");
_ = try json_resp.stringOf(alloc, "name");
_ = try json_resp.stringOf(alloc, "auoptout");
_ = try json_resp.stringOf(alloc, "postal");
_ = try json_resp.stringOf(alloc, "expiry");
_ = try json_resp.stringOf(alloc, "region");
_ = try json_resp.stringOf(alloc, "ssnl4");
_ = try json_resp.stringOf(alloc, "respstat");
}