Tag the order and tell the team when a payment is disputed

Tag the order and alert the team when Stripe or PayPal opens a chargeback. A validated payment.disputed@1 definition.

When a customer disputes a payment with their bank, Stripe or PayPal tells Brainerce, and this automation tags the order disputed and tells the team at once with the provider, the reason and the amount. Trigger: payment.disputed@1. Actions: add_order_tags@1, notify_me@1 and send_internal_email@1.

It only tells you. Brainerce records the dispute: it moves no money, submits no evidence, issues no refund and does not change the order's status or payment status. You answer the dispute in your Stripe or PayPal account, and the evidence deadline is set there.

Model background: Automations.

The definition

{
  "schemaVersion": 1,
  "trigger": {
    "type": "payment.disputed@1",
    "origins": [
      "USER",
      "API",
      "MCP",
      "ASSISTANT",
      "BULK",
      "IMPORT",
      "DUPLICATE",
      "SYSTEM",
      "AUTOMATION"
    ]
  },
  "steps": [
    {
      "id": "tag",
      "type": "action",
      "contract": "add_order_tags@1",
      "input": {
        "orderId": { "$ref": "event.entityId" },
        "tags": ["disputed"]
      }
    },
    {
      "id": "tell",
      "type": "action",
      "contract": "notify_me@1",
      "input": {
        "title": "Dispute opened on order {{order.number}}",
        "message": "{{dispute.provider}} opened a dispute for {{dispute.amount}} {{dispute.currency}}. Reason: {{dispute.reasonCode}}. Answer it in the payment provider's own dashboard."
      }
    },
    {
      "id": "mail",
      "type": "action",
      "contract": "send_internal_email@1",
      "input": {
        "recipientUserIds": ["user_REPLACE_WITH_TEAM_MEMBER_ID"],
        "subject": "Dispute opened on order {{order.number}}",
        "body": "{{dispute.provider}} opened a dispute on order {{order.number}} for {{dispute.amount}} {{dispute.currency}}. Reason code: {{dispute.reasonCode}}. Brainerce only records the dispute. Answer it in the payment provider's own dashboard before the deadline it shows.",
        "includeEntityLink": true
      }
    }
  ]
}

Replace user_REPLACE_WITH_TEAM_MEMBER_ID with the id of a team member (1 to 5 user ids, never an email address). The notice goes to the people who manage automations in the dashboard; the email goes only to the people you name.

origins must include SYSTEM. Every dispute event is recorded with the origin SYSTEM, so a definition without it is refused with ORIGINS_INVALID instead of saving and never firing.

How it works

  • payment.disputed@1 fires once per dispute, when a payment provider first reports it as open on an order. A provider that sends the same dispute again does not run the automation twice.
  • Its facts are the order facts without the status transition, plus event.facts.dispute.provider (upper case: STRIPE, PAYPAL), .reasonCode, .amount (a number in major units of the currency, for example 12.34), .currency and .evidenceDueBy (an ISO date, or null when the provider gave no deadline).
  • A text may use the order variables plus {{dispute.provider}}, {{dispute.reasonCode}}, {{dispute.amount}} and {{dispute.currency}}. The evidence deadline is a fact, not a text variable.
  • The entity is the order, so the order actions, a wait and a condition after it are allowed, except cancel_order@1 and mark_order_shipped@1, which are refused here with ACTION_TRIGGER_UNSUPPORTED. Tagging the order is the safest first step.
  • To alert only on large disputes, add a trigger filter with a rule on event.facts.dispute.amount and one on event.facts.dispute.currency. The amount is in the dispute's own currency, so a threshold of 100 means 100 of that currency, not 100 of your store currency.
  • To act on one reason, filter on event.facts.dispute.reasonCode and list the codes of each provider. Stripe sends lower case codes such as fraudulent; PayPal sends upper case codes such as MERCHANDISE_OR_SERVICE_NOT_RECEIVED. A filter that names only one provider's spelling misses the other.
  • There is no status fact: a dispute is always open when this fires, and a rule on dispute.status is rejected.

What it does not do

  • Only Stripe and PayPal report disputes. Every other payment app reports none, so an order paid through another app never fires it. Do not read "no alert" as "no dispute".
  • It fires only when a dispute is opened. A dispute that is later won, lost or closed fires nothing yet, and a closed dispute never reopens. Stripe sends an inquiry (warning_needs_response) as open too, so an early inquiry fires it.
  • It does not submit evidence, accept the dispute, refund the order or cancel it. cancel_order@1 is refused under this trigger because a dispute opens on a captured payment, which a cancel never touches, and mark_order_shipped@1 is refused so that no automation ships goods against a chargeback. It does not move money and does not change the order's status or payment status.
  • It does not fire for a dispute on a payment that has no order (a donation, a customer payment link), for a Stripe payment saved under an older checkout id, or for a dispute reported before this feature was switched on. Those are not stored, and later reports are not filled in.
  • set_order_hold@1 works under this trigger, but it holds only an order that is still Pending or Processing. A paid order that already shipped is skipped with ORDER_NOT_HOLDABLE, so do not rely on a hold to stop a shipment.
  • The recipients of the team email must still be allowed to receive it at send time, or the run ends SKIPPED with NO_RECIPIENTS.

Create it

With the Admin MCP:

  1. get_automation_guide with topic: "triggers", then "messages".
  2. validate_automation_definition. Fix every finding.
  3. test_automation with entity: { "type": "Order", "id": "<an order id>" }. The test uses a sample dispute (provider SAMPLE, reason fraudulent, the order's own total and currency, no deadline), never a real one, and nothing is saved or sent.
  4. create_automation_draft with name: "Payment disputed".
  5. Tell the merchant to approve it in the dashboard.

With the SDK:

const check = await admin.validateAutomationDefinition(storeId, { definition });
if (!check.ok) throw new Error(JSON.stringify(check.errors));

const draft = await admin.createAutomation(storeId, {
  name: 'Payment disputed',
  definition,
});

What the merchant sees

A draft in Settings, then Automations. Once on, each new dispute tags the order disputed, sends a notice in the dashboard and an email to the people you chose, for example "Dispute opened on order 1042" with the provider, the amount and the reason code. The history shows one row per dispute.