# How to set up multi-channel merchants notifications for Mollie

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&#x20;

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](https://docs.mollie.com/guides/webhooks).

**Requirements**

* [A MessageBird account](https://dashboard.messagebird.com/en/sign-up)
* [Flow Builder](https://www.messagebird.com/flow-builder/)
* [Mollie API](https://www.mollie.com/en/developers)

**Note:** In this guide we have been listening to the payments webhook; however, we can easily replace that with the [Orders API](https://docs.mollie.com/orders/overview), 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](https://docs.mollie.com/reference/v2/payments-api/create-payment) 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.&#x20;

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](https://dashboard.messagebird.com/en/flow-builder) and **create a new flow**.
* Select **Webhook** as the trigger of your flow.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-7432909e93e5b2c3242b56077b7451dac39f4226%2Fimage13.png?alt=media" alt=""><figcaption></figcaption></figure>

* The webhook will only have **id** as a parameter.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-caba4772183d8c49cc68bf083de5e72f69ee85f1%2Fimage2.png?alt=media" alt=""><figcaption></figcaption></figure>

* Add an **End flow** step so that we can get the webhook URL.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-176403b10b26fe6487d0cea2552f2e6dfbdd041a%2Fimage14.png?alt=media" alt=""><figcaption></figcaption></figure>

* **Save** and **Publish** your flow in the top right corner of your screen. Once you do, you will receive the webhook address.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-4f983116e89039d5957a8d0ab68d0b85f35755e5%2Fimage9.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

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.

&#x20;

**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:

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><pre><code>curl -X POST https://api.mollie.com/v2/payments    -H "Authorization: Bearer 
test_VkW7f9CVGqzGrGk6WFy1ARgFjGT292"    -d "amount[currency]=EUR"    -d "amount[value]=10.00"   
-d "description=Order #12345"    -d "redirectUrl=https://webshop.example.org/order/12345/"    
-d
"webhookUrl=https://flows.messagebird.com/flows/a4819cf0-778e-4189-9235-37fe1bfebe59/invoke"    
-d "metadata={\"order_id\": \"12345\"}"
</code></pre></td></tr></tbody></table>

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](https://www.mollie.com/dashboard/org_8162651/onboarding):

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-b571e7468eb588de547732a5431628c23cef983e%2Fimage8.png?alt=media" alt=""><figcaption></figcaption></figure>

**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](https://docs.mollie.com/reference/v2/payments-api/get-payment) endpoint of your Mollie installation.&#x20;
* Configure this step as follows:
* * URL:&#x20;

    ```
    https://api.mollie.com/v2/payments/{id}
    ```

    &#x20;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:&#x20;
    * *status*
    * description
    * amount.value
    * amount.currency
  * The final setup should look like this:

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-cd3d44c2901abddd3b2b907c79b0ce18278b886e%2Fimage7.png?alt=media" alt=""><figcaption></figcaption></figure>

* * And the variables should look like the following:

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-22b031d8174f28de3ea8e21220bf6d72bbad844b%2Fimage12.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

* Done? Awesome! Now it's time to send the extracted information to the interested parties.

&#x20;

**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](https://dashboard.messagebird.com/en/channels) in the MessageBird Dashboard.[<br>](https://dashboard.messagebird.com/en/channels)

  <figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-7dec4f7b8ebc910d50c0327b6af7667e1418b138%2Fimage15.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

* To enable the WhatsApp sandbox, go to [this dedicated page](https://dashboard.messagebird.com/en/whatsapp/sandbox)

&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-ab5ac8651b274234f1a6696692b2f0665f611f21%2Fimage1.png?alt=media" alt=""><figcaption></figcaption></figure>

You can add Facebook Messenger, Line, WeChat, email, Telegram and Instagram as additional channels!&#x20;

&#x20;

**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.<br>

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.

&#x20;

**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:

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-82c67f40126c67d28a932b0338ae5594a6f4a6bd%2Fimage6.png?alt=media" alt=""><figcaption></figcaption></figure>

* The first **Send conversation message** configuration:

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-f93ec204bec4eac7cd34c4037f70b3e292d20729%2Fimage11.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-3440871537959d7359efd5f627c674baf8dd8ad8%2Fimage10.png?alt=media" alt=""><figcaption></figcaption></figure>

* The second **Send conversation message** configuration:

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-aef06f2317affa7d05abd90e2310645864c83aa8%2Fimage19.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-b589de9af9a7ca7a97fb33728c8c1459f378c89c%2Fimage16.png?alt=media" alt=""><figcaption></figcaption></figure>

#### &#x20;

**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).

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-28ed03a34babd8560cc3fdd669c9460f99ecd95c%2Fimage20.png?alt=media" alt=""><figcaption></figcaption></figure>

* The content of the **HTTP Request** step is a **POST** towards your existing webhook, with a JSON payload that contains the request ID.&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-c2b0f7791652847f8820d51b98475f432905022e%2Fimage18.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-01ef1e4e76c7f033972e18ebdc1451311ddaf3e1%2Fimage3.png?alt=media" alt=""><figcaption></figcaption></figure>

**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.

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-7151ec71443b73b4ea7138a7d90ff9c7700ed044%2Fimage4.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-3ce987d56b6361b994769406e1963187022cb54f%2Fimage5.png?alt=media" alt=""><figcaption></figcaption></figure>

**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.

&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-528a828329c0517f4a3b068d2003afd2c28f3c1b%2Fimage17.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;
