Skip to content

How to automatically create invoices in Stripe with Integromat

How to automatically create invoices in Stripe with Integromat

Updated: 19.09.2021

In this article, I will show you how to create invoices in Stripe automatically. Stripe is needed for accepting payments from plastic (regular bank cards) or transfers from bank accounts. Of course, you’ll need a registered account in Stripe and a linked bank account to withdraw money.

We will use Trello and the scenario I described here.

Thus, in one scenario will be implemented invoicing with Paypal and Stripe at once. Stripe is needed for those who are not comfortable paying with Paypal and just need to enter the card or send money from a bank account.

So, here’s what the scenario looks like:

Full scenario with invoicing from Trello card
Full scenario with invoicing from Trello card

As you can see, there are quite a few Stripe modules here, this is because it has a slightly different invoicing scheme than Paypal.

If you don’t have Integromat yet, register now.

Determining the workflow in Trello

As you remember from the article about invoices in Paypal, in my case invoices are created when the agent moves the card to a column. By default, the invoice is creating in Paypal. For the invoice to be invoiced in Stripe, you have to come up with a condition.

In my case, the condition is the Label in the Trello card. The label is called “Stripe“. That is, before moving the card, the agent should set the label to create an invoice in Stripe.

Stripe label in Trello card
Stripe label in Trello card

Editing the scenario in Integromat

Next, we need to edit the scenario in Integromat. We add a router before the Paypal module, add a new branch to it, which will lead to the invoicing in Stripe. The branch in Paypal can be marked immediately as Fallback route.

In the Stripe branch put a filter that will check labels, so that labels should contain Stripe label id. This is done using the map() function. We need to know our label id through Trello source code or from retrieving data about sample card with module Trello -> Get a Card.

Checking for Stripe label in Trello card
Checking for Stripe label in Trello card

A description of how the map() function works and others can be found here — https://support.integromat.com/hc/en-us/articles/360001986513-Mapping

Other examples of how to use this function are here — How to automatically create invoices in Paypal with Integromat

Invoicing in Stripe step by step

Next, in my scenario comes the router again, I’ll explain why later. For now, add Stripe -> Make an API Call and add an account (you’ll need an API key for this, you’ll find it in your account).

Yes, we’ll have to make an API call, there’s nothing in the module that’s ready for us. Fortunately, Stripe has great documentation.

UPDATE: at the time of writing this article, Integromat added ready modules, so you can use them. It’s easier and faster.

The principle of invoice creation is the same:

  1. Create customer.
  2. Create invoice item.
  3. Create an invoice and include invoice item(s).
  4. Finalize the draft invoice so it can be sent.

Below I will describe how I did it via API queries.

Creating a client

The first thing to do is to create a client. In the module Stripe -> Make an API Call we fill the following fields:

  • URL: /v1/customers
  • Method: always will be POST
  • Body: Here we need the client’s name and email. It can be extracted from the Trello card with the help of the module Set variables.

Here’s what the module looks like with the fields filled in:

Creating a client in Stripe
Creating a client in Stripe

The rest of the fields are untouched.

Creating Invoice Item

An item of an invoice is part of the whole invoice. This is useful when you need to add more than one part to an invoice. In my case, it’s always one item, but you still need to create it before creating the invoice itself.

Copy the previous Stripe module and fill in the fields:

  • URL: /v1/invoiceitems
  • Body: customer=45.body.id&amount=Prepayment field* 100&currency=eur

Let me explain about Body: Customer is a variable with customer ID from the previous module (it needs to be run once so that at least one customer is created). Amount – the amount in cents for invoice part, I immediately multiply by 100. Currency: currency.

Here is how the module looks like when the fields are filled:

Creating invoice item in Stripe
Creating invoice item in Stripe

Again, the amount can be extracted from the custom field in Trello.

Creating invoice

After generating an invoice item, you can include it in the main invoice and create it.

Copy the previous Stripe module and fill in the fields:

  • URL: /v1/invoices
  • Body: customer=45.body.id&auto_advance=false&collection_method=send_invoice&days_until_due=60&description=Order number:{{14.idShort}}

Where Customer – customer ID, which we created in the first module, auto_advance is turned off to “manage invoice statuses itself”, more details here – https://stripe.com/docs/billing/invoices/overview#auto_advance, collection_method is set to send_invoice, days_until_due – days, how long the invoice lives until payment, description – something you want to insert in the invoice description, for example, order number from Trello.

This is what the module looks like with the fields filled in:

Creating an invoice in Stripe
Creating an invoice in Stripe

Finalizing Invoice

After this procedure, the invoice will switch from draft status to “open” and the customer can pay for it.

Copy the previous Stripe module and fill in the fields:

  • URL: /v1/invoices/{{48.body.id}}/finalize
  • Body: auto_advance=false

Where {{48.body.id}} – invoice ID from previous module.

Here’s what the module looks like with the fields filled in:

Opening an invoice for payment in Stripe
Opening an invoice for payment in Stripe

The result of the work of this module will be a ready URL with an invoice, the so-called hosted invoice. Here are more details https://stripe.com/docs/billing/invoices/hosted.

You can send the URL yourself in the email or let Stripe do it.

Sending an invoice to agent and customer

What you can do next?

  1. Send a firm email with the invoice URL to the customer.
  2. Send notification to Telegram.
  3. Record the customer’s ID in the appropriate line of Google Sheets.
  4. Post a comment to the Trello card.

All these points you can do with the help of the appropriate modules.

Here’s what the comment looks like in the Trello (in this case an invoice from Paypal):

Comment in Trello with Paypal invoice
Comment in Trello with Paypal invoice

If there’s already a client in Stripe

If the order has several payments, then it is logical for invoices to be created for one client, instead of creating a new client each time.

For this, let’s refine the scenario:

  1. Before the first module Stripe with client creation, we place the router.
  2. Seet the branch with the client creation as a fallback route.
  3. In the new branch, we put a filter that checks the client’s ID in the custom field in the Trello card. (You can write the client’s ID in this field after the client creation).
  4. If the filter finds that the client’s ID exists, the scenario will go to this branch. Then we just duplicate all the same Stripe modules, except the Stripe module with client creation.
Creating a Stripe invoice for an existing customer
Creating a Stripe invoice for an existing customer

That’s basically the whole scenario. If you have any questions, feel free to ask. In the next article, I’ll show you how to monitor payments, refunds, and failed payments in Stripe.

Leave a Reply

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