Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

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

local json = chilkat.JsonObject.new()
json:update_int("amount", 45671)
json:update_string("externalId", "234567898654")
json:update_string("description", "Test transaction")
json:update_string("buyer.email", "jan.kowalski@melements.pl")

local myApiAccessKey = "c12c386b-650b-43db-9430-d84fc05d9433"
local mySigCalcKey = "b758f20d-ba92-44fa-acca-f57e99787b9d"

-- Calculate the Signature header.
local crypt = chilkat.Crypt2.new()
crypt.mac_algorithm = "hmac"
crypt.encoding_mode = "base64"
crypt:set_mac_key_string(mySigCalcKey)
crypt.hash_algorithm = "SHA-256"
local messageBody = json:emit()
local signature = crypt:mac_string_enc(messageBody)

http:set_request_header("Idempotency-Key", crypt:generate_uuid())
http:set_request_header("Api-Key", myApiAccessKey)
http:set_request_header("Signature", signature)
http:set_request_header("Content-Type", "application/json")
http.accept = "application/json"

local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://api.sandbox.paynow.pl/v1/payments", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

print("Response body:")
print(resp.body_str)

-- Sample response:
-- {
--   "redirectUrl": "https://paywall.sandbox.paynow.pl/NOA0-YJ9-Y1P-29V?token=eyJraWQiOiJhMD ... L60wk",
--   "paymentId": "NOA0-YJ9-Y1P-29V",
--   "status": "NEW"
-- }

local jsonResp = chilkat.JsonObject.new()
jsonResp:load(resp.body_str)
local redirectUrl = json:string_of("redirectUrl")
local paymentId = json:string_of("paymentId")
local status = json:string_of("status")