JesusSuarz Posted March 23 Share Posted March 23 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. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted March 28 Share Posted March 28 If its tokenized then you should be using the _Capture method to take payment using the token. I don't see that in your code? 0 Quote Link to comment Share on other sites More sharing options...
JesusSuarz Posted March 29 Author Share Posted March 29 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. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted March 29 Share Posted March 29 I don't see why the localAPI wouldn't work. Do you have an example of the code? You can PM me if you want. 0 Quote Link to comment Share on other sites More sharing options...
JesusSuarz Posted March 30 Author Share Posted March 30 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. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted March 31 Share Posted March 31 Replied now 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.