Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C++) Ibanity XS2A List Financial InstitutionsSee more Ibanity ExamplesDemonstrates how to send a request to get a list of financial institutions. For more information, see https://documentation.ibanity.com/xs2a/api/curl#authentication
#include <CkCertW.h> #include <CkDateTimeW.h> #include <CkCrypt2W.h> #include <CkStringBuilderW.h> #include <CkPrivateKeyW.h> #include <CkRsaW.h> #include <CkHttpW.h> #include <CkJsonObjectW.h> void ChilkatSample(void) { // 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.) CkCertW cert; bool success = cert.LoadPfxFile(L"qa_data/pfx/my_ibanity_certificate.pfx",L"my_pfx_password"); if (success == false) { wprintf(L"%s\n",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. CkDateTimeW dtNow; dtNow.SetFromCurrentSystemTime(); const wchar_t *created = dtNow.getAsUnixTimeStr(false); CkCrypt2W crypt2; crypt2.put_HashAlgorithm(L"sha512"); crypt2.put_EncodingMode(L"base64"); CkStringBuilderW sbDigestHdrValue; sbDigestHdrValue.Append(L"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(L"")); wprintf(L"Generated Digest\n"); wprintf(L"%s\n",sbDigestHdrValue.getAsString()); const wchar_t *request_target = L"get /xs2a/financial-institutions"; CkStringBuilderW sbSigningString; sbSigningString.Append(L"(request-target): "); sbSigningString.AppendLine(request_target,false); sbSigningString.Append(L"host: "); sbSigningString.AppendLine(L"api.ibanity.com",false); sbSigningString.Append(L"digest: "); sbSigningString.AppendLine(sbDigestHdrValue.getAsString(),false); sbSigningString.Append(L"(created): "); sbSigningString.Append(created); // ibanity-idempotency-key is not used with GET requests. wprintf(L"Signing String:\n"); wprintf(L"%s\n",sbSigningString.getAsString()); const wchar_t *signed_headers_list = L"(request-target) host digest (created)"; CkPrivateKeyW privKey; success = privKey.LoadEncryptedPemFile(L"my_ibanity_signature_private_key.pem",L"pem_password"); if (success == false) { wprintf(L"%s\n",privKey.lastErrorText()); return; } CkRsaW rsa; rsa.put_PssSaltLen(32); rsa.put_EncodingMode(L"base64"); // Use the RSASSA-PSS signature algorithm rsa.put_OaepPadding(true); success = rsa.ImportPrivateKeyObj(privKey); if (success == false) { wprintf(L"%s\n",rsa.lastErrorText()); return; } // Sign the signing string. const wchar_t *sigBase64 = rsa.signStringENC(sbSigningString.getAsString(),L"sha-256"); if (rsa.get_LastMethodSuccess() == false) { wprintf(L"%s\n",rsa.lastErrorText()); return; } wprintf(L"Signature:\n"); wprintf(L"%s\n",sigBase64); // Build the signature header value. CkStringBuilderW sbSigHeaderValue; sbSigHeaderValue.Append(L"keyId=\""); // Use your identifier for the application's signature certificate, obtained from the Developer Portal sbSigHeaderValue.Append(L"a0ce296d-84c8-4bd5-8eb4-de0339950cfa"); sbSigHeaderValue.Append(L"\",created="); sbSigHeaderValue.Append(created); sbSigHeaderValue.Append(L",algorithm=\"hs2019\",headers=\""); sbSigHeaderValue.Append(signed_headers_list); sbSigHeaderValue.Append(L"\",signature=\""); sbSigHeaderValue.Append(sigBase64); sbSigHeaderValue.Append(L"\""); // Send the GET request.. CkHttpW http; success = http.SetSslClientCert(cert); if (success == false) { wprintf(L"%s\n",http.lastErrorText()); return; } http.SetRequestHeader(L"Signature",sbSigHeaderValue.getAsString()); http.SetRequestHeader(L"Digest",sbDigestHdrValue.getAsString()); CkStringBuilderW sbResponseBody; success = http.QuickGetSb(L"https://api.ibanity.com/xs2a/financial-institutions",sbResponseBody); if (success == false) { wprintf(L"%s\n",http.lastErrorText()); return; } CkJsonObjectW jResp; jResp.LoadSb(sbResponseBody); jResp.put_EmitCompact(false); wprintf(L"Response Body:\n"); wprintf(L"%s\n",jResp.emit()); int respStatusCode = http.get_LastStatus(); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",http.lastHeader()); wprintf(L"Failed.\n"); 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 // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. const wchar_t *attributesBic = 0; bool attributesBulkPaymentsEnabled; const wchar_t *attributesCountry = 0; bool attributesFinancialInstitutionCustomerReferenceRequired; bool attributesFutureDatedPaymentsAllowed; const wchar_t *attributesLogoUrl = 0; const wchar_t *attributesMaintenanceFrom = 0; const wchar_t *attributesMaintenanceTo = 0; const wchar_t *attributesMaintenanceType = 0; const wchar_t *attributesMaxRequestedAccountReferences = 0; int attributesMinRequestedAccountReferences; const wchar_t *attributesName = 0; bool attributesPaymentsEnabled; bool attributesPeriodicPaymentsEnabled; const wchar_t *attributesPrimaryColor = 0; bool attributesRequiresCredentialStorage; bool attributesRequiresCustomerIpAddress; bool attributesSandbox; const wchar_t *attributesSecondaryColor = 0; const wchar_t *attributesSharedBrandName = 0; const wchar_t *attributesSharedBrandReference = 0; const wchar_t *attributesStatus = 0; const wchar_t *id = 0; const wchar_t *linksSelf = 0; const wchar_t *v_type = 0; int j; int count_j; const wchar_t *strVal = 0; const wchar_t *linksFirst = jResp.stringOf(L"links.first"); int metaPagingLimit = jResp.IntOf(L"meta.paging.limit"); int i = 0; int count_i = jResp.SizeOfArray(L"data"); while (i < count_i) { jResp.put_I(i); attributesBic = jResp.stringOf(L"data[i].attributes.bic"); attributesBulkPaymentsEnabled = jResp.BoolOf(L"data[i].attributes.bulkPaymentsEnabled"); attributesCountry = jResp.stringOf(L"data[i].attributes.country"); attributesFinancialInstitutionCustomerReferenceRequired = jResp.BoolOf(L"data[i].attributes.financialInstitutionCustomerReferenceRequired"); attributesFutureDatedPaymentsAllowed = jResp.BoolOf(L"data[i].attributes.futureDatedPaymentsAllowed"); attributesLogoUrl = jResp.stringOf(L"data[i].attributes.logoUrl"); attributesMaintenanceFrom = jResp.stringOf(L"data[i].attributes.maintenanceFrom"); attributesMaintenanceTo = jResp.stringOf(L"data[i].attributes.maintenanceTo"); attributesMaintenanceType = jResp.stringOf(L"data[i].attributes.maintenanceType"); attributesMaxRequestedAccountReferences = jResp.stringOf(L"data[i].attributes.maxRequestedAccountReferences"); attributesMinRequestedAccountReferences = jResp.IntOf(L"data[i].attributes.minRequestedAccountReferences"); attributesName = jResp.stringOf(L"data[i].attributes.name"); attributesPaymentsEnabled = jResp.BoolOf(L"data[i].attributes.paymentsEnabled"); attributesPeriodicPaymentsEnabled = jResp.BoolOf(L"data[i].attributes.periodicPaymentsEnabled"); attributesPrimaryColor = jResp.stringOf(L"data[i].attributes.primaryColor"); attributesRequiresCredentialStorage = jResp.BoolOf(L"data[i].attributes.requiresCredentialStorage"); attributesRequiresCustomerIpAddress = jResp.BoolOf(L"data[i].attributes.requiresCustomerIpAddress"); attributesSandbox = jResp.BoolOf(L"data[i].attributes.sandbox"); attributesSecondaryColor = jResp.stringOf(L"data[i].attributes.secondaryColor"); attributesSharedBrandName = jResp.stringOf(L"data[i].attributes.sharedBrandName"); attributesSharedBrandReference = jResp.stringOf(L"data[i].attributes.sharedBrandReference"); attributesStatus = jResp.stringOf(L"data[i].attributes.status"); id = jResp.stringOf(L"data[i].id"); linksSelf = jResp.stringOf(L"data[i].links.self"); v_type = jResp.stringOf(L"data[i].type"); j = 0; count_j = jResp.SizeOfArray(L"data[i].attributes.authorizationModels"); while (j < count_j) { jResp.put_J(j); strVal = jResp.stringOf(L"data[i].attributes.authorizationModels[j]"); j = j + 1; } j = 0; count_j = jResp.SizeOfArray(L"data[i].attributes.bulkPaymentsProductTypes"); while (j < count_j) { jResp.put_J(j); strVal = jResp.stringOf(L"data[i].attributes.bulkPaymentsProductTypes[j]"); j = j + 1; } j = 0; count_j = jResp.SizeOfArray(L"data[i].attributes.paymentsProductTypes"); while (j < count_j) { jResp.put_J(j); strVal = jResp.stringOf(L"data[i].attributes.paymentsProductTypes[j]"); j = j + 1; } j = 0; count_j = jResp.SizeOfArray(L"data[i].attributes.periodicPaymentsProductTypes"); while (j < count_j) { jResp.put_J(j); strVal = jResp.stringOf(L"data[i].attributes.periodicPaymentsProductTypes[j]"); j = j + 1; } i = i + 1; } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.