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

Adyen Create Payment Session

See more Adyen Examples

Creates an Adyen payment session.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local http = chilkat.Http.new()

-- 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"
-- }
local json = chilkat.JsonObject.new()
json:update_string("merchantAccount", "YourMerchantAccount")
json:update_string("sdkVersion", "1.9.7")
json:update_string("channel", "Web")
json:update_string("amount.currency", "EUR")
json:update_int("amount.value", 17408)
json:update_string("reference", "Your order number")
json:update_string("countryCode", "NL")
json:update_string("shopperLocale", "nl_NL")
json:update_string("origin", "https://www.yourshop.com")
json:update_string("returnUrl", "https://www.yourshop.com/checkout/completed")

http:set_request_header("X-API-Key", "YourAPIkey")

local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://checkout-test.adyen.com/v41/paymentSession", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

local respStatusCode = resp.status_code
print("Status Code = " .. respStatusCode)
print("Response Body:")
print(jResp:emit())

if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
end

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

local paymentSession = jResp:string_of("paymentSession")