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

Ibanity XS2A List Financial Institutions

See more Ibanity Examples

Demonstrates how to send a request to get a list of financial institutions.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

--  Send the following request:

-- $ curl -X GET https://api.ibanity.com/xs2a/financial-institutions \
-- --cert certificate.pem \
-- --key private_key.pem \
-- -H 'Signature: keyId="75b5d796-de5c-400a-81ce-e72371b01cbc",created=1599659223,algorithm="hs2019",headers="(request-target) digest (created) host",signature="BASE64(RSA-SHA256(SIGNING_STRING))"' \
-- -H 'Digest: SHA-512=beDaRguyEb8fhh5wnl37bOTDtvhuYZyZNkTZ9LiC9Wc='

-- Ibanity provides the certificate + private key in PFX format.  This example will use the .pfx instead of the pair of PEM files.
-- (It is also possible to implement using Chilkat with the PEM files, but PFX is easier.)
local cert = chilkat.Cert.new()
local success = cert:load_pfx_file("qa_data/pfx/my_ibanity_certificate.pfx", "my_pfx_password")
if not success then
    print(cert.last_error_text)
    return
end

-- We need to calculate the Digest and Signature header fields.
-- For a detailed explanation, see Calculate Ibanity HTTP Signature Example

-- We'll just write the code here as briefly as possible.

local dtNow = chilkat.DateTime.new()
dtNow:set_from_current_system_time()
local created = dtNow:get_as_unix_time_str(false)

local crypt2 = chilkat.Crypt2.new()
crypt2.hash_algorithm = "sha512"
crypt2.encoding_mode = "base64"

local sbDigestHdrValue = chilkat.StringBuilder.new()
sbDigestHdrValue:append("SHA-512=")
-- GET requests have empty payloads.  The SHA-512 hash of the empty string is the same for all GET requests.
-- Therefore all GET requests will use "z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=="
-- You can eliminate the explicit hash computation (for GET requests) and simply use the above literal string.
sbDigestHdrValue:append(crypt2:hash_string_enc(""))

print("Generated Digest")
print(sbDigestHdrValue:get_as_string())

local request_target = "get /xs2a/financial-institutions"

local sbSigningString = chilkat.StringBuilder.new()
sbSigningString:append("(request-target): ")
sbSigningString:append_line(request_target, false)
sbSigningString:append("host: ")
sbSigningString:append_line("api.ibanity.com", false)
sbSigningString:append("digest: ")
sbSigningString:append_line(sbDigestHdrValue:get_as_string(), false)
sbSigningString:append("(created): ")
sbSigningString:append(created)
-- ibanity-idempotency-key is not used with GET requests.

print("Signing String:")
print(sbSigningString:get_as_string())

local signed_headers_list = "(request-target) host digest (created)"

local privKey = chilkat.PrivateKey.new()
success = privKey:load_encrypted_pem_file("my_ibanity_signature_private_key.pem", "pem_password")
if not success then
    print(privKey.last_error_text)
    return
end

local rsa = chilkat.Rsa.new()
rsa.pss_salt_len = 32
rsa.encoding_mode = "base64"
-- Use the RSASSA-PSS signature algorithm
rsa.pkcs_padding = false

success = rsa:use_private_key(privKey)
if not success then
    print(rsa.last_error_text)
    return
end

-- Sign the signing string.
local sigBase64 = rsa:sign_string_enc(sbSigningString:get_as_string(), "sha-256")
if not rsa.last_method_success then
    print(rsa.last_error_text)
    return
end

print("Signature:")
print(sigBase64)

-- Build the signature header value.
local sbSigHeaderValue = chilkat.StringBuilder.new()
sbSigHeaderValue:append("keyId=\"")
-- Use your identifier for the application's signature certificate, obtained from the Developer Portal
sbSigHeaderValue:append("a0ce296d-84c8-4bd5-8eb4-de0339950cfa")
sbSigHeaderValue:append("\",created=")
sbSigHeaderValue:append(created)
sbSigHeaderValue:append(",algorithm=\"hs2019\",headers=\"")
sbSigHeaderValue:append(signed_headers_list)
sbSigHeaderValue:append("\",signature=\"")
sbSigHeaderValue:append(sigBase64)
sbSigHeaderValue:append("\"")

