Sample code for 30+ languages & platforms
Visual FoxPro

Ibanity XS2A List Financial Institutions

See more Ibanity Examples

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

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loCert
LOCAL loDtNow
LOCAL lcCreated
LOCAL loCrypt2
LOCAL loSbDigestHdrValue
LOCAL lcRequest_target
LOCAL loSbSigningString
LOCAL lcSigned_headers_list
LOCAL loPrivKey
LOCAL loRsa
LOCAL lcSigBase64
LOCAL loSbSigHeaderValue
LOCAL loHttp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcAttributesBic
LOCAL lnAttributesBulkPaymentsEnabled
LOCAL lcAttributesCountry
LOCAL lnAttributesFinancialInstitutionCustomerReferenceRequired
LOCAL lnAttributesFutureDatedPaymentsAllowed
LOCAL lcAttributesLogoUrl
LOCAL lcAttributesMaintenanceFrom
LOCAL lcAttributesMaintenanceTo
LOCAL lcAttributesMaintenanceType
LOCAL lcAttributesMaxRequestedAccountReferences
LOCAL lnAttributesMinRequestedAccountReferences
LOCAL lcAttributesName
LOCAL lnAttributesPaymentsEnabled
LOCAL lnAttributesPeriodicPaymentsEnabled
LOCAL lcAttributesPrimaryColor
LOCAL lnAttributesRequiresCredentialStorage
LOCAL lnAttributesRequiresCustomerIpAddress
LOCAL lnAttributesSandbox
LOCAL lcAttributesSecondaryColor
LOCAL lcAttributesSharedBrandName
LOCAL lcAttributesSharedBrandReference
LOCAL lcAttributesStatus
LOCAL lcId
LOCAL lcLinksSelf
LOCAL lcV_type
LOCAL j
LOCAL lnCount_j
LOCAL lcStrVal
LOCAL lcLinksFirst
LOCAL lnMetaPagingLimit
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

* 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.)
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadPfxFile("qa_data/pfx/my_ibanity_certificate.pfx","my_pfx_password")
IF (lnSuccess = 0) THEN
    ? loCert.LastErrorText
    RELEASE loCert
    CANCEL
ENDIF

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

loDtNow = CreateObject('Chilkat.CkDateTime')
loDtNow.SetFromCurrentSystemTime()
lcCreated = loDtNow.GetAsUnixTimeStr(0)

loCrypt2 = CreateObject('Chilkat.Crypt2')
loCrypt2.HashAlgorithm = "sha512"
loCrypt2.EncodingMode = "base64"

loSbDigestHdrValue = CreateObject('Chilkat.StringBuilder')
loSbDigestHdrValue.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.
loSbDigestHdrValue.Append(loCrypt2.HashStringENC(""))

? "Generated Digest"
? loSbDigestHdrValue.GetAsString()

lcRequest_target = "get /xs2a/financial-institutions"

loSbSigningString = CreateObject('Chilkat.StringBuilder')
loSbSigningString.Append("(request-target): ")
loSbSigningString.AppendLine(lcRequest_target,0)
loSbSigningString.Append("host: ")
loSbSigningString.AppendLine("api.ibanity.com",0)
loSbSigningString.Append("digest: ")
loSbSigningString.AppendLine(loSbDigestHdrValue.GetAsString(),0)
loSbSigningString.Append("(created): ")
loSbSigningString.Append(lcCreated)
* ibanity-idempotency-key is not used with GET requests.

? "Signing String:"
? loSbSigningString.GetAsString()

lcSigned_headers_list = "(request-target) host digest (created)"

loPrivKey = CreateObject('Chilkat.PrivateKey')
lnSuccess = loPrivKey.LoadEncryptedPemFile("my_ibanity_signature_private_key.pem","pem_password")
IF (lnSuccess = 0) THEN
    ? loPrivKey.LastErrorText
    RELEASE loCert
    RELEASE loDtNow
    RELEASE loCrypt2
    RELEASE loSbDigestHdrValue
    RELEASE loSbSigningString
    RELEASE loPrivKey
    CANCEL
ENDIF

loRsa = CreateObject('Chilkat.Rsa')
loRsa.PssSaltLen = 32
loRsa.EncodingMode = "base64"
* Use the RSASSA-PSS signature algorithm
loRsa.PkcsPadding = 0

lnSuccess = loRsa.UsePrivateKey(loPrivKey)
IF (lnSuccess = 0) THEN
    ? loRsa.LastErrorText
    RELEASE loCert
    RELEASE loDtNow
    RELEASE loCrypt2
    RELEASE loSbDigestHdrValue
    RELEASE loSbSigningString
    RELEASE loPrivKey
    RELEASE loRsa
    CANCEL
ENDIF

* Sign the signing string.
lcSigBase64 = loRsa.SignStringENC(loSbSigningString.GetAsString(),"sha-256")
IF (loRsa.LastMethodSuccess = 0) THEN
    ? loRsa.LastErrorText
    RELEASE loCert
    RELEASE loDtNow
    RELEASE loCrypt2
    RELEASE loSbDigestHdrValue
    RELEASE loSbSigningString
    RELEASE loPrivKey
    RELEASE loRsa
    CANCEL
ENDIF

? "Signature:"
? lcSigBase64

