Problem/Motivation
When a BlueSnap API call fails, the API clients catch the BluesnapApiException, log it, and throw a generic Commerce exception (e.g. HardDeclineException('We encountered an error processing your payment method...')) without passing the original exception along.
As a result, code that catches the decline (a custom gateway override, an event subscriber, etc.) has no way to read BlueSnap's actual reason, e.g. "302 - Insufficient funds. Please use another card or contact your bank for assistance". That reason only ends up in the logs. On our site, store staff wanted to see the decline reason on the order; we couldn't do that without patching the module.
This affects:
TransactionsClient::create(),::update()and::refund()AltTransactionsClient::create()SubscriptionsClient::create()and::update()VaultedShoppersClient: includes BlueSnap's message in the text, but doesn't pass the original exception either
Steps to reproduce
- In sandbox mode, add a payment with card
4000000000007007and amount714.00(insufficient funds). - Catch the resulting
HardDeclineException(e.g. by extending the gateway plugin) and call$exception->getPrevious(). - It returns
NULL; BlueSnap's reason is only in thecommerce_bluesnaplog entry.
Proposed resolution
Pass the caught exception as $previous wherever an API client re-throws, e.g.:
throw new HardDeclineException('We encountered an error processing your payment method. Please verify your details and try again.', 0, $e);Messages shown to customers don't change. Code that needs the reason can then use $exception->getPrevious()->getMessage().
Remaining tasks
- Review the MR.
API changes
None. The thrown exceptions now carry the original BluesnapApiException as their previous exception.
Issue fork commerce_bluesnap-3631291
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
jsacksick commented