Cancel rules
Automatically void authorized transactions that meet conditions you define, before the payment settles.
Cancel rules let you automatically void transactions after the card network authorizes them but before settlement. When a transaction matches a cancel rule's conditions, Pay.com voids the authorization and returns a configurable failure message.
How cancel rules differ from payment rules
Payment rules fire before authorization, so the charge never reaches the card network. Cancel rules fire after authorization. The card network approves the funds first, and then Pay.com voids the authorization.
| Payment rule (Block) | Cancel rule | |
|---|---|---|
| Fires | Before the card network | After the card network authorizes |
underlying_network_details | null (charge never sent) | Populated (authorization occurred) |
decline_code | blocked_by_risk_rule | cancelled_by_risk |
| Applies to | Charges, holds | Charges, holds |
Use a cancel rule when the condition you want to evaluate is only meaningful after an authorization has been issued. Use a payment rule with the Block action if you want to prevent the charge from reaching the card network entirely.
When cancel rules fire
Cancel rules evaluate after authorization. The exact moment depends on the transaction type:
| Transaction type | When the cancel rule fires |
|---|---|
| Hold | At POST /v1/holds, after the card network authorizes the hold |
| Direct charge | At POST /v1/charges, after authorization but before capture |
| Charge with 3D Secure | At POST /v1/charges/{id}/confirm, after the customer completes the 3DS challenge |
For direct charges, Pay.com processes authorization and capture as two internal steps. The cancel rule runs between them. Neither you nor your customer sees this intermediate state.
Cancel rules also apply to off-session charges and holds, created with
off_session: true. Unlike payment rules, they have no setting to skip these
recurring transactions.
Conditions
Cancel rules evaluate the same fields as payment rules, plus the results the card network returns: the AVS and CVV checks, the 3D Secure result, and the Account Name Inquiry result. They can also read Matched payment rule. For each condition, choose a Field, an Operator, and a Value. For the complete list of fields and operators, see Rule conditions and operators.
The cancel rules page
Go to Rules → Cancel in the Pay.com dashboard to access cancel rules. The page has three tabs:
- Rules: lists all your cancel rules. Each rule shows its current state (Enabled or Disabled). From here you can toggle a rule on or off, open it, or edit, duplicate, or delete it.
- Logs: shows the transactions your cancel rules evaluated, and whether each rule matched.
- Audit Log: shows who created, changed, or deleted each rule.
Like payment rules, cancel rules have a Simulation Mode, which logs matches without voiding the transaction.
Create a cancel rule
Create the rule in the Pay.com dashboard's rule builder. It's enabled as soon as you save it.
- 1
Open the rule builder
In Rules → Cancel, click Create new rule.
Give the rule a descriptive name so you can identify it later.
- 2
Configure the logic
Define the conditions the rule evaluates on each transaction. For each condition, choose a Field, an Operator, and a Value.
You can combine multiple conditions using AND (all conditions must be true) or OR (any condition must be true).
To match against a set of values, choose the is in list operator and select a risk list you've already created.
- 3
Set the failure message
Enter the message returned in
failure_messagewhen the rule cancels a transaction. This message appears on the hold or charge record and is visible to you via the API. - 4
Save the rule
Click Confirm & Save Rule. The rule is enabled immediately.
Cancel rule outcome
When a cancel rule matches, the API returns an error response with
decline_code: "cancelled_by_risk". The hold or charge object is still
created with status: "failed". Retrieve it with the ID in the error
object to inspect the full record, including risk_assessment_details.
Hold canceled by a rule
In this example, a rule with the condition first name equals TestCancel
cancels a hold. Amounts are in the currency's smallest unit, so 1000 is
$10.00 USD. The request sends raw card details, which require an API key
enabled for raw card data. See
PCI compliant keys.
{
"amount": 1000,
"currency": "usd",
"source_data": {
"type": "card",
"card": {
"number": "4242424242424242",
"expiry_month": "12",
"expiry_year": "2028",
"cvv": "123",
"name": "TestCancel User"
},
"billing_details": {
"name": "TestCancel User",
"email": "customer@example.com",
"address": {
"line1": "100 Test St",
"city": "New York",
"state": "NY",
"postal_code": "10001",
"country": "US"
}
}
},
"payment_method_options": {
"card": {
"duplicate_card_check": false
}
},
"description": "Hold with cancel rule condition"
}{
"error": {
"type": "payment_method_error",
"code": "card_declined",
"decline_code": "cancelled_by_risk",
"message": "Test cancel rule",
"hold": "hld_701530028785011712",
"payment_method": "pm_card_701530039697956864",
"underlying_network_details": {
"network": "visa",
"visa": {
"auth_code": "140541"
}
}
}
}The hold object is still created. Retrieve it with the ID in error.hold:
GET /v1/holds/hld_701530028785011712{
"id": "hld_701530028785011712",
"status": "failed",
"failure_code": "cancelled_by_risk",
"failure_message": "Test cancel rule",
"risk_assessment_details": {
"outcome_source": "rule",
"rule_id": "rl_700293741725877248",
"flags": [],
"bypassed": []
},
"underlying_network_details": {
"network": "visa",
"visa": {
"auth_code": "140541"
}
}
}Direct charge canceled by a rule
Direct charges created with
POST /v1/charges follow the
same structure, with two differences:
- The error response returns
error.charge(such as"chrg_701530061018236928") instead oferror.hold. - Retrieve the failed charge record from
GET /v1/charges/{charge_id}to readfailure_code,failure_message,risk_assessment_details, andunderlying_network_details.
On any canceled hold or charge:
underlying_network_detailsis populated and includes anauth_code. The authorization reached the card network and was approved before the cancel rule voided it.risk_assessment_detailscontainsoutcome_source: "rule"and therule_idof the matched rule. Unlike payment rule outcomes, there is nooutcomefield.- The hold or charge object is still created and retrievable. Use the ID in
error.holdorerror.chargeto fetch it.
Next steps
- Payment rules: Block charges or enforce 3DS before they reach the card network.
- Review rules: Flag transactions or customers for manual review after authorization.
- Risk lists: Create named collections of values to use in rule conditions.
- Test your rules: Verify that rules fire correctly using test transactions.