* Build the signature header value.
loSbSigHeaderValue = CreateObject('Chilkat.StringBuilder')
loSbSigHeaderValue.Append('keyId="')
* Use your identifier for the application's signature certificate, obtained from the Developer Portal
loSbSigHeaderValue.Append("a0ce296d-84c8-4bd5-8eb4-de0339950cfa")
loSbSigHeaderValue.Append('",created=')
loSbSigHeaderValue.Append(lcCreated)
loSbSigHeaderValue.Append(',algorithm="hs2019",headers="')
loSbSigHeaderValue.Append(lcSigned_headers_list)
loSbSigHeaderValue.Append('",signature="')
loSbSigHeaderValue.Append(lcSigBase64)
loSbSigHeaderValue.Append('"')

* Send the GET request..
loHttp = CreateObject('Chilkat.Http')

lnSuccess = loHttp.SetSslClientCert(loCert)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loCert
    RELEASE loDtNow
    RELEASE loCrypt2
    RELEASE loSbDigestHdrValue
    RELEASE loSbSigningString
    RELEASE loPrivKey
    RELEASE loRsa
    RELEASE loSbSigHeaderValue
    RELEASE loHttp
    CANCEL
ENDIF

loHttp.SetRequestHeader("Signature",loSbSigHeaderValue.GetAsString())
loHttp.SetRequestHeader("Digest",loSbDigestHdrValue.GetAsString())

loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://api.ibanity.com/xs2a/financial-institutions",loSbResponseBody)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loCert
    RELEASE loDtNow
    RELEASE loCrypt2
    RELEASE loSbDigestHdrValue
    RELEASE loSbSigningString
    RELEASE loPrivKey
    RELEASE loRsa
    RELEASE loSbSigHeaderValue
    RELEASE loHttp
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    RELEASE loCert
    RELEASE loDtNow
    RELEASE loCrypt2
    RELEASE loSbDigestHdrValue
    RELEASE loSbSigningString
    RELEASE loPrivKey
    RELEASE loRsa
    RELEASE loSbSigHeaderValue
    RELEASE loHttp
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

* 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

lcLinksFirst = loJResp.StringOf("links.first")
lnMetaPagingLimit = loJResp.IntOf("meta.paging.limit")
i = 0
lnCount_i = loJResp.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcAttributesBic = loJResp.StringOf("data[i].attributes.bic")
    lnAttributesBulkPaymentsEnabled = loJResp.BoolOf("data[i].attributes.bulkPaymentsEnabled")
    lcAttributesCountry = loJResp.StringOf("data[i].attributes.country")
    lnAttributesFinancialInstitutionCustomerReferenceRequired = loJResp.BoolOf("data[i].attributes.financialInstitutionCustomerReferenceRequired")
    lnAttributesFutureDatedPaymentsAllowed = loJResp.BoolOf("data[i].attributes.futureDatedPaymentsAllowed")
    lcAttributesLogoUrl = loJResp.StringOf("data[i].attributes.logoUrl")
    lcAttributesMaintenanceFrom = loJResp.StringOf("data[i].attributes.maintenanceFrom")
    lcAttributesMaintenanceTo = loJResp.StringOf("data[i].attributes.maintenanceTo")
    lcAttributesMaintenanceType = loJResp.StringOf("data[i].attributes.maintenanceType")
    lcAttributesMaxRequestedAccountReferences = loJResp.StringOf("data[i].attributes.maxRequestedAccountReferences")
    lnAttributesMinRequestedAccountReferences = loJResp.IntOf("data[i].attributes.minRequestedAccountReferences")
    lcAttributesName = loJResp.StringOf("data[i].attributes.name")
    lnAttributesPaymentsEnabled = loJResp.BoolOf("data[i].attributes.paymentsEnabled")
    lnAttributesPeriodicPaymentsEnabled = loJResp.BoolOf("data[i].attributes.periodicPaymentsEnabled")
    lcAttributesPrimaryColor = loJResp.StringOf("data[i].attributes.primaryColor")
    lnAttributesRequiresCredentialStorage = loJResp.BoolOf("data[i].attributes.requiresCredentialStorage")
    lnAttributesRequiresCustomerIpAddress = loJResp.BoolOf("data[i].attributes.requiresCustomerIpAddress")
    lnAttributesSandbox = loJResp.BoolOf("data[i].attributes.sandbox")
    lcAttributesSecondaryColor = loJResp.StringOf("data[i].attributes.secondaryColor")
    lcAttributesSharedBrandName = loJResp.StringOf("data[i].attributes.sharedBrandName")
    lcAttributesSharedBrandReference = loJResp.StringOf("data[i].attributes.sharedBrandReference")
    lcAttributesStatus = loJResp.StringOf("data[i].attributes.status")
    lcId = loJResp.StringOf("data[i].id")
    lcLinksSelf = loJResp.StringOf("data[i].links.self")
    lcV_type = loJResp.StringOf("data[i].type")
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.authorizationModels")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.authorizationModels[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.bulkPaymentsProductTypes")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.bulkPaymentsProductTypes[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.paymentsProductTypes")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.paymentsProductTypes[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.periodicPaymentsProductTypes")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.periodicPaymentsProductTypes[j]")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loCert
RELEASE loDtNow
RELEASE loCrypt2
RELEASE loSbDigestHdrValue
RELEASE loSbSigningString
RELEASE loPrivKey
RELEASE loRsa
RELEASE loSbSigHeaderValue
RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJResp