Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

CardConnect Validate Merchant-Level Credentials

See more CardConnect Examples

To test and validate merchant-level credentials, you can make a PUT request, including the merchant ID in the body of the request, to the base URL. The Gateway verifies that the MID matches the credentials provided in the header.

Chilkat Zig Downloads

Zig
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 json = try chilkat.JsonObject.init();
    defer json.deinit();
    try json.updateString("merchid", "MERCHANT_ID");

    const url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/";

    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;
    };

    // If we get a 200 response status and an HTML response saying "CardConnect REST Servlet", then our credentials are correct.
    std.debug.print("response status code = {d}\n", .{resp.getStatusCode()});

    std.debug.print("response string:\n", .{});
    std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});

    // Sample output:

    // response status code = 200
    // response string:
    // <html lang="en"><body><h1>CardConnect REST Servlet</h1></body></html>
}