-- Send the GET request..
local http = chilkat.Http.new()

success = http:set_ssl_client_cert(cert)
if not success then
    print(http.last_error_text)
    return
end

http:set_request_header("Signature", sbSigHeaderValue:get_as_string())
http:set_request_header("Digest", sbDigestHdrValue:get_as_string())

local sbResponseBody = chilkat.StringBuilder.new()
success = http:quick_get_sb("https://api.ibanity.com/xs2a/financial-institutions", sbResponseBody)
if not success then
    print(http.last_error_text)
    return
end

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

print("Response Body:")
print(jResp:emit())

local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(http.last_header)
    print("Failed.")
    return
end

-- Sample output:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "data": [
--     {
--       "attributes": {
--         "authorizationModels": [
--           "detailed",
--           "financialInstitutionOffered"
--         ],
--         "bic": "NBBEBEBB203",
--         "bulkPaymentsEnabled": true,
--         "bulkPaymentsProductTypes": [
--           "sepaCreditTransfer"
--         ],
--         "country": null,
--         "financialInstitutionCustomerReferenceRequired": false,
--         "futureDatedPaymentsAllowed": true,
--         "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png",
--         "maintenanceFrom": null,
--         "maintenanceTo": null,
--         "maintenanceType": null,
--         "maxRequestedAccountReferences": null,
--         "minRequestedAccountReferences": 0,
--         "name": "Bogus Financial",
--         "paymentsEnabled": true,
--         "paymentsProductTypes": [
--           "sepaCreditTransfer"
--         ],
--         "periodicPaymentsEnabled": true,
--         "periodicPaymentsProductTypes": [
--           "sepaCreditTransfer"
--         ],
--         "primaryColor": "#7d39ff",
--         "requiresCredentialStorage": false,
--         "requiresCustomerIpAddress": false,
--         "sandbox": true,
--         "secondaryColor": "#3DF2C2",
--         "sharedBrandName": null,
--         "sharedBrandReference": null,
--         "status": "beta"
--       },
--       "id": "2d3d70a4-cb3c-477c-97e1-cbe495b82841",
--       "links": {
--         "self": "https://api.ibanity.com/xs2a/financial-institutions/2d3d70a4-cb3c-477c-97e1-cbe495b82841"
--       },
--       "type": "financialInstitution"
--     },
--     {
--       "attributes": {
--         "authorizationModels": [
--           "detailed",
--           "financialInstitutionOffered"
--         ],
--         "bic": "NBBEBEBB203",
--         "bulkPaymentsEnabled": true,
--         "bulkPaymentsProductTypes": [
--           "sepaCreditTransfer"
--         ],
--         "country": null,
--         "financialInstitutionCustomerReferenceRequired": false,
--         "futureDatedPaymentsAllowed": true,
--         "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png",
--         "maintenanceFrom": null,
--         "maintenanceTo": null,
--         "maintenanceType": null,
--         "maxRequestedAccountReferences": null,
--         "minRequestedAccountReferences": 0,
--         "name": "XYZ Trust",
--         "paymentsEnabled": true,
--         "paymentsProductTypes": [
--           "sepaCreditTransfer"
--         ],
--         "periodicPaymentsEnabled": true,
--         "periodicPaymentsProductTypes": [
--           "sepaCreditTransfer"
--         ],
--         "primaryColor": "#7d39ff",
--         "requiresCredentialStorage": false,
--         "requiresCustomerIpAddress": false,
--         "sandbox": true,
--         "secondaryColor": "#3DF2C2",
--         "sharedBrandName": null,
--         "sharedBrandReference": null,
--         "status": "beta"
--       },
--       "id": "d4100f28-936b-4379-a3f8-86314a2014fb",
--       "links": {
--         "self": "https://api.ibanity.com/xs2a/financial-institutions/d4100f28-936b-4379-a3f8-86314a2014fb"
--       },
--       "type": "financialInstitution"
--     }
--   ],
--   "links": {
--     "first": "https://api.ibanity.com/xs2a/financial-institutions"
--   },
--   "meta": {
--     "paging": {
--       "limit": 10
--     }
--   }
-- }

