Mechanic Get Mechanic
Task library

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.

Try this task

When it runs

Occurs when a user manually triggers the task

What you choose

  • Include partially paid orders
  • Run daily
  • Hours to wait after midnight when running daily

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.

Task code and subscriptions

You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.

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
How task subscriptions work

Option types and flags

Task 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 %}
Mechanic Liquid reference

Default option values

Include partially paid orders
false
Run daily
false