Zig Requires Chilkat v11.0.0+
Zig
Adyen Create Payment Session
See more Adyen Examples
Creates an Adyen payment session.Chilkat Zig Downloads
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, and is constructed by the code that follows.
// {
// "merchantAccount": "YourMerchantAccount",
// "sdkVersion": "1.9.7",
// "channel": "Web",
// "amount": {
// "currency": "EUR",
// "value": 17408
// },
// "reference": "Your order number",
// "countryCode": "NL",
// "shopperLocale": "nl_NL",
// "origin": "https://www.yourshop.com",
// "returnUrl": "https://www.yourshop.com/checkout/completed"
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("merchantAccount", "YourMerchantAccount") catch {};
json.updateString("sdkVersion", "1.9.7") catch {};
json.updateString("channel", "Web") catch {};
json.updateString("amount.currency", "EUR") catch {};
json.updateInt("amount.value", 17408) catch {};
json.updateString("reference", "Your order number") catch {};
json.updateString("countryCode", "NL") catch {};
json.updateString("shopperLocale", "nl_NL") catch {};
json.updateString("origin", "https://www.yourshop.com") catch {};
json.updateString("returnUrl", "https://www.yourshop.com/checkout/completed") catch {};
http.setRequestHeader("X-API-Key", "YourAPIkey");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://checkout-test.adyen.com/v41/paymentSession", 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:
// {
// "paymentSession": "eyJjaGVja291 ... iMS45LjcifQ=="
// }
// 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, "paymentSession");
}