-- 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 attributesBic = ""
local attributesBulkPaymentsEnabled = false
local attributesCountry = ""
local attributesFinancialInstitutionCustomerReferenceRequired = false
local attributesFutureDatedPaymentsAllowed = false
local attributesLogoUrl = ""
local attributesMaintenanceFrom = ""
local attributesMaintenanceTo = ""
local attributesMaintenanceType = ""
local attributesMaxRequestedAccountReferences = ""
local attributesMinRequestedAccountReferences = 0
local attributesName = ""
local attributesPaymentsEnabled = false
local attributesPeriodicPaymentsEnabled = false
local attributesPrimaryColor = ""
local attributesRequiresCredentialStorage = false
local attributesRequiresCustomerIpAddress = false
local attributesSandbox = false
local attributesSecondaryColor = ""
local attributesSharedBrandName = ""
local attributesSharedBrandReference = ""
local attributesStatus = ""
local id = ""
local linksSelf = ""
local v_type = ""
local j = 0
local count_j = 0
local strVal = ""

local linksFirst = jResp:string_of("links.first")
local metaPagingLimit = jResp:int_of("meta.paging.limit")
local i = 0
local count_i = jResp:size_of_array("data")
while i < count_i do
    jResp.i = i
    attributesBic = jResp:string_of("data[i].attributes.bic")
    attributesBulkPaymentsEnabled = jResp:bool_of("data[i].attributes.bulkPaymentsEnabled")
    attributesCountry = jResp:string_of("data[i].attributes.country")
    attributesFinancialInstitutionCustomerReferenceRequired = jResp:bool_of("data[i].attributes.financialInstitutionCustomerReferenceRequired")
    attributesFutureDatedPaymentsAllowed = jResp:bool_of("data[i].attributes.futureDatedPaymentsAllowed")
    attributesLogoUrl = jResp:string_of("data[i].attributes.logoUrl")
    attributesMaintenanceFrom = jResp:string_of("data[i].attributes.maintenanceFrom")
    attributesMaintenanceTo = jResp:string_of("data[i].attributes.maintenanceTo")
    attributesMaintenanceType = jResp:string_of("data[i].attributes.maintenanceType")
    attributesMaxRequestedAccountReferences = jResp:string_of("data[i].attributes.maxRequestedAccountReferences")
    attributesMinRequestedAccountReferences = jResp:int_of("data[i].attributes.minRequestedAccountReferences")
    attributesName = jResp:string_of("data[i].attributes.name")
    attributesPaymentsEnabled = jResp:bool_of("data[i].attributes.paymentsEnabled")
    attributesPeriodicPaymentsEnabled = jResp:bool_of("data[i].attributes.periodicPaymentsEnabled")
    attributesPrimaryColor = jResp:string_of("data[i].attributes.primaryColor")
    attributesRequiresCredentialStorage = jResp:bool_of("data[i].attributes.requiresCredentialStorage")
    attributesRequiresCustomerIpAddress = jResp:bool_of("data[i].attributes.requiresCustomerIpAddress")
    attributesSandbox = jResp:bool_of("data[i].attributes.sandbox")
    attributesSecondaryColor = jResp:string_of("data[i].attributes.secondaryColor")
    attributesSharedBrandName = jResp:string_of("data[i].attributes.sharedBrandName")
    attributesSharedBrandReference = jResp:string_of("data[i].attributes.sharedBrandReference")
    attributesStatus = jResp:string_of("data[i].attributes.status")
    id = jResp:string_of("data[i].id")
    linksSelf = jResp:string_of("data[i].links.self")
    v_type = jResp:string_of("data[i].type")
    j = 0
    count_j = jResp:size_of_array("data[i].attributes.authorizationModels")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("data[i].attributes.authorizationModels[j]")
        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("data[i].attributes.bulkPaymentsProductTypes")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("data[i].attributes.bulkPaymentsProductTypes[j]")
        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("data[i].attributes.paymentsProductTypes")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("data[i].attributes.paymentsProductTypes[j]")
        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("data[i].attributes.periodicPaymentsProductTypes")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("data[i].attributes.periodicPaymentsProductTypes[j]")
        j = j + 1
    end

    i = i + 1
end