Generate a report of orders that still require payment, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Generate a report of orders that still require payment

by Isaac Bowen (team@usemechanic.com)

This task generates a CSV spreadsheet, listing orders that are unpaid, partially paid, or pending payment. The resulting report is emailed to the recipient of your choice. Optionally, choose to have this report generated hourly, or daily.

Runs when a user triggers the task. Configuration includes include closed orders, recipient email address, email subject, email body, csv attachment filename, run hourly, and run daily.

15-day free trial – unlimited tasks

Documentation

This task generates a CSV spreadsheet, listing orders that are unpaid, partially paid, or pending payment. The resulting report is emailed to the recipient of your choice. Optionally, choose to have this report generated hourly, or daily.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

Events
when a user triggers the task (mechanic/user/trigger)
Options
include closed orders (boolean), recipient email address (email, required), email subject (required), email body (required, multiline), csv attachment filename (required), run hourly (boolean), run daily (boolean)
Script
{% assign orders = shop.orders %}

{% if options.include_closed_orders__boolean %}
  {% assign orders = orders.any %}
{% endif %}

{% assign orders_to_report = orders.unpaid | concat: orders.partially_paid | concat: orders.pending %}

{% if orders_to_report == empty and event.preview != true %}
  {% log "Zero orders found - skipping email. :)" %}
{% else %}
  {% assign rows = array %}
  {% assign header = array %}
  {% assign header[0] = "Order number" %}
  {% assign header[1] = "Date" %}
  {% assign header[2] = "Customer name" %}
  {% assign header[3] = "Order total" %}
  {% assign rows[0] = header %}

  {% for order in orders_to_report %}
    {% assign row = array %}
    {% assign row[0] = order.name %}
    {% assign row[1] = order.processed_at | date: "%F" %}
    {% assign row[2] = order.customer.first_name | append: " " | append: order.customer.last_name | strip %}
    {% assign row[3] = order.total_price | money_with_currency %}
    {% assign rows[rows.size] = row %}
  {% endfor %}

  {% action "email" %}
    {
      "to": {{ options.recipient_email_address__email_required | json }},
      "subject": {{ options.email_subject__required | json }},
      "body": {{ options.email_body__required_multiline | strip | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }},
      "attachments": {
        {{ options.csv_attachment_filename__required | replace: ".csv", "" | append: ".csv" | json }}: {{ rows | csv | json }}
      }
    }
  {% endaction %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Include closed orders
true
Email subject
Orders that require payment: {{ "now" | date: "%F" }}
Email body
Hello,

Please find the attached report. Thanks!

-Mechanic, for {{ shop.name }}
Csv attachment filename
orders-that-require-payment-{{ "now" | date: "%Y%m%d" }}.csv