Callbacks
Callbacks are the mechanism Norce Checkout uses to interact with adapters and external systems during the checkout process. They allow you to extend the checkout logic without tightly coupling your systems. There are three types of callbacks, each serving a distinct purpose:
- Validations: Gatekeepers that approve or deny an order.
- Hooks: Synchronous events that modify order data in real-time.
- Notifications: Asynchronous events that trigger after a change is committed.
Validations
Validations are checks performed to verify that an order is valid before it can proceed to the next step (usually payment). When an order validation is requested, Norce Checkout first checks basic requirements (like having items in the cart and a valid order total).
After basic checks, it invokes all registered Validation Adapters. These external services can enforce custom business rules, such as:
- Verifying stock availability in an ERP.
- Checking if a voucher code is still valid.
- Validating customer credit limits.
- Ensuring the delivery address is serviceable.
If any validation fails, the checkout process is halted, and errors are returned to the frontend.
For technical implementation details, see the Validations Developer Guide.
Hooks
Hooks are synchronous callbacks used to modify the order as it changes. They allow adapters or custom logic to "intervene" in the checkout flow. When a change is attempted on an order (e.g., adding an item), registered hooks are invoked. The hook receives the proposed state and can return a set of changes (patches) to apply to the order.
Common use cases for hooks include:
- Shipping Calculation: Recalculating shipping options when the cart content or address changes.
- Dynamic Pricing: Adjusting item prices based on customer type or quantity.
- Payment Updates: Updating payment amounts when the order total changes.
Hooks are powerful because they allow you to keep data synchronized across different systems (like Cart, Shipping, and Payment) in real-time.
For technical implementation details, see the Hooks Developer Guide.
Notifications
Notifications are asynchronous triggers that occur after a change has been successfully committed to the order. Unlike hooks, they do not block or modify the user's action. They are designed for "fire-and-forget" scenarios or side effects.
Notifications are configured with a scope (a specific part of the order data) and a schema. When the data within the scope changes and matches the schema, the notification is sent.
Common use cases for notifications include:
- Order Completion: Informing an ERP or WMS when an order reaches the
completedstate. - Payment Updates: Notifying a BI system when a payment is captured.
- Customer Updates: Syncing new customer details to a CRM.
For technical implementation details, see the Custom Notifications Developer Guide.