Overview

Hooks are a feature that allows you to trigger actions or receive notifications at specific stages of a transaction. They are executed asynchronously, meaning that failure in hook execution do not block or affect the main transaction.

You might use hooks to send notifications when payments complete, update external databases after user signups, or log specific transaction details for monitoring.

By keeping these extra tasks separate from the core business logic, hooks help you maintain a modular, scalable, and resilient system design.


Types of hooks

Blnk supports two types of hooks:

  1. Pre-transaction hooks (PRE_TRANSACTION)
  2. Post-transaction hooks (POST_TRANSACTION)

Pre-transaction hooks

PRE_TRANSACTION executes before any transaction begins, serving as the first line of defense and preparation in your transaction pipeline.

Some ideal use cases are:

  1. Data validation: Ensures all incoming transaction data meets your required standards for quality and consistency.

  2. Pre-processing checks: Verifies that all necessary preconditions are met before proceeding.

  3. Data enrichment: Fetches additional details from external services to enhance transaction data.

  4. Audit logging: Records initial transaction details to your monitoring systems for tracking and compliance.

Example scenario:

When a customer places an order, a pre-transaction hook automatically contacts a credit scoring API to validate the customer’s creditworthiness before processing. This validation ensures that only qualified transactions move forward.

Post-transaction hooks

POST_TRANSACTION executes after a transaction has been completed, handling all necessary follow-up actions and integrations.

Some ideal use cases are:

  1. Notification: Sends alerts to external systems and users about completed transactions.

  2. Data synchronisation: Updates connected systems like CRMs, accounting tools, and fraud monitoring platforms with the latest transaction data.

  3. Logging & auditing: Creates detailed records for monitoring, compliance, and troubleshooting.

  4. Settlement processing: Transmits transaction records to settlement and reconciliation systems.

Example scenario:

A common implementation is fraud detection, where the post-transaction hook automatically sends transaction details to a fraud analysis system. This system examines patterns and flags suspicious activities without impacting the original transaction flow.


Benefits of using hooks

  1. Extensibility & modularity:

    Hooks allow you to add new features and functionality without touching the core transaction logic. For example, you can add new analytics tracking or notification systems by simply creating new hooks, keeping your codebase clean and maintainable.

  2. Asynchronous processing:

    By handling side operations asynchronously, hooks prevent performance bottlenecks in your main transaction flow. When a transaction occurs, hooks can process tasks like sending emails or updating external systems in the background, ensuring the primary transaction completes quickly.

  3. Error isolation:

    If a hook fails (for example, if an external notification service is down), it won’t impact the core transaction. This isolation ensures that critical business operations continue even when auxiliary services experience issues.

  4. Flexibility:

    Hooks provide a standardized way to integrate with various external services and systems. Whether you’re connecting to CRM systems, payment processors, or analytics platforms, hooks offer a consistent integration pattern that’s easy to implement and maintain.

  5. Scalability:

    As your system grows, hooks help manage increasing complexity. They let you efficiently handle more auxiliary tasks, additional integrations, and growing data requirements while maintaining system stability. For instance, you can easily add new monitoring systems or data processors without restructuring your core application.

  6. System maintenance:

    Hooks make it easier to:

    • Debug issues by isolating problems to specific hooks.
    • Update integrations without system-wide changes.
    • Monitor and optimize performance of individual components.

Need help?

We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool.

To ask questions or discuss issues, please contact us or join our Discord community.

Sign up on Blnk Cloud

Connect your Blnk Ledger and explore advanced features (access control & collaboration, anomaly detection, secure storage & file management, etc.) in one intuitive dashboard.