Skip to content

How to automatically create invoices in Paypal with Integromat

Сценарий Integromat для выставления инвойсов. Paypal + Stripe

Updated: 08.04.2023

Invoices are convenient for everyone. The customer does not need to enter the amount and recipient email. All he has to do for payment is to log into Paypal and click on few buttons.

In this post, I will tell you how to create invoices in Paypal and receive money with Integromat. In my case, each order has a flex price, so I need to dynamically load the price into the invoice. I will use Trello as an example.

Registering the Paypal account

First, you need to register a Paypal account, on which you can accept the money (not for all countries it is available).

Then we need to go to https://developer.paypal.com/ and create a new app in Sandbox or Live mode. After creation, the Client ID and Consumer secret key will be generated for your app.

Создание приложения в Paypal
Creating an app in Paypal

Then you need to register Integromat account, if you are not registered yet.

Creating a scenario for Paypal invoicing

Let’s see how a scenario for invoicing looks like using the integration with Trello.

First we need to figure out what trigger we will use for generating the invoice. In my case, it’s moving the card to a certain list.

I can have 3 types of payment:

  1. Prepayment
  2. Middle payment
  3. Full payment.

For each of these types of payments will be different lists in Trello. But their meaning is the same and the scenarios are almost the same. Let’s take a look at the process of the prepayment scenario.

Сценарий Integromat для выставления инвойсов. Paypal + Stripe
Integromat scenario for invoicing. Paypal + Stripe. In this article, we only look at Paypal (this part of the scenario goes above)

Creating a Trigger in Trello

The trigger will be a webhook in the module Trello -> Watch activities (Instant). Select the board, list, and updateCard action.

Создание вебхука в Trello модуле
Creating a webhook in the Trello module

You can run just this module once and see if it triggers when you move a card to or from this list. If it does, go ahead.

Since this webhook can be triggered when we don’t need it, we put a filter on the listAfter variable so that the scenario will only work when the final list into which the card is moved is exactly the one we need.

Find out the list ID through a test run of the module or the source code of the Trello page and add the list ID to the filter right after the first module.

Фильтр по ID списка после перемещения карточки
Filter by list ID after moving a card

Retrieving data from Custom fields in Trello

If we use custom fields in a card, we have to take data from them. To do that, first, we add the module Trello -> Get a Card to get all the information about the card.

The data of the custom fields are in an array. You retrieve them and create variables from them, which will be used in the scenario. To get the data from the array, use the map() function.

  1. Add the Tools -> Set multiple variables module to set variables. I recommend creating a Set multiple variables module right away, as it will be easier to add more variables over time, as the scenario will grow and become more complicated.
  2. Find out the IDs of all your custom fields via the source code of Trello or look at the Get a Card module after its activation.
  3. Set a variable for each field you want to use in the scenario through the map() function.
Так выглядят мои поля в трелло
This is what Custom Fields look like in Trello

This is how the Set multiple variables module looks like to get custom fields from a card:

Set multiple variables Integromat
Set multiple variables module in Integromat

The knowledge base of how this function works and others can be found here – https://support.integromat.com/hc/en-us/articles/360001986513-Mapping

In brief, we:

  1. Specify the array in which to look for the key (Custom Fields).
  2. Setting the key and its type in raw format.
  3. Setting the key for the filter.
  4. Setting the filter value.
Функция map() в Integromat
map() function in Integromat

Once we have all the fields, we can continue scenario.

Create and configure module Paypal -> Create a payment (step 1)

Next, we create the module Paypal -> Create a payment (step 1). Add your Paypal account connection, using the Client ID and Consumer secret key from the developer area.

Настройка модуля Paypal -> Create payment
Setting up Paypal -> Create payment module

Description of the fields in this module:

  • Cancel URL – here we enter the URL to which the client will be redirected if he refused or there was a payment error. I recommend creating such a page on the website and filling its URL here.
  • Transaction – here you should create the transaction body: set amount for payment, currency, and description if needed. In the description, I recommend you insert the Trello card ID so after the payment you can identify the Trello card on which the payment was made. You can also add a template as a marker for your project (for example, if your account receives payments from different projects and you need to identify payments for your project).
  • Return URL – a URL where the data will be sent when the customer agrees to pay (clicks on the “Pay” button). This will be a webhook. Here we get to the module Paypal -> Execute payment (step 2).

