Invoice Automation: Tips, Tricks & API Examples (2023)

If you have a business, you need to handle invoices. And if you have an online business, you probably use Stripe for your payment infrastructure. By using Stripe in combination with Rowy, companies can use invoice automation to take control of their financial data to save time and costs.

Invoice automation uses software to streamline the invoicing process to fit your business needs. It includes tasks like creating invoices, sending payment requests, and generating reports. In this article, we will walk through the process of using Stripe and Rowy to automate various invoice-related tasks.

A study by Online Invoices declares that 54% of small and medium businesses expect late payments: by automating your invoice management system, you can reduce the risk of payment errors and late invoices―which in turn will result in reduced costs. This is particularly true for businesses that process a large number of invoices each month, but you'll also benefit from the added peace of mind if you're a freelancer with few clients: manual processes are more likely to create mistakes, so automation will help with accurate reporting and data handling.

How To Obtain Stripe API Keys

First, you will need a secret authentication key to use Stripe's API:

  1. Log in to your Stripe dashboard.
  2. Click on the "Developers" tab in the top menu.
  3. Click on "API keys" in the left-hand menu.
  4. Click on the "Create secret key" button.
  5. Enter a name for the new key.
  6. Click on "Create key" button.

You can now use your Stripe API keys to interact with Stripe from Rowy:

Stripe API key dashboard - 0.jpg

4 Features To Automate Invoices With Stripe

1. Creating A New Customer From Email

Having a CRM system in place to keep track of your customer information is an essential first step to automating your invoicing process. Stripe is great for that, but if you're using a spreadsheet or other manual system, you'll need to manually enter customer details into Stripe. Combining Stripe with Rowy to get the best of both worlds is a great alternative: you can use Stripe to process payments, and Rowy to manage customer data in a spreadsheet UI.

First, let's create a few columns in Rowy to store customer information:

  • An email column to store the customer's email address.
  • An address column to store the customer's address as a subtable with the fields city, country, line1, postal_code, and state.
  • A name column to store the company name.
  • A stripe_customer_id column to store the customer's ID created by Stripe.

All these columns are optional for Stripe's API, but they'll be necessary to create correct invoices.

Next, we create a new Action column to create a new customer in Stripe using an API call, with the following code in the Action settings:

const action:Action = async ({row,ref,db,storage,auth,actionParams,user,logging}) => {
  const res = await fetch('https://api.stripe.com/v1/customers', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${rowy.secrets.stripe_secret_key}` 
    },
    body: JSON.stringify({
      email: row.email,
      address: row.address,
      name: row.name
    })
  }).then(res => res.json())

  row.stripe_customer_id = res.id
}

You'll obtain the following table:

Rowy dashboard with a customer email column and an Action column - 1.jpg

Every time you add a new row and click the Action button, the script will run to create a new customer object in Stripe and return the customer's ID:

Stripe customer dashboard - 2.jpg

We can then use this customer ID to create new payments and invoices. You could for example create a new Stripe customer every time someone fills up your contact form on your website.

2. Auto-Generating Stripe Invoices

We can now use Stripe to automatically generate invoices. This can be done via API by specifying the customer id and individual invoice items with a specific amount. Stripe considers an invoice to be a collection of invoice items, and each invoice item has a price, quantity, and description.

First, we create a new sub-table to store our invoices:

Rowy invoice subtable - 9.jpg

Then, we add another sub-table inside the invoice sub-table to store each individual invoice items:

Rowy invoice item subtable - 10.jpg

We can now update the runInvoiceCustomer Action column in the invoices sub-table to create the Stripe invoice we can use to request payments from customers:

const invoice = await fetch('https://api.stripe.com/v1/invoices', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${rowy.secrets.stripe_secret_key}` 
  },
  body: JSON.stringify({
    customer: row.stripe_customer_id,
    description: row.description
  })
}).then(res => res.json())

row.stripe_invoice_id = invoice.id

const invoiceItems = row.invoice_items
const size = invoiceItems.length

for(let i = 0 ; i < size ; i++){
  const item = await fetch('https://api.stripe.com/v1/invoiceitems', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${rowy.secrets.stripe_secret_key}` 
    },
    body: JSON.stringify({
      customer: row.stripe_customer_id,
      amount: item.amount,
      description: item.description,
      currency: 'usd',
      invoice: invoice.id
    })
  }).then(item => item.json())

  row.invoiceitems[i].stripe_invoiceitem_id = item.id
}

This will create a new invoice object for the customer specified by the "customer" parameter and returns the invoice's ID:

Stripe invoice dashboard - 3.jpg

Once the invoice object is created, you can retrieve the invoice PDF, send a payment link, and more. Here is an example of an invoice as a PDF generated automatically by Stripe:

Stripe invoice PDF example - 4.jpg

It's also worth noting that you can use additional API methods to retrieve all the invoices of a customer or update them.

3. Automating Accounting Tasks With Stripe

We can use a Rowy Action column to automate accounting tasks using our invoice data like calculating totals or estimate taxes. For example, an action column to calculate the total amount of all invoices for a given customer:

const customer = row.stripe_customer_id
const invoices = row.invoices
const invoice_size = invoices.length
let total = 0

for(let i = 0 ; i < invoice_size ; i++){
  const invoice = invoices[i]
  const invoice_items = invoice.invoice_items
  const invoice_item_size = invoice_items.length

  for(let j = 0 ; j < invoice_item_size ; j++){
    const item = invoice_items[j]
    total += item.amount
  }

}

return total

This will retrieve all invoices and compute the total amount.

Of course, you can use custom logic to calculate the total amount of all invoices for a given month, or per quarter, for example―whatever you want to create your own custom invoice reports.

Action column in Rowy with aggregate total for accounting - 5.jpg

4. Sending Stripe payment requests

Last but not least, you can send payment requests from generated invoices with the click of a button using another Rowy action:

const isSent = await fetch(`https://api.stripe.com/v1/invoices/${row.stripe_invoice_id}/send`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${rowy.secrets.stripe_secret_key}` 
    }
  }).then(item => item.json())

if(isSent){
  row.is_sent = true
}

This Stripe API endpoint will send an email to the customer with a payment link:

Stripe payment email - 7.jpg

The payment link redirects the customer to Stripe's payment portal where they can pay the invoice in a secure user interface:

Stripe customer payment portal - 8.jpg

Join Rowy's Discord

In conclusion, Stripe and Rowy offer together a simple way to automate invoice processing, to save online businesses a significant amount of time and resources. After obtaining Stripe API keys, you can connect your Stripe account to Rowy via API and automate various invoice-related tasks like creating new customers, generating invoices, automating accounting tasks, and sending payment requests: a great way to streamline your business processes and focus on growth!

For more useful demos or to ask questions, join our Discord community. It's free, and we'll be happy to help you with your specific use cases.

Get started with Rowy in minutes

Continue reading

Browse all