diff --git a/modules/gateways/callback/xendit.php b/modules/gateways/callback/xendit.php index 5df5da0..9fcc265 100644 --- a/modules/gateways/callback/xendit.php +++ b/modules/gateways/callback/xendit.php @@ -5,7 +5,7 @@ require_once __DIR__ . '/../xendit/autoload.php'; use Xendit\Lib\Callback; -use Xendit\lib\CreditCard; +use Xendit\Lib\CreditCard; use Xendit\Lib\XenditRequest; $callback = new Callback(); @@ -20,18 +20,18 @@ // Create/Update credit card if ($action == 'updatecc' || $action == "createcc") { /* - * Make sure the 3DS authentication status = 1 + * Make sure the CC authentication status = 1 * That mean the CC token is valid to create the charge */ -// if(!isset($postData['xendit_3ds_authentication_status']) || $postData['xendit_3ds_authentication_status'] == 0){ -// logTransaction($gatewayParams['paymentmethod'], $postData, "3DS authentication failed"); -// $creditCard->renderJson( -// [ -// 'error' => true, -// 'message' => '3DS authentication failed.', -// ] -// ); -// } + if (!isset($postData['xendit_cc_authentication_status']) || $postData['xendit_cc_authentication_status'] == 0) { + logTransaction($gatewayParams['paymentmethod'], $postData, "CC authentication failed"); + $creditCard->renderJson( + [ + 'error' => true, + 'message' => 'CC authentication failed.', + ] + ); + } /* * Make sure the credit card info has value @@ -70,7 +70,7 @@ $creditCard->renderJson( [ 'error' => true, - 'message' => 'Invalid Hash', + 'message' => 'Invalid.', ] ); } diff --git a/modules/gateways/xendit.php b/modules/gateways/xendit.php index f9e657f..70f9776 100644 --- a/modules/gateways/xendit.php +++ b/modules/gateways/xendit.php @@ -10,10 +10,11 @@ require __DIR__ . '/xendit/autoload.php'; // defines -define('XENDIT_PAYMENT_GATEWAY_VERSION', '1.0.6'); +define('XENDIT_PAYMENT_GATEWAY_VERSION', '1.0.7'); use WHMCS\Billing\Invoice; use Xendit\Lib\ActionBase; +use Xendit\Lib\CreditCard; use Xendit\Lib\Link; use Xendit\Lib\Model\XenditTransaction; use Xendit\Lib\Recurring; @@ -118,7 +119,7 @@ function xendit_capture($params) } // Generate payload - $cc = new \Xendit\Lib\CreditCard(); + $cc = new CreditCard(); $payload = $cc->generateCCPaymentRequest($params); try { @@ -195,13 +196,14 @@ function xendit_remoteinput($params) $secretKey = $params['xenditTestMode'] == 'on' ? $params['xenditTestSecretKey'] : $params['xenditSecretKey']; $xenditRequest = new XenditRequest(); + $creditCard = new CreditCard(); // Card settings try { $cardSettings = $xenditRequest->getCardSettings(); $canUseDynamic3ds = $cardSettings['can_use_dynamic_3ds'] ?? 0; } catch (\Exception $e) { - return (new ActionBase)->errorMessage($e->getMessage()); + return $creditCard->errorMessage($e->getMessage()); } // Client Parameters @@ -228,7 +230,7 @@ function xendit_remoteinput($params) 'return_url' => $systemUrl . 'modules/gateways/callback/xendit.php', 'payment_method_url' => $systemUrl . 'index.php?rp=/account/paymentmethods', 'can_use_dynamic_3ds' => $canUseDynamic3ds, - 'verification_hash' => sha1( + 'verification_hash' => $creditCard->generateHash( implode('|', [ $publicKey, $clientId, @@ -286,6 +288,7 @@ function xendit_remoteupdate($params) } $xenditRequest = new XenditRequest(); + $creditCard = new CreditCard(); // Gateway Configuration Parameters $publicKey = $xenditRequest->getPublicKey(); @@ -297,7 +300,7 @@ function xendit_remoteupdate($params) $cardSettings = $xenditRequest->getCardSettings(); $canUseDynamic3ds = $cardSettings['can_use_dynamic_3ds'] ?? 0; } catch (\Exception $e) { - return (new ActionBase)->errorMessage($e->getMessage()); + return $creditCard->errorMessage($e->getMessage()); } // Client Parameters @@ -327,7 +330,7 @@ function xendit_remoteupdate($params) 'return_url' => $systemUrl . 'modules/gateways/callback/xendit.php', 'payment_method_url' => $systemUrl . 'index.php?rp=/account/paymentmethods', 'can_use_dynamic_3ds' => $canUseDynamic3ds, - 'verification_hash' => sha1( + 'verification_hash' => $creditCard->generateHash( implode('|', [ $publicKey, $clientId, diff --git a/modules/gateways/xendit/assets/js/xendit.js b/modules/gateways/xendit/assets/js/xendit.js index 04b982e..5d3304a 100644 --- a/modules/gateways/xendit/assets/js/xendit.js +++ b/modules/gateways/xendit/assets/js/xendit.js @@ -75,7 +75,7 @@ jQuery(function ($) { if (typeof err != 'undefined') { failure_reason = err.message || err.error_code; } else { - failure_reason = 'We encountered an issue while processing the checkout. Please contact us. Code: 200035'; + failure_reason = 'We encountered an issue while processing the update card. Please contact us. Code: 200035'; } cc_xendit_form.validation.html(failure_reason); cc_xendit_form.form.append(""); @@ -209,13 +209,9 @@ jQuery(function ($) { if(cc_xendit_form.canUseDynamic3DS()){ Xendit.card.threeDSRecommendation({'token_id': token_id}, cc_xendit_form.on3DSRecommendationResponse); }else{ - let data = {'token_id': token_id, 'amount': '10000'}; - Xendit.card.createToken(data, cc_xendit_form.onTokenizationResponse); + Xendit.card.createAuthentication({'token_id': token_id, 'amount': 0}, cc_xendit_form.on3DSAuthenticationResponse); } - // Check if it needs to use 3DS - Xendit.card.threeDSRecommendation({'token_id': token_id}, cc_xendit_form.on3DSRecommendationResponse); - // Prevent form submitting return false; }, @@ -228,11 +224,11 @@ jQuery(function ($) { } if(response.should_3ds){ - let data = {'token_id': $("input[name='xendit_token']").val(), 'amount': '10000'}; + let data = {'token_id': $("input[name='xendit_token']").val(), 'amount': '0'}; Xendit.card.createAuthentication(data, cc_xendit_form.on3DSAuthenticationResponse); return; }else{ - cc_xendit_form.form.append( "" ); + cc_xendit_form.form.append( "" ); cc_xendit_form.form.submit(); return false; } @@ -244,7 +240,7 @@ jQuery(function ($) { return false; } - let threeDsAuthenticationSuccess = 0; + let ccAuthenticationSuccess = 0; if(response.status === 'IN_REVIEW' || response.status === 'CARD_ENROLLED' ){ $('body').append('
' + '