Zig
Zig
Paynow.pl -- Make a Payment Request
See more Paynow.pl Examples
Make a payment request POST with prepared message on Paynow payment request endpoint.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();
// Implements the following CURL command:
// curl --request POST 'https://api.sandbox.paynow.pl/v1/payments' \
// -H 'Content-Type: application/json' \
// -H 'Api-Key: c12c386b-650b-43db-9430-d84fc05d9433' \
// -H 'Signature: aYPCytCoc+/wFgqHZJjgBCi20omXTn0yzm9LysJgnFo=' \
// -H 'Idempotency-Key: 59c6dd26-f905-487b-96c9-fd1d2bd76885' \
// --data-raw '{
// "amount": 45671,
// "externalId": "234567898654",
// "description": "Test transaction",
// "buyer": {
// "email": "jan.kowalski@melements.pl"
// }
// }'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "amount": 45671,
// "externalId": "234567898654",
// "description": "Test transaction",
// "buyer": {
// "email": "jan.kowalski@melements.pl"
// }
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateInt("amount", 45671) catch {};
json.updateString("externalId", "234567898654") catch {};
json.updateString("description", "Test transaction") catch {};
json.updateString("buyer.email", "jan.kowalski@melements.pl") catch {};
const my_api_access_key = "c12c386b-650b-43db-9430-d84fc05d9433";
const my_sig_calc_key = "b758f20d-ba92-44fa-acca-f57e99787b9d";
// Calculate the Signature header.
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
crypt.setMacAlgorithm("hmac");
crypt.setEncodingMode("base64");
crypt.setMacKeyString(my_sig_calc_key) catch {};
crypt.setHashAlgorithm("SHA-256");
const message_body = try json.emit(alloc);
const signature = try crypt.macStringENC(alloc, message_body);
http.setRequestHeader("Idempotency-Key", try crypt.generateUuid(alloc));
http.setRequestHeader("Api-Key", my_api_access_key);
http.setRequestHeader("Signature", signature);
http.setRequestHeader("Content-Type", "application/json");
http.setAccept("application/json");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://api.sandbox.paynow.pl/v1/payments", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response body:\n", .{});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
// Sample response:
// {
// "redirectUrl": "https://paywall.sandbox.paynow.pl/NOA0-YJ9-Y1P-29V?token=eyJraWQiOiJhMD ... L60wk",
// "paymentId": "NOA0-YJ9-Y1P-29V",
// "status": "NEW"
// }
const json_resp = try chilkat.JsonObject.init();
defer json_resp.deinit();
json_resp.load(try resp.getBodyStr(alloc)) catch {};
_ = try json.stringOf(alloc, "redirectUrl");
_ = try json.stringOf(alloc, "paymentId");
_ = try json.stringOf(alloc, "status");
}