Jump to content

JesusSuarz

Member
  • Posts

    93
  • Joined

  • Last visited

  • Days Won

    3

JesusSuarz last won the day on July 5 2022

JesusSuarz had the most liked content!

About JesusSuarz

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

JesusSuarz's Achievements

  1. In the next post I left a much more personalized way of doing it, https://whmcs.community/topic/333237-change-error-message-gateway-module/#comment-1408524 I made a reference to @steven99 answer, his answer was very helpful. Thanks
  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:
  3. In case anyone else is looking for an alternative way, this is the way I did it. $configuraciones = GatewaySetting::where('gateway', '=', 'YOUR_MODULE_NAME') ->whereIn('setting', ['public_key', 'private_key', 'testMode']) ->get(); // Inicializa las variables $apiKey = $privateKey = $testModeValue = null; // Itera sobre los resultados y asigna los valores foreach ($configuraciones as $configuracion) { if ($configuracion->setting == 'public_key') { $apiKey = $configuracion->value; } elseif ($configuracion->setting == 'private_key') { $privateKey = $configuracion->value; } elseif ($configuracion->setting == 'testMode') { $testModeValue = $configuracion->value; } } Then just use the variables: $apiKey $privateKey $testModeValue In my case I needed to find the apikey and privatekey data of my module because my hook had to consume these details.
  4. It worked perfectly for me, I didn't know this could be done. however, this appears to be undocumented within classes. https://classdocs.whmcs.com/8.9/WHMCS/Module_ns.html Would it be good to document it?
  5. Hello, I made another topic regarding this here: At first it worked fine, however for some unknown reason it stopped working. I do not know what to do now. 😞
  6. hi @leemahoney3 Can you help me with an answer on this topic? I was going to ask you privately, but it would be better to share it with everyone. I can't find how to solve this.
  7. 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!
  8. You are right, @leemahoney3 I have fixed the code and now it works. However, I am seeing that whmcs' local API functions cannot be used. this is normal? Apparently when using API functions the module stops working as it should.
  9. Hello, I hope you can assist me. I am currently developing a tokenised remote storage gateway module using the ePayco PHP SDK. (I intend to release it for free once completed). Here is some documentation on the matter: WHMCS Tokenised Remote Storage: https://developers.whmcs.com/payment-gateways/tokenised-remote-storage/ GitHub Documentation: https://github.com/WHMCS/developer-docs/blob/master/payment-gateways/tokenised-remote-storage.md WHMCS Example Token Gateway: https://github.com/WHMCS/sample-tokenisation-gateway-module/blob/master/modules/gateways/tokengateway.php ePayco PHP SDK: https://github.com/epayco/epayco-php ePayco API: https://api.epayco.co/#14ce0e39-2f4f-48bc-bb62-b4ef773fcb4b ePayco Credit Card Test: https://docs.epayco.com/docs/medios-de-pruebas-1 Here is my current code, followed by the issue I am encountering: <?php /** * WHMCS Sample Tokenisation Gateway Module * * This sample module demonstrates how to create a merchant gateway module * that accepts input of pay method data locally and then exchanges it for * a token that is stored locally for future billing attempts. * * As with all modules, within the module itself, all functions must be * prefixed with the module filename, followed by an underscore, and then * the function name. For this example file, the filename is "tokengateway" * and therefore all functions begin "tokengateway_". * * For more information, please refer to the online documentation. * * @see https://developers.whmcs.com/payment-gateways/ * * @copyright Copyright (c) WHMCS Limited 2019 * @license http://www.whmcs.com/license/ WHMCS Eula */ if (!defined("WHMCS")) { die("No se puede acceder a este archivo directamente"); } require 'epayco_tokenizacion/vendor/autoload.php'; use Epayco\Epayco; /** * Define module related meta data. * * Values returned here are used to determine module related capabilities and * settings. * * @see https://developers.whmcs.com/payment-gateways/meta-data-params/ * * @return array */ function epayco_tokenizacion_MetaData() { return [ 'DisplayName' => 'ePayco Tokenizacion', 'APIVersion' => '1.1', // Use API Version 1.1 ]; } /** * Define gateway configuration options. * * The fields you define here determine the configuration options that are * presented to administrator users when activating and configuring your * payment gateway module for use. * * Supported field types include: * * text * * password * * yesno * * dropdown * * radio * * textarea * * For more information, please refer to the online documentation. * * @see https://developers.whmcs.com/payment-gateways/configuration/ * * @return array */ function epayco_tokenizacion_config() { return [ 'FriendlyName' => [ 'Type' => 'System', 'Value' => 'ePayco Tokenizacion', ], 'publicKey' => [ 'FriendlyName' => 'Public Key (PUBLIC_KEY)', 'Type' => 'text', 'Size' => '32', 'Default' => '', 'Description' => '<br/>Corresponde a la llave de autenticación en el API Rest, Proporcionado en su panel de clientes en la opción Configuración > Personalización > Llaves secretas.', ], 'privateKey' => [ 'FriendlyName' => 'Private Key (PRIVATE_KEY)', 'Type' => 'text', 'Size' => '32', 'Default' => '', 'Description' => '<br/>Corresponde a la llave transacción de su cuenta, Proporcionado en su panel de clientes en la opción Configuración > Personalización > Llaves secretas.', ], // the yesno field type displays a single checkbox option 'testMode' => [ 'FriendlyName' => 'Modo de pruebas', 'Type' => 'yesno', 'Description' => 'Habilite para activar el modo de pruebas', ], ]; } /** * Store payment details. * * Called when a new pay method is added or an existing pay method is * requested to be updated or deleted. * * @param array $params Payment Gateway Module Parameters * * @see https://developers.whmcs.com/payment-gateways/tokenised-remote-storage/ * * @return array */ /** * Store remote card details. * * This function handles the tokenization of a credit card using ePayco API. * * @param array $params Payment gateway module parameters * @return array Result array containing status and possibly a token */ function epaycogateway_storeremote($params) { $apiKey = $params['publicKey']; $privateKey = $params['privateKey']; $testMode = $params['testMode']; $epayco = new Epayco( ['apiKey' => $apiKey, 'privateKey' => $privateKey, 'test' => $testMode] ); $action = $params['action']; $remoteGatewayToken = $params['gatewayid']; $cardType = $params['cardtype']; $cardNumber = "4575623182290326"; $cardExpiry = "1225"; $cardCvv = "123"; $firstName = $params['clientdetails']['firstname']; $lastName = $params['clientdetails']['lastname']; $email = $params['clientdetails']['email']; $address = $params['clientdetails']['address1'] . ' ' . $params['clientdetails']['address2']; $city = $params['clientdetails']['city']; $state = $params['clientdetails']['state']; $postcode = $params['clientdetails']['postcode']; $country = $params['clientdetails']['country']; $phone = $params['clientdetails']['phonenumber']; $epaycoToken = $response = null; switch ($action) { case 'create': try { $tokenResponse = $epayco->token->create([ 'card[number]' => $cardNumber, 'card[exp_month]' => substr($cardExpiry, 0, 2), 'card[exp_year]' => '20'. substr($cardExpiry, 2, 2), 'card[cvc]' => $cardCvv, 'hasCvv' => true, ]); $epaycoToken = $tokenResponse->id; $response = $epayco->customer->create([ 'token_card' => $epaycoToken, 'name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'address' => $address, 'city' => $city, 'state' => $state, 'country' => $country, 'phone' => $phone, 'postal_code' => $postcode, ]); } catch (Exception $e) { // Handle exceptions $response = [ 'error' => true, 'message' => $e->getMessage(), ]; } break; case 'update': // Handle updating break; case 'delete': // Handle deleting break; } return [ 'status' => $response['error'] ? 'error' : 'success', 'rawdata' => $response, 'gatewayid' => $epaycoToken, ]; } My problem: The token is created successfully in the payment gateway, and the customer is registered. However, when I try to make a transaction using a test card, I receive the following message: The following errors have occurred: The credit card details you entered were declined. Please try a different card or contact support. I am sending the card details because another issue I am facing is that the cardCvv is not being transmitted to the backend. I have checked all the WHMCS configurations but didn't notice anything unusual. I also created a PHP file to test the card and SDK, which works correctly, so I'm at a loss for what the problem might be. Does anyone have any insights on why I might be receiving this error? I am hopeful for your assistance, thank you.
  10. After doing this, my problem with disconnecting users was resolved. Thank you very much!
  11. this was the solution for me, disable database backup and use alternative method to extract my mysql backup and this solved my problem. Thank you very much!
  12. So to solve my problem, it occurred to me that the code is executed only if it is in the administration area or in the client area, and in this way it easily only executes for the client that is already registered. I will leave the code in case someone else needs it in the future: https://pastebin.com/xqd3pQEC Note that the value of the custom field must be set to "Required field" for a value to exist in the record and when edited "there is something to search the database or it may return null".
  13. hello. if I check the option "Administrators only" this will make the field disappear from the registration form. therefore I don't want it to disappear from the registration form. if not that the client "put the data in this field only the first time", but in the future or later only an administrator can edit it. hope now you understand the difference. on the hook, it works more or less well. (within the client and administrator area) However, if a new customer tries to register the following error appears: apparently the VALUE returns null. this is why you get an error in the registry.
  14. Could you help me with this issue?

     

  15. hello the code does not work. it seems that $vars['fieldid'] and $vars['relid'] are blank or null in $vars you can fix it?
×
×
  • 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