Skip to content

ZES-88. Cancel order when Zip charge fails; bump version to 1.2.12 - #112

Merged
james-gornell merged 1 commit into
masterfrom
fix/ZES-88/cancel-order-on-charge-failure
Jul 13, 2026
Merged

ZES-88. Cancel order when Zip charge fails; bump version to 1.2.12#112
james-gornell merged 1 commit into
masterfrom
fix/ZES-88/cancel-order-on-charge-failure

Conversation

@alphadp

@alphadp alphadp commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

A client reported an order created in Magento as pending with no matching successful charge. Zip logged AccountAdapterException: This account is locked ... cannot be charged (HTTP 402). The order (YW121519810) was placed, the charge failed, but the order stayed pending.

Root cause

In Model/Charge::charge() the catch guard was:

if (!$e instanceof ApiException || !$e instanceof LocalizedException) {
    $this->_logger->alert($errorMessage);
    throw $e;
}

An exception can never be both types, so at least one !instanceof is always true - the guard is always true - the method logged ALERT: Unexpected behavior .[402] ... and rethrew before reaching cancelOrder(). The order was never cancelled.

Fix

  • Model/Charge.php: || -> &&. Genuinely-unexpected exceptions are rethrown as-is, while ApiException/LocalizedException fall through to charge cancellation + order cancellation. This resolves the incident.
  • Helper/Data::handleException(): returned an imploded string while all five callers (Charge, Token, TransactionCancel/Capture/Refund) destructure it via list($apiError, $message, $logMessage) - they were all silently getting null. Restored the array return so the correct decline message reaches the customer and logs.
  • Bumped version 1.2.11 -> 1.2.12 (composer.json, etc/module.xml) and added CHANGELOG.md.

@alphadp
alphadp force-pushed the fix/ZES-88/cancel-order-on-charge-failure branch from c549cd5 to c92a16b Compare July 8, 2026 15:00
Do not leave a pending order in Magento when the charge cannot be completed.

- Model/Charge::charge(): fix the always-true catch guard (|| -> &&) so that a
  failed charge (e.g. HTTP 402 "account is locked") reaches cancelOrder() instead
  of rethrowing early and leaving the order as 'pending'.
- Helper/Data::handleException(): return the [apiError, message, logMessage] array
  again (it had been imploded into a string), so the list() destructuring in all
  five call sites works and the decline message reaches the customer and logs.
- Bump version to 1.2.12 (composer.json, etc/module.xml) and add CHANGELOG.md.
@alphadp
alphadp force-pushed the fix/ZES-88/cancel-order-on-charge-failure branch from c92a16b to eefe0e8 Compare July 8, 2026 15:18
@james-gornell
james-gornell merged commit 3004730 into master Jul 13, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants