Skip to content

C# example for ClearBank® API and Webhooks

Notifications You must be signed in to change notification settings

alimazrae/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 5 application that demonstrates how to make a call to the ClearBank API and how to receive, validate and respond to webhooks.

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

Overview

The application has one controller with 2 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 from ClearBank

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 on the ClearBank Portal

You will need:

  • Your private key and a Certificate Signing Request (CSR) 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
  • Your public key which can be downloaded from the Webhook Management page of the ClearBank Portal

Copy your public key, API token and the ClearBank public key into the SampleController constructor.

Build and run

dotnet run

Application starts listening on port 5000. You can also test it:

curl.exe --location --request POST "http://localhost:5000/sample/api" --header "Content-Type: application/json" --data-raw "{\"fieldName\" :\"test\"}"

Now set up ngrok

.\ngrok.exe http 5000

You will get an output similar to

Forwarding https://91bf871fa2aa.ngrok.io -> http://localhost:5000 

Copy the url and add /sample/webhook at the end.

The full url will be https://91bf871fa2aa.ngrok.io/sample/webhook. On the Webhook Management page of the ClearBank Portal, find the test webhook i.e. FITestEvent, enable it and set the webhook URL. Click the Test button to receive a webhook in the application and see it in the console:

Received webhook: FITestEvent, payload: Test

Demo

demo

About

C# example for ClearBank® API and Webhooks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%