Jump to content

change error message (gateway module)


Go to solution Solved by JesusSuarz,

Recommended Posts

Hello everyone,

I'm in the final stages of developing a custom payment module for WHMCS, where I'm leveraging the platform's tokenization capabilities. So far, the process has been relatively smooth, and I'm close to completing the module. However, I've encountered a specific challenge related to customizing error messages.

During my testing, I've noticed that WHMCS uses the $vars['errormessage'] variable to store and display error messages that arise during payment transactions. Here's a typical example of the responses I'm dealing with:
 

$vars['errormessage'] = "Default WHMCS error message here.";

I remember customizing these error messages in past projects, adjusting them to be more specific to the context of my module, but unfortunately, I can't recall how I achieved it.

My questions are as follows:

Is it possible to intercept and modify these error messages programmatically within the payment module I'm developing?
If so, could someone guide me on the best approach or provide a snippet of example code that demonstrates how to achieve this customization?
Any guidance or advice will be greatly appreciated, especially if you have experience working with tokenization in WHMCS or customizing error messages within payment modules.

Thank you in advance for your time and help!

 

Screenshot_101.png

Link to comment
Share on other sites

  • Solution

The best way to achieve this is by creating a hook with a session variable.

$_SESSION['form_submitted'] = true;
add_hook('ClientAreaPage', 1, function ($vars) {
    if (isset($_SESSION['form_submitted']) && $_SESSION['form_submitted'] === true) {
        // Asegurarse de que la lógica para establecer $_SESSION['gateway_error'] se maneje adecuadamente en el envío del formulario
        if (isset($_SESSION['gateway_error'])) {
            $errorMsg = $_SESSION['gateway_error'];
            unset($_SESSION['gateway_error']); // Limpia el mensaje de error
            unset($_SESSION['form_submitted']); // Importante: limpia también el indicador de envío de formulario
            return array('errormessage' => $errorMsg);
        }
        // Limpia el indicador si no hay errores para este envío de formulario
        unset($_SESSION['form_submitted']);
    }
    // En caso de recarga de página sin envío de formulario, no hacer nada
});

if ($_SESSION['gateway_error']) {
//then in the return of the response, add the following
 $_SESSION['gateway_error'] = 'Error: my custom error.';
}

this way I was able to get my own custom error.

In this case, I made my error come directly from the API epayco. passing the response to the session variable.

image.png.868f6e168686cda3af818e2bbb5bf277.png

Reference: 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated