Webhooks and Events
Learn about Trustly event notifications (webhooks) and client-side event listeners
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 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.
Before you can handle event notifications, ensure you have completed the following:
To receive notifications, you must configure a webhook listener URL. You can configure this URL in two ways:
notificationUrl in the Trustly administrative interface.notificationUrl in the establishData object 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
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.
An Event notification contains the following headers:
In the Trustly Sandbox environment, some asynchronous notifications such as payout processing are run in batches every 300 seconds (5 minutes).
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:
The following properties are included on some events based on the transactionType and eventType:
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.
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:
Deny or Failed events where paymentProviderTransaction.status equals SW021 (Insufficient Funds) or SW054 (Security Controls), AND suggestedRetryAmount is greater than 0.suggestedRetryAmount field.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).
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.
The listener receives two parameters: the high-level command (open, close, event) and the detailed object data.