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

Adyen Verify Payment Result

See more Adyen Examples

Once a payment has completed, this verifies the result from your server with a /payments/result request.

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();

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Use this online tool to generate the code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "payload": "2he28Ddhwj242he28Ddhwj..."
    // }
    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("payload", "2he28Ddhwj242he28Ddhwj...") catch {};

    http.setRequestHeader("X-API-Key", "Your_API_key");

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("POST", "https://checkout-test.adyen.com/v41/payments/result", json, "application/json", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    resp.getBodySb(sb_response_body) catch {};

    const j_resp = try chilkat.JsonObject.init();
    defer j_resp.deinit();
    j_resp.loadSb(sb_response_body) catch {};
    j_resp.setEmitCompact(false);

    const resp_status_code = resp.getStatusCode();
    std.debug.print("Status Code = {d}\n", .{resp_status_code});
    std.debug.print("Response Body:\n", .{});
    std.debug.print("{s}\n", .{try j_resp.emit(alloc)});

    if (resp_status_code >= 400) {
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

    // Sample JSON response:

    // {
    //   "pspReference": "851559480052382F",
    //   "resultCode": "Authorised",
    //   "merchantReference": "123",
    //   "paymentMethod": "ideal",
    //   "shopperLocale": "nl_NL"
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    _ = try j_resp.stringOf(alloc, "pspReference");
    _ = try j_resp.stringOf(alloc, "resultCode");
    _ = try j_resp.stringOf(alloc, "merchantReference");
    _ = try j_resp.stringOf(alloc, "paymentMethod");
    _ = try j_resp.stringOf(alloc, "shopperLocale");
}