JesusSuarz Posted March 30 Share Posted March 30 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! 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted March 31 Share Posted March 31 Depends on the messages, that looks like a generic WHMCS one found in lang/english.php (or whatever language you use) $_LANG['remoteTransError'] = "Remote Transaction Failure. Please Contact Support."; If you want to change it, look into Language Overrides 0 Quote Link to comment Share on other sites More sharing options...
Solution JesusSuarz Posted April 2 Author Solution Share Posted April 2 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. Reference: 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.