Support » Plugin: Eway Payment Gateway » Suggested way to handle customisation of errors?

  • Whenever the WooCommerce transaction fails, this plugin generates an error notice like this:

    > Transaction failed
    > (D4465)

    I had a dig around for a filter to hopefully make these a bit more customer friendly. There seems to be a lot of infrastructure for more detailed messages (i.e. EwayResponse::getCodeDescription), but I can’t see that any of it is hooked up. I also can’t seen an obvious filter point.

    Is there a recommended approach to customising these?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author webaware


    G’day jaydisc,

    It’s hooked up alright, but that code in particular is not handled — Eway doesn’t map it to a friendly description. That’s because it usually is the result of a bad card number attempt, and giving a friendly description to someone testing out card numbers isn’t seen as useful.

    But you can hook eway_code_description to change (supply!) a friendly message if you wish. It takes two parameters, $msg and $code.


    Thread Starter jaydisc


    Sorry, that was a bad example. I also get the same outcome with any code, currently ‘D4460’. I’ve added a filter:

    add_filter('eway_code_description', 'custom_eway_code_description', 10, 2);
    function custom_eway_code_description($msg, $code)
    	return $msg;

    But that isn’t getting invoked either.

    I can see that in class.WooCommerce.php, that $response->getErrorMessage is called ~ line 621 to set that error message:

    $error_msg = $response->getErrorMessage(esc_html__('Transaction failed', 'eway-payment-gateway'));

    When I look at EwayResponse::getErrorMessage, I don’t see any reference to getCodeDescription(), which is what seems to offer nicer messages as well as your hook point. It just grabs $this->Errors and $this->ResponseMessage (where eWay’s code is), and returns them imploded over <br>’s.

    Thread Starter jaydisc


    Maybe I should be trying this with v5?

    Thread Starter jaydisc


    Actually, I think I just found the issue. In getErrorMessage($error_msg), for some reason you’re only showing the array_keys() for the ResponseMessages:

    $errors[] = ' (' . esc_html(implode(',', array_keys($this->ResponseMessage))) . ')';

    If I remove that, I get the expected results:

    $errors[] = ' (' . esc_html(implode(',', $this->ResponseMessage)) . ')';

    Plugin Author webaware


    Ah, yes. I remember now. Codes only, for what you can see in a browser, again to stop giving information to card testers.

    I’ve just added a filter hook so that you can change that if you prefer. Download the 5.0.0-dev again (or grab from GH).

    The new filter hook is woocommerce_eway_error_msg and it passes $error_msg and $response. If you call the following, you’ll get the detailed message as written to the log:


    However, be mindful of giving card testers too much help!


    • This reply was modified 4 days, 8 hours ago by webaware. Reason: spelnig
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.