Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Ibanity XS2A List Financial Institutions

See more Ibanity Examples

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

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.CkDateTime,
  Chilkat.Rsa,
  Chilkat.StringBuilder,
  Chilkat.JsonObject,
  Chilkat.PrivateKey,
  Chilkat.Cert,
  Chilkat.Crypt2;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  cert: TCert;
  dtNow: TCkDateTime;
  created: string;
  crypt2: TCrypt2;
  sbDigestHdrValue: TStringBuilder;
  request_target: string;
  sbSigningString: TStringBuilder;
  signed_headers_list: string;
  privKey: TPrivateKey;
  rsa: TRsa;
  sigBase64: string;
  sbSigHeaderValue: TStringBuilder;
  http: THttp;
  sbResponseBody: TStringBuilder;
  jResp: TJsonObject;
  respStatusCode: Integer;
  attributesBic: string;
  attributesBulkPaymentsEnabled: Boolean;
  attributesCountry: string;
  attributesFinancialInstitutionCustomerReferenceRequired: Boolean;
  attributesFutureDatedPaymentsAllowed: Boolean;
  attributesLogoUrl: string;
  attributesMaintenanceFrom: string;
  attributesMaintenanceTo: string;
  attributesMaintenanceType: string;
  attributesMaxRequestedAccountReferences: string;
  attributesMinRequestedAccountReferences: Integer;
  attributesName: string;
  attributesPaymentsEnabled: Boolean;
  attributesPeriodicPaymentsEnabled: Boolean;
  attributesPrimaryColor: string;
  attributesRequiresCredentialStorage: Boolean;
  attributesRequiresCustomerIpAddress: Boolean;
  attributesSandbox: Boolean;
  attributesSecondaryColor: string;
  attributesSharedBrandName: string;
  attributesSharedBrandReference: string;
  attributesStatus: string;
  id: string;
  linksSelf: string;
  v_type: string;
  j: Integer;
  count_j: Integer;
  strVal: string;
  linksFirst: string;
  metaPagingLimit: Integer;
  i: Integer;
  count_i: Integer;

begin
  success := False;

  //  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.)
  cert := TCert.Create;
  success := cert.LoadPfxFile('qa_data/pfx/my_ibanity_certificate.pfx','my_pfx_password');
  if (success = False) then
    begin
      WriteLn(cert.LastErrorText);
      Exit;
    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.

  dtNow := TCkDateTime.Create;
  dtNow.SetFromCurrentSystemTime();
  created := dtNow.GetAsUnixTimeStr(False);

  crypt2 := TCrypt2.Create;
  crypt2.HashAlgorithm := 'sha512';
  crypt2.EncodingMode := 'base64';

  sbDigestHdrValue := TStringBuilder.Create;
  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.HashStringENC(''));

  WriteLn('Generated Digest');
  WriteLn(sbDigestHdrValue.GetAsString());

  request_target := 'get /xs2a/financial-institutions';

  sbSigningString := TStringBuilder.Create;
  sbSigningString.Append('(request-target): ');
  sbSigningString.AppendLine(request_target,False);
  sbSigningString.Append('host: ');
  sbSigningString.AppendLine('api.ibanity.com',False);
  sbSigningString.Append('digest: ');
  sbSigningString.AppendLine(sbDigestHdrValue.GetAsString(),False);
  sbSigningString.Append('(created): ');
  sbSigningString.Append(created);
  //  ibanity-idempotency-key is not used with GET requests.

  WriteLn('Signing String:');
  WriteLn(sbSigningString.GetAsString());

  signed_headers_list := '(request-target) host digest (created)';

  privKey := TPrivateKey.Create;
  success := privKey.LoadEncryptedPemFile('my_ibanity_signature_private_key.pem','pem_password');
  if (success = False) then
    begin
      WriteLn(privKey.LastErrorText);
      Exit;
    end;

  rsa := TRsa.Create;
  rsa.PssSaltLen := 32;
  rsa.EncodingMode := 'base64';
  //  Use the RSASSA-PSS signature algorithm
  rsa.PkcsPadding := False;

  success := rsa.UsePrivateKey(privKey);
  if (success = False) then
    begin
      WriteLn(rsa.LastErrorText);
      Exit;
    end;

  //  Sign the signing string.
  sigBase64 := rsa.SignStringENC(sbSigningString.GetAsString(),'sha-256');
  if (rsa.LastMethodSuccess = False) then
    begin
      WriteLn(rsa.LastErrorText);
      Exit;
    end;

  WriteLn('Signature:');
  WriteLn(sigBase64);

  //  Build the signature header value.
  sbSigHeaderValue := TStringBuilder.Create;
  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..
  http := THttp.Create;

  success := http.SetSslClientCert(cert);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  http.SetRequestHeader('Signature',sbSigHeaderValue.GetAsString());
  http.SetRequestHeader('Digest',sbDigestHdrValue.GetAsString());

  sbResponseBody := TStringBuilder.Create;
  success := http.QuickGetSb('https://api.ibanity.com/xs2a/financial-institutions',sbResponseBody);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  jResp := TJsonObject.Create;
  jResp.LoadSb(sbResponseBody);
  jResp.EmitCompact := False;

  WriteLn('Response Body:');
  WriteLn(jResp.Emit());

  respStatusCode := http.LastStatus;
  WriteLn('Response Status Code = ' + respStatusCode);
  if (respStatusCode >= 400) then
    begin
      WriteLn('Response Header:');
      WriteLn(http.LastHeader);
      WriteLn('Failed.');
      Exit;
    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

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

      j := 0;
      count_j := jResp.SizeOfArray('data[i].attributes.bulkPaymentsProductTypes');
      while j < count_j do
        begin
          jResp.J := j;
          strVal := jResp.StringOf('data[i].attributes.bulkPaymentsProductTypes[j]');
          j := j + 1;
        end;

      j := 0;
      count_j := jResp.SizeOfArray('data[i].attributes.paymentsProductTypes');
      while j < count_j do
        begin
          jResp.J := j;
          strVal := jResp.StringOf('data[i].attributes.paymentsProductTypes[j]');
          j := j + 1;
        end;

      j := 0;
      count_j := jResp.SizeOfArray('data[i].attributes.periodicPaymentsProductTypes');
      while j < count_j do
        begin
          jResp.J := j;
          strVal := jResp.StringOf('data[i].attributes.periodicPaymentsProductTypes[j]');
          j := j + 1;
        end;

      i := i + 1;
    end;



  cert.Free;
  dtNow.Free;
  crypt2.Free;
  sbDigestHdrValue.Free;
  sbSigningString.Free;
  privKey.Free;
  rsa.Free;
  sbSigHeaderValue.Free;
  http.Free;
  sbResponseBody.Free;
  jResp.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.