InvoiceAhoy is an Invoice API that integrates with Medusa storefronts, allowing you to easily create, storage, and deliver invoices from your Medusa store. The InvoiceAhoy Medusa plugin enables you to easily plug invoiceahoy's API into a Medusa store to automatically create invoices for Medusa orders.
There is currently no easy way to create invoices for Medusa orders, and the only way to really achieve this is to either write your own plugin, or to go through the tedious task of creating an invoicing service and invoice templates.
The invoiceahoy plugin solves this problem by offering an easy API and SDKs to create and retrieve invoices. Invoices are encrypted and stored securely in the cloud, and you control access to the invoices using the API.
Here's a quick guide on installing and setting up the plugin to get you generating invoices in minutes.
Setting Up Invoicing for Your Medusa Storefront
This blog guides you through setting up the InvoiceAhoy Medusa plugin for your Medusa storefront to automatically create invoices for Medusa orders.
What you'll need
- You need to have an InvoiceAhoy account, you can start with a free plan to get going.
- A MedusaJS storefront.
The InvoiceAhoy Medusa Plugin
InvoiceAhoy has a plugin for Medusa that does all the heavy lifting of creating invoices for you.
The plugin listens for the order.payment_captured
event on the Medusa event bus and creates an invoice
when an order has been captured.
The plugin can be found here: https://github.com/invoiceahoy/medusa-plugin-invoiceahoy
Installing & configuring the plugin
1. Run the following command in the directory of the Medusa backend to install the plugin:
npm install medusa-plugin-invoiceahoy
2. Next, run the database migrations. This creates a new invoices
table in your Medusa schema that contains
the information about the invoices for your orders.
npx medusa migrations run
3. Next, set your InvoiceAhoy API key in your store's .env
file. You can retrieve your API key when you log into your
InvoiceAhoy account:
INVOICEAHOY_API_KEY=<YOUR_INVOICEAHOY_API_KEY>
4. Lastly, set your invoice options in the medusa-config.js
config file. Add the following at the end of the plugins
array:
const plugins = [
// ...
{
resolve: `medusa-plugin-invoiceahoy`,
options: {
logo_url: "https://invoiceahoy.com/ia_logo.svg", // the logo to add to the invoice
api_key: process.env.INVOICEAHOY_API_KEY, // required
},
},
]
The following options are available for the plugin:
api_key
Your unique InvoiceAhoy API keylogo_url
The URL to a logo image you want to add to the invoice
That's it! Your plugin is configured and the InvoiceAhoy
plugin for Medusa will be loaded the next time you start your Medusa backend.
Using the generated Invoice
The plugin is designed so that you can use any service to deliver the invoice.
After the invoice is created, a invoice.created
event is emitted on the Medusa event bus, containing the download links
for the generated invoice. You can use this event to download the invoice and attach it to the confirmation
email you send to the customer, or you can simply include the download link in the email.
The payload of the invoice.created
event contains the download information of the newly created invoice:
{
"id": "inv_2345678",
"download_pdf": "https://downloads.invoiceahoy.com/...",
"download_html": "https://downloads.invoiceahoy.com/...",
"doc_number": "386"
}
Conclusion
This blog post gives an overview of how to install and configure the Invoice Plugin for Medusa to enable automatic invoice creation for your Medusa orders. The plugin makes it easy to create invoices for your Medusa invoices.
Want to try it out?
Create a free account and start creating invoices in minutes.