Mechanic is a development and ecommerce automation platform for Shopify. :)
Stay on top of chargebacks and inquiries! Nightly or on-demand, this task will scan the last 60 days of your order records, and apply the tags of your choice to orders with chargeback or inquiry activity, based on what that activity looks like.
Runs Occurs when a user manually triggers the task and Occurs every day at midnight (in local time). Configuration includes tag for any, tag for accepted, tag for charge refunded, tag for lost, tag for needs response, tag for under review, and tag for won.
Stay on top of chargebacks and inquiries! Nightly or on-demand, this task will scan the last 60 days of your order records, and apply the tags of your choice to orders with chargeback or inquiry activity, based on what that activity looks like.
If you would like for the task to scan orders beyond 60 days, you can enable read all orders in your Mechanic settings.
Learn more about chargebacks in the Shopify documentation:
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?)
mechanic/user/trigger mechanic/scheduler/daily
{% assign tag_for_any = options.tag_for_any__required | strip %} {% assign statuses_and_tags = hash %} {% assign statuses_and_tags["ACCEPTED"] = options.tag_for_accepted__required | strip %} {% assign statuses_and_tags["CHARGE_REFUNDED"] = options.tag_for_charge_refunded__required | strip %} {% assign statuses_and_tags["LOST"] = options.tag_for_lost__required | strip %} {% assign statuses_and_tags["NEEDS_RESPONSE"] = options.tag_for_needs_response__required | strip %} {% assign statuses_and_tags["UNDER_REVIEW"] = options.tag_for_under_review__required | strip %} {% assign statuses_and_tags["WON"] = options.tag_for_won__required | strip %} {% assign status_tags = statuses_and_tags | values %} {% assign cursor = nil %} {% for n in (0..100) %} {% capture query %} query { orders ( first: 250 after: {{ cursor | json }} query:"chargeback_status:any" ) { pageInfo { hasNextPage } edges { cursor node { id disputes { initiatedAs status } tags } } } } {% endcapture %} {% assign result = query | shopify %} {% if event.preview %} {% capture result_json %} { "data": { "orders": { "edges": [ { "node": { "id": "gid://shopify/Order/1234567890", "legacyResourceId": "1234567890", "disputes": [ { "initiatedAs": "CHARGEBACK", "status": "NEEDS_RESPONSE" } ] } } ] } } } {% endcapture %} {% assign result = result_json | parse_json %} {% endif %} {% assign orders = result.data.orders.edges | map: "node" %} {% for order in orders %} {% assign tags_should_have = array %} {% assign tags_to_add = array %} {% assign tags_to_remove = array %} {% assign tags_should_have = tags_should_have | push: tag_for_any %} {% assign dispute_statuses = order.disputes | where: "initiatedAs", "CHARGEBACK" | map: "status" %} {% for dispute_status in dispute_statuses %} {% assign tags_should_have = tags_should_have | push: statuses_and_tags[dispute_status] %} {% endfor %} {% for status_tag in status_tags %} {% unless tags_should_have contains status_tag %} {% if order.tags contains status_tag %} {% assign tags_to_remove = tags_to_remove | push: status_tag %} {% endif %} {% endunless %} {% endfor %} {% for tag_should_have in tags_should_have %} {% unless order.tags contains tag_should_have %} {% assign tags_to_add = tags_to_add | push: tag_should_have %} {% endunless %} {% endfor %} {% log order_id: order.legacyResourceId, dispute_statuses: dispute_statuses, order_tags: order.tags, tags_should_have: tags_should_have, tags_to_add: tags_to_add, tags_to_remove: tags_to_remove %} {% if tags_to_add != blank or tags_to_remove != blank %} {% action "shopify" %} mutation { {% if tags_to_add != blank %} tagsAdd( id: {{ order.id | json }} tags: {{ tags_to_add | json }} ) { userErrors { field message } } {% endif %} {% if tags_to_remove != blank %} tagsRemove( id: {{ order.id | json }} tags: {{ tags_to_remove | json }} ) { userErrors { field message } } {% endif %} } {% endaction %} {% endif %} {% endfor %} {% if result.data.orders.pageInfo.hasNextPage %} {% assign cursor = result.data.orders.edges.last.cursor %} {% else %} {% break %} {% endif %} {% endfor %}
chargeback-any
chargeback-accepted
chargeback-refunded
chargeback-lost
chargeback-needs-response
chargeback-under-review
chargeback-won