Create and configure module Paypal -> Execute payment (step 2)

For the payment to go through, Paypal needs to send data that the client clicked on the payment button and agreed with withdrawal.

To do this, we will need to create a new scenario. Here’s what it will look like:

Сценарий Paypal -> Execute payment (step 2)
Scenario Paypal -> Execute payment (step 2)
  1. Create a scenario, create a webhook, copy its URL.
  2. Insert the copied URL into the module Paypal -> Create a payment (step 1) in the first scenario (Return URL). If needed, you can add additional parameters there via ampersand &.
  3. Now after the client confirms his intention to pay, our webhook will get a response with Payment ID and Payer ID.
  4. After webhook create Paypal -> Execute payment module (step 2) module, put Payment ID and Payer ID from webhook module into it.
  5. Next, optionally, after successful payment, you can add a redirect to the “Thank you for your payment” page. Create a page, add the Webhook response module and configure it.
Редирект после оплаты Paypal
Redirect after successful payment Paypal

Where:

  • Status: 302 – redirect code.
  • Key: key (Location).
  • Value: URL where to redirect.

Next, you can add an Email sending module to notify the customer of a successful payment and to thank them.


Now let’s go back to the first scenario. Once we have created the invoice (Paypal -> Create Payment) its result will be a unique link Approval URL, which the customer will have to go to and pay. This variable with the link can be sent to email, Telegram, or anywhere through the appropriate modules in the scenario. I send it in the body of the email along with the “Pay” button.

Avoid agent’s mistakes

The agent who will send the card to the invoice will make mistakes and sometimes leave certain fields blank. So you need to determine which fields are mandatory and add a filter to the scenario that will check if all fields are filled in.

Here’s what it looks like:

Проверка полей на заполненность в Integromat
Checking fields for emptiness in Integromat

After mapping all the fields from the Trello card in the Set multiple variables module, you create a router, and then one branch from it goes to the Telegram message (as a notification of error). There should be a filter in this branch. In this case, it checks mandatory fields, whether their variables empty or not. If at least one field matches emptyarray, i.e. empty, the scenario will pass this filter and send an error message to Telegram. The scenario will not go through the other branch (creating an invoice in Paypal).

In another branch that goes into the creation of the Paypal invoice, we check route type Fallback route which the scenario will continue to use if it cannot go through other branches (in our case, the branch that checks for errors).

So if there is at least 1 required field empty, the scenario goes to the Telegram error notification. If all fields are filled, the scenario goes into invoice link creation.

Examples of notifications in Telegram

Выставление инвойса
A message with an invoice
Comment in Trello card with an invoice
Comment in Trello card with an invoice
Оплата получена
Payment received
Необходимые поля не заполнены
Mandatory fields aren’t filled

In the screenshot above, when an error occurs, all required fields and their contents are displayed. The agent should see for itself where the empty field is.

To display only empty error fields, it is necessary to make the message markup a bit more complicated:

  1. Create a Set Multiple Variables module and use the if() function to determine which of the fields are empty.
  2. Combine the empty fields into one line with function split().
  3. Output the module result to the Telegram message body.
Вывод только ошибочных полей в сообщении
Output only erroneous fields in the message

In Telegram, it’s convenient that you can add a mention of an agent with an @. You can use the switch() function to do this. Or you can define each agent nickname in the Set Multiple Variables module beforehand and insert the variable in the message. I described this approach in more detail here.

The function switch() is simple:

  • Specify the variable to be checked:
  • If the value is A
  • Then result is B
  • If the value is A1
  • then the result is B1
  • and so on.
Упоминание менеджера через @ в сообщении Телеграм
Mentioning agent via @ in a Telegram message

This is the Paypal invoicing scenario. If you have any questions, ask in the comments. This scenario works perfectly. In the next article, I’ll tell you how to receive notifications of successful payment via Paypal, and what you can do with this data.

Leave a Reply

Your email address will not be published. Required fields are marked *