Capture all authorized payments, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Capture all authorized payments

This task will scan for all orders that have a financial status of "authorized", and will capture payment for them. This task can be scheduled to run daily, and can be run on demand.

Runs Occurs when a user manually triggers the task. Configuration includes include partially paid orders, run daily, and hours to wait after midnight when running daily.

15-day free trial – unlimited tasks

Documentation

This task will scan for all orders that have a financial status of "authorized", and will capture payment for them. This task can be scheduled to run daily, and can be run on demand.

This task will scan for all orders that have a financial status of "authorized", and will capture payment for them. Enable "Run daily" to perform this every day at midnight, or use the "Run task" button to perform this scan on demand.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, 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.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
{% if options.run_daily__boolean %}mechanic/scheduler/daily{% if options.hours_to_wait_after_midnight_when_running_daily__number %}+{{ options.hours_to_wait_after_midnight_when_running_daily__number | times: 60 | round }}.minutes{% endif %}{% endif %}
mechanic/user/trigger
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
include partially paid orders (boolean), run daily (boolean), hours to wait after midnight when running daily (number)
Code
{% if event.preview %}
  {% action "shopify" %}
    mutation {
      orderCapture(
        input: {
          id: "gid://shopify/Order/1234567890"
          parentTransactionId: "gid://shopify/OrderTransaction/1234567890"
          amount: "10.00"
          currency: {{ shop.currency }}
        }
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% else %}
  {% assign cursor = nil %}
  {% assign conditions = array %}
  {% assign conditions[0] = "financial_status:authorized" %}

  {% if options.include_partially_paid_orders__boolean %}
    {% assign conditions[1] = "financial_status:partially_paid" %}
  {% endif %}

  {% for n in (0..100) %}
    {% capture query %}
      query {
        orders(
          first: 200
          after: {{ cursor | json }}
          query: {{ conditions | join: " OR " | json }}
        ) {
          pageInfo {
            hasNextPage
          }
          edges {
            cursor
            node {
              id
              transactions(
                capturable: true
              ) {
                id
                kind
              }
              totalCapturableSet {
                presentmentMoney {
                  amount
                  currencyCode
                }
              }
            }
          }
        }
      }
    {% endcapture %}

    {% assign result = query | shopify %}

    {% for edge in result.data.orders.edges %}
      {% assign transaction = edge.node.transactions | where: "kind", "AUTHORIZATION" | first %}

      {% action "shopify" %}
        mutation {
          orderCapture(
            input: {
              id: {{ edge.node.id | json }}
              parentTransactionId: {{ transaction.id | json }}
              amount: {{ edge.node.totalCapturableSet.presentmentMoney.amount | json }}
              currency: {{ edge.node.totalCapturableSet.presentmentMoney.currencyCode }}
            }
          ) {
            userErrors {
              field
              message
            }
          }
        }
      {% endaction %}
    {% endfor %}

    {% if result.data.pageInfo.hasNextPage %}
      {% assign cursor = result.data.orders.edges.last.cursor %}
    {% else %}
      {% break %}
    {% endif %}
  {% endfor %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more