Skip to content

clearbank/fi-api-101

Repository files navigation

ClearBank® API 101

This repository is intended for users who are testing their connectivity and interaction with the ClearBank API and webhooks.

It contains an example .NET 8 application that demonstrates how to make a call to the ClearBank API and how to receive, validate and respond to webhooks using minimal APIs.

Please note that the code in this repository is not production ready and has been simplified for brevity.

Overview

The application has the following minimal API endpoints:

  • POST /sample/api to make an API request to the POST /v1/test endpoint in the ClearBank API.
  • POST /sample/webhook to receive webhooks.
  • POST /webhooktrigger/trigger to simulate sending a webhook (for testing purposes).

It does payload signing for API calls and signature verification for webhooks.

Prerequisites

To be able to run the application and receive webhooks, you will need:

Set up

You will need:

  • To generate a public and private key pair (PKCS#8 format), this can be done using open source tools such as openssl.
  • To generate a Certificate Signing Request (CSR) using your private key which was created in the previous step. The CSR should be created in PKCS#10 format.
  • An API token which can be generated by uploading your CSR file on the Certificates and Tokens page of the ClearBank Portal

Copy your API token, private key, and public key into the AuthProfile configuration in the Startup.cs file.

Build and run

dotnet run

Application starts listening on port 5000.

Testing the API endpoint

You can test the API endpoint by running the following command, which will use the contents of the test.json file as the body of the request:

curl.exe --location --request POST "http://localhost:5000/sample/api" --header "Content-Type: application/json" --data-binary "@test.json"

You will receive the request body and the correlation ID as a response.

Testing the webhooks endpoint

To test webhooks functionality, you can use the webhook trigger endpoint to simulate sending a simplified webhook to the webhooks receiver endpoint:

 curl.exe --location --request POST "http://localhost:5000/webhooktrigger/trigger" --header "Content-Type: application/json" --data-binary "@test.json"

This will simulate sending a webhook to the /sample/webhook endpoint and you will see the following output in the console:

Received webhook: test.webhook, payload: {"FieldName":"test"}

Demo

demo

About

C# example for ClearBank® API and Webhooks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages