How to set up multi-channel merchants notifications for Mollie
Last updated
Last updated
In this guide, you'll learn how to intercept all payment status updates and send notifications over multiple channels so you track all the payments made on your platform
You'll learn how to create a flow that sends WhatsApp and SMS notifications for all payment updates that move to the paid status. We’ll be using Flow Builder’s inbound webhook capabilities coupled with Mollie’s payment webhook functionality.
Requirements
Note: In this guide we have been listening to the payments webhook; however, we can easily replace that with the Orders API, in which case we would need to adapt the flow to the order states (authorized or paid).
Defining the webhook on the FlowBuilder side
The Mollie payments API provides you with the possibility of defining a webhook URL whenever a payment is created — a webhook will be invoked every time the payment’s status changes.
To guarantee security, the webhook will only receive the payment ID as a parameter. We will do a lookup on the actual payment information to determine what the payment status is.
Go to Flow Builder and create a new flow.
Select Webhook as the trigger of your flow.
The webhook will only have id as a parameter.
Add an End flow step so that we can get the webhook URL.
Save and Publish your flow in the top right corner of your screen. Once you do, you will receive the webhook address.
In the CURL example above, the id will be the only recognized parameter from the payload sent to the URL. If you send it additional parameters, they will be discarded.
Connecting the webhook to the payment
To create a payment with Mollie, pass this URL as the webhook parameter, so that you get the payment notification inside the flow you just created:
In the CURL example above, the webhookUrl points to the webhook you just configured with MessageBird.
In this payment example code, we are passing the Mollie test API key from the account you want to connect to. Once this flow is fully validated, we should pass the Live account API key from Mollie's Dashboard:
Looking up payment information on Mollie
When the webhook URL is called we need to retrieve the payment information from Mollie, and extract the necessary data from the payload. To make this happen:
Add a Fetch Variables step to your flow that points to the /get-payment endpoint of your Mollie installation.
Configure this step as follows:
URL:
Where the {id} is the parameter received by the webhook
Method: GET
Add the authentication header to the request, passing again your Mollie test API key
Key: Authorization
Value: Bearer test_VkW7f9CVGqzGrGk6WFy1ARgFjGT292
Variables: We will extract from the response returned by the /get-payments URL the information for the notifications. Since we are dealing with JSON data, we will refer to the key by its name and when dealing with hierarchies of data will use . (dot) to move to the next level:
status
description
amount.value
amount.currency
The final setup should look like this:
And the variables should look like the following:
Done? Awesome! Now it's time to send the extracted information to the interested parties.
Setting up channels for communication
To send notifications, we will define the communication channels - for this example, we will use the SMS channel and WhatsApp Sandbox channel.
To active the SMS channel, go to your Channels in the MessageBird Dashboard.
To enable the WhatsApp sandbox, go to this dedicated page
You can add Facebook Messenger, Line, WeChat, email, Telegram and Instagram as additional channels!
Channel limitations
Every channel has platform-specific rules and might require a separate authorization procedure as well as its own messaging policy. For WhatsApp, you need to define and get a Template Message approved to send unsolicited messages.
For this demo, we assume that you can freely send a message on the channel, without having to resort to templates. Make sure to read the documentation to understand what you can do for each particular channel.
Sending conversation messages based on payment statuses
Now that the channels are defined, it is time to add a couple of Send conversations message steps to the flow. We will add two notifications:
We will always send all the order information over a WhatsApp message, such as “{status} {amount.value} {amount.currency} {description}” which would translate at run time to “created 10 EUR bookshelf 10A”.
We will send a message over SMS only if the status of the payment switched to paid.
For both notifications, the Send conversations message step will be configured with type Text and the recipient will be the telephone number/WhatsApp number you would like to send the notification to.
The final flow looks like this:
The first Send conversation message configuration:
The second Send conversation message configuration:
Connecting notifications to your existing checkout flow
You might already have an existing webhook attached to the payments or orders API. In that case, you might like to maintain that functionality:
At the end of the flow you can add an HTTP request step, which will make one last call to your existing webhook, passing the payment id as a parameter (the same payload you would have received from Mollie callback).
The content of the HTTP Request step is a POST towards your existing webhook, with a JSON payload that contains the request ID.
Testing and debugging
If you want to validate and test the logic of the flow, you can use the Test flow functionality, which will start up the Emulator and allow you to define custom payloads for each call and response.
Going live
Once the flow is up and running, every time a payment changes status, you will receive notifications via WhatsApp and when a payment goes to status paid, you will also get an SMS.