Notify the team and offer a coupon when a payment fails
Tell the team when a card payment fails, wait an hour, re-check the shopper did not pay, then email a personal coupon. A validated payment.failed@1 definition.
When a payment on a checkout fails, tell the team at once, wait an hour, check the shopper did not retry and pay, then give them a personal coupon by email. Trigger: payment.failed@1. Steps: notify_me@1, wait, condition on a live value, create_customer_coupon@1, send_customer_email@1.
Model background: Automations.
The definition
{
"schemaVersion": 1,
"trigger": {
"type": "payment.failed@1",
"origins": [
"USER",
"API",
"MCP",
"ASSISTANT",
"BULK",
"IMPORT",
"DUPLICATE",
"SYSTEM",
"AUTOMATION"
],
"filter": {
"op": "all",
"rules": [
{
"path": "event.facts.payment.provider",
"op": "eq",
"value": "STRIPE"
},
{
"path": "event.facts.cart.subtotal",
"op": "gte",
"value": 50
}
]
}
},
"steps": [
{
"id": "tell",
"type": "action",
"contract": "notify_me@1",
"input": {
"title": "A payment failed on a cart of {{cart.subtotal}} {{cart.currency}}",
"message": "A payment on cart {{cart.id}} ({{cart.itemCount}} items) did not go through."
}
},
{
"id": "pause",
"type": "wait",
"duration": {
"amount": 1,
"unit": "hours"
}
},
{
"id": "not_paid",
"type": "condition",
"when": {
"op": "all",
"rules": [
{
"path": "current.cart.status",
"op": "neq",
"value": "CONVERTED"
}
]
},
"then": [
{
"id": "coupon",
"type": "action",
"contract": "create_customer_coupon@1",
"input": {
"customerId": {
"$ref": "event.facts.customer.id"
},
"type": "percent",
"value": 10,
"expiresInDays": 7
}
},
{
"id": "mail",
"type": "action",
"contract": "send_customer_email@1",
"input": {
"customerId": {
"$ref": "event.facts.customer.id"
},
"templateId": "TEMPLATE_ID",
"kind": "marketing",
"frequencyDays": 7
}
}
]
}
]
}Replace before saving:
STRIPE: the upper-case slug of the payment app (STRIPE,PAYPAL,GROW, and so on). Remove the rule to react to every app that reports failures.- The number
50: the smallest cart subtotal worth the effort, in the cart's own currency. TEMPLATE_ID: the id of a template in the store's campaign library that prints the coupon with{{coupon.code}}. The email always sends the template's latest version.percent,10andexpiresInDays(1 to 365): the coupon. It is single-use and only that customer can redeem it.
How it works
payment.failed@1fires once per failed payment attempt on a checkout. Its entity is the cart the checkout was started on, the same family ascheckout.abandoned@1, so a customer step acts on the cart's customer and the test runs on aCart.- Its facts:
event.facts.cart.id,.createdAt,.itemCount,.lineCount,.subtotal,.currency,.productIds(at most 250,.listsTruncatedsays when it was cut),.hasCoupon,.salesChannelId;event.facts.payment.provider(upper case, such asSTRIPE);event.facts.payment.reason(declined,authentication_failed,cancelled,errororunknown); andevent.facts.customer(null for a guest). The provider's own error message is never a fact. Most payment apps send only free text, so many failures readunknown: do not build a rule that needsdeclined. - A text may use
{{cart.id}},{{cart.itemCount}},{{cart.subtotal}},{{cart.currency}},{{customer.id}},{{customer.ordersCount}},{{payment.provider}}and{{payment.reason}}. - A shopper may fail and then pay within minutes. After a
waitthe facts are the old ones, so the condition tests the live valuecurrent.cart.statusneqCONVERTED: a cart that became an order readsCONVERTED, and the coupon and the email are skipped for that shopper. The condition has noelse, so a false result ends the runSUCCEEDEDwith the outcomeCONDITION_NOT_MET. A cart deleted meanwhile ends the runSKIPPEDwithCART_NOT_FOUND. - A guest who only typed an email at checkout has no customer. The team notice still goes out, but the coupon and the email are skipped for them, and a customer rule on the trigger is not met.
- The customer id is
{ "$ref": "event.facts.customer.id" }.
Which failures start it
Only payment apps that report a failure send it: Stripe, PayPal, Grow, Cardcom, iCredit, MAX, Takbull and Tranzila. Nedarim Plus (declines are ignored on purpose), Invoice4U and Morning report only successes. Sola has no webhook, so a decline reaches the automation only when the storefront's confirm step gets it. Do not tell a merchant that every failed payment triggers it.
What it does not do
- It does not fire for a failed attempt on a payment link, for a failed payment on an order that already exists as pending, for an amount mismatch or a "payment cannot be verified" check (those are integrity failures, not a decline), for a late failure report on a checkout that is already paid, or for a payment the provider is still processing.
- It does not send the shopper a "your payment failed" message of its own.
send_customer_email@1is a marketing email: it goes only to a customer who agreed to marketing emails, and never when they are suppressed (SUPPRESSED), have no address (NO_CUSTOMER_EMAIL), or already got one insidefrequencyDays(FREQUENCY_CAP). It needs a business postal address on the store (NO_POSTAL_ADDRESSotherwise). A coupon minted for a shopper who never agreed to marketing is minted all the same, but nobody emails it. - It does not conflict with the store's own abandoned-checkout recovery emails: the
RECOVERY_EMAIL_ACTIVErefusal applies tocheckout.abandoned@1only. A shopper can still get both a recovery email and this one. - It does not read the provider's error text, a card number, a name or an address. None of them is in the facts.
- It is the automation trigger. The outbound
payment.failedwebhook event is a different thing and is not changed by it.
Create it
With the Admin MCP:
get_automation_guidewithtopic: "triggers", then"live-values"and"messages".validate_automation_definition. Fix every finding.test_automationwithentity: { "type": "Cart", "id": "<a recent cart id>" }. The cart is tested as if its payment had just been declined by a sample provider, the wait is shown and never waited, and the condition is judged on today's value. Testing on a cart needs permission to view every order.create_automation_draftwithname: "Payment failed follow-up".- 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 failed follow-up',
definition,
});What the merchant sees
A draft in Settings, then Automations. Once on, each failed attempt that matches the filter starts a run: the notice arrives at once, the run shows WAITING for an hour, then ends SUCCEEDED (coupon created and email sent, or the shopper paid meanwhile) or SKIPPED with the reason code. A shopper who fails three times in a row starts three runs, one per attempt. The list's "Last 7 days" column counts them.
Abandoned cart reminder with a live check
Wait after a cart goes idle, re-check it is still abandoned, then email the shopper. A validated definition with a wait step and a live cart check.
Flag a return nobody answered
Wait 3 days after a return request, then notify the managers if it is still unanswered. A validated definition with a wait step and a live return check.