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

  1. In sandbox mode, add a payment with card 4000000000007007 and amount 714.00 (insufficient funds).
  2. Catch the resulting HardDeclineException (e.g. by extending the gateway plugin) and call $exception->getPrevious().
  3. It returns NULL; BlueSnap's reason is only in the commerce_bluesnap log 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.

Command icon 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

jsacksick created an issue. See original summary.

  • jsacksick committed 9755d25e on 3.x
    feat: #3631291 Keep the BlueSnap API exception as the previous exception...
jsacksick’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.