Webhooks and events
Learn about Trustly event notifications (webhooks) and client-side event listeners
Trustly uses two complementary event systems: server-side webhooks (Event Notifications) to communicate transaction status changes to your backend, and client-side Event Listeners to track user interactions within the Trustly Lightbox.
Event Notifications (Webhooks)
Event Notifications are Event objects pushed to the merchant server. A notification indicates changes to the object referenced in the event, such as changes to the transaction status (authorized, canceled, denied). For most use cases, receiving and processing event notifications is required to successfully integrate a Trustly product.
Trustly uses asynchronous event notifications (webhooks) to communicate transaction status. Because transfers on the Automated Clearing House (ACH) network are not instant, you cannot rely on the immediate API response to determine the final state. You must implement a notification handler to receive and process these updates.
Prerequisites
Before you can handle event notifications, ensure you have completed the following:
- Publicly Accessible Endpoint: You must have a publicly accessible HTTPS endpoint on your server to receive POST requests from Trustly.
- Security Configuration: You should be prepared to validate the cryptographic signature included in the request headers to ensure the notification is authentic. See Validate the notification signature.
Configure your listener
To receive notifications, you must configure a webhook listener URL. You can configure this URL in two ways:
- Default configuration: Contact your Trustly Integration team or Support representative to configure a default
notificationUrlin the Trustly administrative interface. - Per-Transaction: Override the default by passing a specific
notificationUrlin theestablishDataobject when you initiate a transaction. See Establish Data for more information.
Trustly sends a POST request to your endpoint with the event details. Your system must acknowledge receipt by returning a 200 OK status.
You must return HTTP status 200 OK in less than 3 seconds. If Trustly does not receive a 200 OK response in 3 seconds, we will retry the notification every 5 minutes for 12 hours.
Example Header
Security
Ensure you verify the event notification was sent by Trustly and has not been tampered with by following the steps in Secure Requests to validate the request signature provided.
Event headers
An Event notification contains the following headers:
Sandbox event timing
In the Trustly Sandbox environment, some asynchronous notifications such as payout processing are run in batches every 300 seconds (5 minutes).
Event properties
An Event notification body is an application/x-www-form-urlencoded string containing various data points. All events contain at a minimum, the following parameters:
Primary properties
Conditional properties
The following properties are included on some events based on the transactionType and eventType:
Event types
Authorize event example
Verify the signature
To ensure the notification originated from Trustly and has not been tampered with, validate the cryptographic signature included in the Authorization request header.
See Validate the notification signature for implementation details and code samples.
Available Funds Guidance
If your merchant account is enabled for Available Funds Guidance (AFG), you can use webhook payloads to intelligently recover transactions that fail due to insufficient funds.
When a payment fails, the notification payload may contain a suggestedRetryAmount. This value represents a safe upper limit for a new transaction attempt based on the customer’s available balance at the time of the failure.
Prerequisites: Contact your Trustly Customer Success Manager or Implementation Team to enable Available Funds Guidance for your merchant account.
To implement this recovery logic:
- Listen for
DenyorFailedevents wherepaymentProviderTransaction.statusequalsSW021(Insufficient Funds) orSW054(Security Controls), ANDsuggestedRetryAmountis greater than0. - Check the payload for the
suggestedRetryAmountfield. - Prompt the customer to retry the payment using the suggested value.
Event Listeners (client-side)
The Trustly SDK provides an addPanelListener function which is used to track user events within the Trustly Lightbox experience. This function is also essential for intercepting the standard browser redirects (returnUrl and cancelUrl) in order to process those final events with JavaScript callbacks directly within your Single Page Application (SPA).
Supported notifications and event types
You can use the addPanelListener function to provide a custom handler to deal with Lightbox events.
The JavaScript window event notification call below only works on native apps when the Trustly SDK is used or if the merchant implements the creation of new windows.
Listener example
Command and event reference
The listener receives two parameters: the high-level command (open, close, event) and the detailed object data.