Objective-C
Objective-C
Ibanity XS2A List Financial Institutions
See more Ibanity Examples
Demonstrates how to send a request to get a list of financial institutions.Chilkat Objective-C Downloads
#import <CkoCert.h>
#import <CkoDateTime.h>
#import <NSString.h>
#import <CkoCrypt2.h>
#import <CkoStringBuilder.h>
#import <CkoPrivateKey.h>
#import <CkoRsa.h>
#import <CkoHttp.h>
#import <CkoJsonObject.h>
BOOL success = NO;
// 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.)
CkoCert *cert = [[CkoCert alloc] init];
success = [cert LoadPfxFile: @"qa_data/pfx/my_ibanity_certificate.pfx" password: @"my_pfx_password"];
if (success == NO) {
NSLog(@"%@",cert.LastErrorText);
return;
}
// 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.
CkoDateTime *dtNow = [[CkoDateTime alloc] init];
[dtNow SetFromCurrentSystemTime];
NSString *created = [dtNow GetAsUnixTimeStr: NO];
CkoCrypt2 *crypt2 = [[CkoCrypt2 alloc] init];
crypt2.HashAlgorithm = @"sha512";
crypt2.EncodingMode = @"base64";
CkoStringBuilder *sbDigestHdrValue = [[CkoStringBuilder alloc] init];
[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: @""]];
NSLog(@"%@",@"Generated Digest");
NSLog(@"%@",[sbDigestHdrValue GetAsString]);
NSString *request_target = @"get /xs2a/financial-institutions";
CkoStringBuilder *sbSigningString = [[CkoStringBuilder alloc] init];
[sbSigningString Append: @"(request-target): "];
[sbSigningString AppendLine: request_target crlf: NO];
[sbSigningString Append: @"host: "];
[sbSigningString AppendLine: @"api.ibanity.com" crlf: NO];
[sbSigningString Append: @"digest: "];
[sbSigningString AppendLine: [sbDigestHdrValue GetAsString] crlf: NO];
[sbSigningString Append: @"(created): "];
[sbSigningString Append: created];
// ibanity-idempotency-key is not used with GET requests.
NSLog(@"%@",@"Signing String:");
NSLog(@"%@",[sbSigningString GetAsString]);
NSString *signed_headers_list = @"(request-target) host digest (created)";
CkoPrivateKey *privKey = [[CkoPrivateKey alloc] init];
success = [privKey LoadEncryptedPemFile: @"my_ibanity_signature_private_key.pem" password: @"pem_password"];
if (success == NO) {
NSLog(@"%@",privKey.LastErrorText);
return;
}
CkoRsa *rsa = [[CkoRsa alloc] init];
rsa.PssSaltLen = [NSNumber numberWithInt:32];
rsa.EncodingMode = @"base64";
// Use the RSASSA-PSS signature algorithm
rsa.PkcsPadding = NO;
success = [rsa UsePrivateKey: privKey];
if (success == NO) {
NSLog(@"%@",rsa.LastErrorText);
return;
}
// Sign the signing string.
NSString *sigBase64 = [rsa SignStringENC: [sbSigningString GetAsString] hashAlg: @"sha-256"];
if (rsa.LastMethodSuccess == NO) {
NSLog(@"%@",rsa.LastErrorText);
return;
}
NSLog(@"%@",@"Signature:");
NSLog(@"%@",sigBase64);
// Build the signature header value.
CkoStringBuilder *sbSigHeaderValue = [[CkoStringBuilder alloc] init];
[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..
CkoHttp *http = [[CkoHttp alloc] init];
success = [http SetSslClientCert: cert];
if (success == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
[http SetRequestHeader: @"Signature" value: [sbSigHeaderValue GetAsString]];
[http SetRequestHeader: @"Digest" value: [sbDigestHdrValue GetAsString]];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [http QuickGetSb: @"https://api.ibanity.com/xs2a/financial-institutions" sbContent: sbResponseBody];
if (success == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;
NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);
int respStatusCode = [http.LastStatus intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
NSLog(@"%@",@"Response Header:");
NSLog(@"%@",http.LastHeader);
NSLog(@"%@",@"Failed.");
return;
}
// 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
NSString *attributesBic = 0;
BOOL attributesBulkPaymentsEnabled;
NSString *attributesCountry = 0;
BOOL attributesFinancialInstitutionCustomerReferenceRequired;
BOOL attributesFutureDatedPaymentsAllowed;
NSString *attributesLogoUrl = 0;
NSString *attributesMaintenanceFrom = 0;
NSString *attributesMaintenanceTo = 0;
NSString *attributesMaintenanceType = 0;
NSString *attributesMaxRequestedAccountReferences = 0;
int attributesMinRequestedAccountReferences;
NSString *attributesName = 0;
BOOL attributesPaymentsEnabled;
BOOL attributesPeriodicPaymentsEnabled;
NSString *attributesPrimaryColor = 0;
BOOL attributesRequiresCredentialStorage;
BOOL attributesRequiresCustomerIpAddress;
BOOL attributesSandbox;
NSString *attributesSecondaryColor = 0;
NSString *attributesSharedBrandName = 0;
NSString *attributesSharedBrandReference = 0;
NSString *attributesStatus = 0;
NSString *id = 0;
NSString *linksSelf = 0;
NSString *v_type = 0;
int j;
int count_j;
NSString *strVal = 0;
NSString *linksFirst = [jResp StringOf: @"links.first"];
int metaPagingLimit = [[jResp IntOf: @"meta.paging.limit"] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"data"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: 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"] intValue];
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"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"data[i].attributes.authorizationModels[j]"];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"data[i].attributes.bulkPaymentsProductTypes"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"data[i].attributes.bulkPaymentsProductTypes[j]"];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"data[i].attributes.paymentsProductTypes"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"data[i].attributes.paymentsProductTypes[j]"];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"data[i].attributes.periodicPaymentsProductTypes"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"data[i].attributes.periodicPaymentsProductTypes[j]"];
j = j + 1;
}
i = i + 1;
}