API Documentation
Signup Now
  • Welcome!
  • Authenticate with Api-secret keys
  • Lenme Webhooks
    • Lenme Webhook Events
    • Integrating Lenme Webhooks
  • Reference
    • API Reference
    • List borrower's loan request
    • Get Borrower Loan History
    • Offer Loan Requests
    • Fund Loan
    • Fetch Banking Data
    • Fetch Transfer History
    • Get Loans
    • Get Loan payments
    • Fetch Third Party Service
Powered by GitBook
On this page
  • Integrating Lenme Webhooks into Your Server
  • Code examples for verification incoming webhooks
  1. Lenme Webhooks

Integrating Lenme Webhooks

Integrating real time Lenme webhook notifications into your server side

Integrating Lenme Webhooks into Your Server

Webhooks provide real-time notifications about events, allowing your server to stay updated as changes occur. Lenme's webhook functionality enables your server to receive these notifications seamlessly. This guide will walk you through the integration process using multiple programming languages such as Python, Java, PHP, and more.

Verification and Data Extraction

The integration process involves verifying and extracting data from the webhook payload and headers. When a webhook notification is received, it includes a JSON payload encoded as a JWT token. This token contains all the necessary event data. Additionally, headers such as X-Lenme-Topic identify the type of event.

To ensure the integrity and authenticity of the received data, the webhook payload is signed using a secret key provided during subscription. This secret key allows your server to decode the JWT token and verify its authenticity. Once verified, the data can be extracted and processed accordingly.

This guide will provide step-by-step instructions on how to handle these tasks, including:

  • Setting up your server to receive webhook notifications.

  • Verifying the JWT token using the provided secret key.

  • Extracting event data from the payload.

  • Processing the data based on the event type indicated in the headers.

Code examples for verification incoming webhooks

import json
import jwt

secret_key = "your-webhook-secret-key-here"

def validate_lenme_webhook(request_body, headers):
    body = json.loads(request_body)
    token = body.get("token")
    topic = headers.get("X-Lenme-Topic")
    data = jwt.decode(token, secret_key, algorithms=["HS256"])
    return data
import org.json.JSONObject;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.Claims;

public class ValidateLenmeWebhook {
    private static final String SECRET_KEY = "your-webhook-secret-key-here";

    public static Claims validateLenmeWebhook(String requestBody, Map<String, String> headers) {
        JSONObject body = new JSONObject(requestBody);
        String token = body.getString("token");
        String topic = headers.get("X-Lenme-Topic");

        Claims data = Jwts.parser()
                          .setSigningKey(SECRET_KEY.getBytes())
                          .parseClaimsJws(token)
                          .getBody();
        return data;
    }
}
require 'json'
require 'jwt'

SECRET_KEY = 'your-webhook-secret-key-here'

def validate_lenme_webhook(request_body, headers)
  body = JSON.parse(request_body)
  token = body['token']
  topic = headers['X-Lenme-Topic']

  decoded = JWT.decode(token, SECRET_KEY, true, algorithm: 'HS256')[0]
  return decoded
end
const jwt = require('jsonwebtoken');

const SECRET_KEY = 'your-webhook-secret-key-here';

function validateLenmeWebhook(requestBody, headers) {
  const body = JSON.parse(requestBody);
  const token = body.token;
  const topic = headers['X-Lenme-Topic'];

  const data = jwt.verify(token, SECRET_KEY);
  return data;
}
<?php
require 'vendor/autoload.php';
use \Firebase\JWT\JWT;

$secret_key = "your-webhook-secret-key-here";

function validate_lenme_webhook($request_body, $headers) {
    $body = json_decode($request_body, true);
    $token = $body['token'];
    $topic = $headers['X-Lenme-Topic'];

    $decoded = JWT::decode($token, $secret_key, array('HS256'));
    return $decoded;
}
?>
PreviousLenme Webhook EventsNextAPI Reference

Last updated 10 months ago