• Resolved jaydisc

    (@jaydisc)


    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 6 replies - 1 through 6 (of 6 total)
  • Plugin Author webaware

    (@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.

    cheers,
    Ross

    Thread Starter jaydisc

    (@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)
    {
    	echo($msg);
    	echo($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

    (@jaydisc)

    Maybe I should be trying this with v5?

    Thread Starter jaydisc

    (@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

    (@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).

    https://www.dropbox.com/s/ghdjeyaouf8ibn1/eway-payment-gateway-5.0.0-dev.zip?dl=1

    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:

    $response->getErrorsForLog()

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

    cheers,
    Ross

    • This reply was modified 2 years ago by webaware. Reason: spelnig
    Thread Starter jaydisc

    (@jaydisc)

    Ah, that’s perfect (woocommerce_eway_error_msg). Thank you. I will wait the release of v5 before implementing that, and yes, I will keep the error message very generic. Unfortunately, my site has to use guest checkout, so card testing is a major concern.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Suggested way to handle customisation of errors?’ is closed to new replies.