From 95d5ecd432f1e7e967894394f9d106ddeea6df28 Mon Sep 17 00:00:00 2001 From: SenthilKumar Date: Fri, 26 Mar 2021 17:09:12 +0530 Subject: [PATCH 1/4] admin and front end changes --- .../community/Hps/Transit/Helper/Data.php | 4 +- .../community/Hps/Transit/Model/Payment.php | 31 +++++++-- .../Transit/Model/Source/AvsResultCodes.php | 68 +++++++++++++++++++ .../Transit/Model/Source/CvvResultCodes.php | 36 ++++++++++ app/code/community/Hps/Transit/etc/system.xml | 46 +++++++++++++ 5 files changed, 178 insertions(+), 7 deletions(-) create mode 100644 app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php create mode 100644 app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php diff --git a/app/code/community/Hps/Transit/Helper/Data.php b/app/code/community/Hps/Transit/Helper/Data.php index 5ff7752..f09a6b3 100644 --- a/app/code/community/Hps/Transit/Helper/Data.php +++ b/app/code/community/Hps/Transit/Helper/Data.php @@ -2,10 +2,10 @@ use GlobalPayments\Api\ServicesContainer; use GlobalPayments\Api\ServiceConfigs\AcceptorConfig; -use GlobalPayments\Api\ServiceConfigs\Gateways\TransitConfig; use GlobalPayments\Api\Entities\Enums\CardDataSource; use GlobalPayments\Api\Entities\Enums\Environment; use GlobalPayments\Api\Entities\Enums\GatewayProvider; +use GlobalPayments\Api\ServiceConfigs\Gateways\TransitConfig; /** * @category Hps @@ -21,7 +21,7 @@ class Hps_Transit_Helper_Data extends Mage_Core_Helper_Abstract const CONFIG_FORMAT = 'payment/hps_transit/%s'; public function configureSDK($isTsep = false) - { + { $config = new TransitConfig(); $pairs = [ diff --git a/app/code/community/Hps/Transit/Model/Payment.php b/app/code/community/Hps/Transit/Model/Payment.php index dfd2e43..33b7f83 100644 --- a/app/code/community/Hps/Transit/Model/Payment.php +++ b/app/code/community/Hps/Transit/Model/Payment.php @@ -96,6 +96,12 @@ public function authorize(Varien_Object $payment, $amount) private function _authorize(Varien_Object $payment, $amount, $capture) { $this->getFraudSettings(); + + $declinedAvsCodes = Mage::getStoreConfig('payment/hps_transit/avs_decline_codes'); + $declinedCvnCodes = Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes'); + + Mage::log(print_r($declinedAvsCodes, true)); + Mage::log(print_r($declinedCvnCodes, true)); /* @var $order Mage_Sales_Model_Order */ $order = $payment->getOrder(); @@ -190,10 +196,25 @@ private function _authorize(Varien_Object $payment, $amount, $capture) return; } + + $status = self::STATUS_APPROVED; + //auto reversal incase of AVS/CVV decline + $avsCvvValidation = Mage::getStoreConfig('payment/hps_transit/avs_cvv_validation'); + if ($response->responseCode === '00' && $avsCvvValidation === true) { + if(!empty($response->avsResponseCode) || !empty($response->cvnResponseCode)){ + $declinedAvsCodes = Mage::getStoreConfig('payment/hps_transit/avs_decline_codes'); + $declinedCvnCodes = Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes'); + if(in_array($response->avsResponseCode, $declinedAvsCodes) || + in_array($response->cvnResponseCode, $declinedCvnCodes)){ + $reverseResponse = $cardOrToken->reverse($amount)->execute(); + $status = self::STATUS_DECLINED; + } + } + } $this->_debugChargeService(); // \Hps_Transit_Model_Payment::closeTransaction - $this->closeTransaction($payment, $amount, $response); + $this->closeTransaction($payment, $amount, $response, $status); if ($multiToken) { $this->saveMultiUseToken($response, $cardData, $customerId, $cardType); @@ -319,12 +340,12 @@ protected function closeTransaction($payment, $amount, $response, $status = self if (property_exists($response, 'avsResultCode')) { $payment->setCcAvsStatus($response->avsResultCode); - $details['avs_response_code'] = $response->avsResultCode; - $details['avs_response_text'] = $response->avsResultText; + $details['avs_response_code'] = $response->avsResponseCode; + $details['avs_response_text'] = $response->avsResponseMessage; } - if (property_exists($response, 'cvvResultCode')) { - $details['cvv_response_code'] = $response->cvvResultCode; + if (property_exists($response, 'cavvResponseCode')) { + $details['cvv_response_code'] = $response->cavvResponseCode; $details['cvv_response_text'] = $response->cvvResultText; } diff --git a/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php b/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php new file mode 100644 index 0000000..1d44440 --- /dev/null +++ b/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php @@ -0,0 +1,68 @@ + 'A', + 'label' => 'Address matches, zip No Match' + ), + array( + 'value' => 'N', + 'label' => 'Neither address or zip code match' + ), + array( + 'value' => 'R', + 'label' => 'Retry - system unable to respond' + ), + array( + 'value' => 'S/U', + 'label' => 'AVS not supported' + ), + array( + 'value' => 'Z/W', + 'label' => '9-digit zip code match, address no match' + ), + array( + 'value' => 'X/Y', + 'label' => '5-digit zip code and address match' + ), + array( + 'value' => 'G', + 'label' => 'Address not verified for International transaction' + ), + array( + 'value' => 'B', + 'label' => 'Address match, Zip not verified' + ), + array( + 'value' => 'C', + 'label' => 'Address and zip mismatch' + ), + array( + 'value' => 'D', + 'label' => 'Address and zip match' + ), + array( + 'value' => 'I', + 'label' => 'AVS not verified for International transaction' + ), + array( + 'value' => 'M', + 'label' => 'Street address and postal code matches' + ), + array( + 'value' => 'P', + 'label' => 'Address and Zip not verified' + ) + ); + } +} diff --git a/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php b/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php new file mode 100644 index 0000000..cd8d209 --- /dev/null +++ b/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php @@ -0,0 +1,36 @@ + 'N', + 'label' => 'Not Matching' + ), + array( + 'value' => 'P', + 'label' => 'Not Processed' + ), + array( + 'value' => 'S', + 'label' => 'Result not present' + ), + array( + 'value' => 'U', + 'label' => 'Issuer not certified' + ), + array( + 'value' => '?', + 'label' => 'CVV unrecognized' + ), + ); + } +} diff --git a/app/code/community/Hps/Transit/etc/system.xml b/app/code/community/Hps/Transit/etc/system.xml index 459b03a..3da7f29 100644 --- a/app/code/community/Hps/Transit/etc/system.xml +++ b/app/code/community/Hps/Transit/etc/system.xml @@ -203,6 +203,52 @@ 1 + + + select + adminhtml/system_config_source_yesno + 67 + 1 + 1 + 1 + 1 + + + + + multiselect + hps_transit/source_avsresultcodes + 68 + 1 + 1 + 1 + 1 + + + + + multiselect + hps_transit/source_cvvresultcodes + 69 + 1 + 1 + 1 + 1 + + + + + + + + + + From 9bda585aeb86afc7314296003b6e5ba21bea5ca0 Mon Sep 17 00:00:00 2001 From: SenthilKumar Date: Tue, 30 Mar 2021 18:14:28 +0530 Subject: [PATCH 2/4] Result codes and reversal logic updated --- .../community/Hps/Transit/Model/Payment.php | 43 ++++++--------- .../Transit/Model/Source/AvsResultCodes.php | 52 ++----------------- .../Transit/Model/Source/CvvResultCodes.php | 22 ++------ 3 files changed, 26 insertions(+), 91 deletions(-) diff --git a/app/code/community/Hps/Transit/Model/Payment.php b/app/code/community/Hps/Transit/Model/Payment.php index 33b7f83..fae0202 100644 --- a/app/code/community/Hps/Transit/Model/Payment.php +++ b/app/code/community/Hps/Transit/Model/Payment.php @@ -96,12 +96,6 @@ public function authorize(Varien_Object $payment, $amount) private function _authorize(Varien_Object $payment, $amount, $capture) { $this->getFraudSettings(); - - $declinedAvsCodes = Mage::getStoreConfig('payment/hps_transit/avs_decline_codes'); - $declinedCvnCodes = Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes'); - - Mage::log(print_r($declinedAvsCodes, true)); - Mage::log(print_r($declinedCvnCodes, true)); /* @var $order Mage_Sales_Model_Order */ $order = $payment->getOrder(); @@ -168,13 +162,25 @@ private function _authorize(Varien_Object $payment, $amount, $capture) } $response = $builder->execute(); - - if ($response->responseCode !== '00' || $response->responseMessage === 'Partially Approved') { + + if ($response->responseCode !== '00') { // TODO: move this // $this->updateVelocity($e); - - if ($response->responseCode === '10' || $response->responseMessage === 'Partially Approved') { + $status = self::STATUS_APPROVED; + if($response->responseCode === '10' || $response->responseMessage === 'Partially Approved'){ try { $response->void()->withDescription('POST_AUTH_USER_DECLINE')->execute(); } catch (\Exception $e) {} + } else { + $avsCvvValidation = Mage::getStoreConfig('payment/hps_transit/avs_cvv_validation'); + if($avsCvvValidation === true && + (!empty($response->avsResponseCode) || !empty($response->cvnResponseCode))){ + $declinedAvsCodes = Mage::getStoreConfig('payment/hps_transit/avs_decline_codes'); + $declinedCvnCodes = Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes'); + if(in_array($response->avsResponseCode, $declinedAvsCodes) || + in_array($response->cvnResponseCode, $declinedCvnCodes)){ + try { $cardOrToken->reverse($amount)->execute(); } catch (\Exception $e) {} + $status = self::STATUS_DECLINED; + } + } } if (!$this->_allow_fraud || $response->responseCode !== 'FR') { @@ -192,26 +198,11 @@ private function _authorize(Varien_Object $payment, $amount, $capture) ); } - $this->closeTransaction($payment,$amount,$e); + $this->closeTransaction($payment,$amount,$response, $status); return; } - $status = self::STATUS_APPROVED; - //auto reversal incase of AVS/CVV decline - $avsCvvValidation = Mage::getStoreConfig('payment/hps_transit/avs_cvv_validation'); - if ($response->responseCode === '00' && $avsCvvValidation === true) { - if(!empty($response->avsResponseCode) || !empty($response->cvnResponseCode)){ - $declinedAvsCodes = Mage::getStoreConfig('payment/hps_transit/avs_decline_codes'); - $declinedCvnCodes = Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes'); - if(in_array($response->avsResponseCode, $declinedAvsCodes) || - in_array($response->cvnResponseCode, $declinedCvnCodes)){ - $reverseResponse = $cardOrToken->reverse($amount)->execute(); - $status = self::STATUS_DECLINED; - } - } - } - $this->_debugChargeService(); // \Hps_Transit_Model_Payment::closeTransaction $this->closeTransaction($payment, $amount, $response, $status); diff --git a/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php b/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php index 1d44440..a9a1456 100644 --- a/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php +++ b/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php @@ -12,57 +12,13 @@ public function toOptionArray() { return array( array( - 'value' => 'A', - 'label' => 'Address matches, zip No Match' + 'value' => 'D2018', + 'label' => 'AVS FAILED' ), array( - 'value' => 'N', - 'label' => 'Neither address or zip code match' - ), - array( - 'value' => 'R', - 'label' => 'Retry - system unable to respond' - ), - array( - 'value' => 'S/U', - 'label' => 'AVS not supported' - ), - array( - 'value' => 'Z/W', - 'label' => '9-digit zip code match, address no match' + 'value' => 'D2027', + 'label' => 'AVS and CVV2 failed' ), - array( - 'value' => 'X/Y', - 'label' => '5-digit zip code and address match' - ), - array( - 'value' => 'G', - 'label' => 'Address not verified for International transaction' - ), - array( - 'value' => 'B', - 'label' => 'Address match, Zip not verified' - ), - array( - 'value' => 'C', - 'label' => 'Address and zip mismatch' - ), - array( - 'value' => 'D', - 'label' => 'Address and zip match' - ), - array( - 'value' => 'I', - 'label' => 'AVS not verified for International transaction' - ), - array( - 'value' => 'M', - 'label' => 'Street address and postal code matches' - ), - array( - 'value' => 'P', - 'label' => 'Address and Zip not verified' - ) ); } } diff --git a/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php b/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php index cd8d209..341ee98 100644 --- a/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php +++ b/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php @@ -12,25 +12,13 @@ public function toOptionArray() { return array( array( - 'value' => 'N', - 'label' => 'Not Matching' + 'value' => 'D2020', + 'label' => 'CVV2 verification failed' ), array( - 'value' => 'P', - 'label' => 'Not Processed' - ), - array( - 'value' => 'S', - 'label' => 'Result not present' - ), - array( - 'value' => 'U', - 'label' => 'Issuer not certified' - ), - array( - 'value' => '?', - 'label' => 'CVV unrecognized' - ), + 'value' => 'D2027', + 'label' => 'AVS and CVV2 failed' + ) ); } } From b33195fd4a74f5f9d17615a8111e302926af9465 Mon Sep 17 00:00:00 2001 From: SenthilKumar Date: Wed, 31 Mar 2021 15:18:34 +0530 Subject: [PATCH 3/4] space removed --- app/code/community/Hps/Transit/etc/system.xml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/code/community/Hps/Transit/etc/system.xml b/app/code/community/Hps/Transit/etc/system.xml index 3da7f29..92e6a14 100644 --- a/app/code/community/Hps/Transit/etc/system.xml +++ b/app/code/community/Hps/Transit/etc/system.xml @@ -240,15 +240,7 @@ 1 1 - - - - - - - - - + From 48d945917010f1a0a268bb2401d77597de30972a Mon Sep 17 00:00:00 2001 From: SenthilKumar Date: Mon, 17 May 2021 14:17:09 +0530 Subject: [PATCH 4/4] PR review comments changes --- .../community/Hps/Transit/Model/Payment.php | 12 ++-- .../Transit/Model/Source/AvsResultCodes.php | 66 +++++++++++++++++-- .../Transit/Model/Source/CvvResultCodes.php | 20 ++++-- app/code/community/Hps/Transit/etc/system.xml | 4 +- 4 files changed, 85 insertions(+), 17 deletions(-) diff --git a/app/code/community/Hps/Transit/Model/Payment.php b/app/code/community/Hps/Transit/Model/Payment.php index fae0202..ac2b376 100644 --- a/app/code/community/Hps/Transit/Model/Payment.php +++ b/app/code/community/Hps/Transit/Model/Payment.php @@ -162,7 +162,7 @@ private function _authorize(Varien_Object $payment, $amount, $capture) } $response = $builder->execute(); - + if ($response->responseCode !== '00') { // TODO: move this // $this->updateVelocity($e); @@ -173,8 +173,8 @@ private function _authorize(Varien_Object $payment, $amount, $capture) $avsCvvValidation = Mage::getStoreConfig('payment/hps_transit/avs_cvv_validation'); if($avsCvvValidation === true && (!empty($response->avsResponseCode) || !empty($response->cvnResponseCode))){ - $declinedAvsCodes = Mage::getStoreConfig('payment/hps_transit/avs_decline_codes'); - $declinedCvnCodes = Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes'); + $declinedAvsCodes = explode(',', Mage::getStoreConfig('payment/hps_transit/avs_decline_codes')); + $declinedCvnCodes = explode(',', Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes')); if(in_array($response->avsResponseCode, $declinedAvsCodes) || in_array($response->cvnResponseCode, $declinedCvnCodes)){ try { $cardOrToken->reverse($amount)->execute(); } catch (\Exception $e) {} @@ -335,9 +335,9 @@ protected function closeTransaction($payment, $amount, $response, $status = self $details['avs_response_text'] = $response->avsResponseMessage; } - if (property_exists($response, 'cavvResponseCode')) { - $details['cvv_response_code'] = $response->cavvResponseCode; - $details['cvv_response_text'] = $response->cvvResultText; + if (property_exists($response, 'cvnResponseCode')) { + $details['cvv_response_code'] = $response->cvnResponseCode; + $details['cvv_response_text'] = $response->cvnResponseMessage; } $info->setAdditionalData(serialize($details)); diff --git a/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php b/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php index a9a1456..8513c28 100644 --- a/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php +++ b/app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php @@ -12,13 +12,69 @@ public function toOptionArray() { return array( array( - 'value' => 'D2018', - 'label' => 'AVS FAILED' + 'value' => 'A', + 'label' => 'Address matches, zip No Match' ), array( - 'value' => 'D2027', - 'label' => 'AVS and CVV2 failed' - ), + 'value' => 'N', + 'label' => 'Neither address or zip code match' + ), + array( + 'value' => 'R', + 'label' => 'Retry - system unable to respond' + ), + array( + 'value' => 'U', + 'label' => 'Visa / Discover card AVS not supported' + ), + array( + 'value' => 'S', + 'label' => 'Master / Amex card AVS not supported' + ), + array( + 'value' => 'Z', + 'label' => 'Visa / Discover card 9-digit zip code match, address no match' + ), + array( + 'value' => 'W', + 'label' => 'Master / Amex card 9-digit zip code match, address no match' + ), + array( + 'value' => 'Y', + 'label' => 'Visa / Discover card 5-digit zip code and address match' + ), + array( + 'value' => 'X', + 'label' => 'Master / Amex card 5-digit zip code and address match' + ), + array( + 'value' => 'G', + 'label' => 'Address not verified for International transaction' + ), + array( + 'value' => 'B', + 'label' => 'Address match, Zip not verified' + ), + array( + 'value' => 'C', + 'label' => 'Address and zip mismatch' + ), + array( + 'value' => 'D', + 'label' => 'Address and zip match' + ), + array( + 'value' => 'I', + 'label' => 'AVS not verified for International transaction' + ), + array( + 'value' => 'M', + 'label' => 'Street address and postal code matches' + ), + array( + 'value' => 'P', + 'label' => 'Address and Zip not verified' + ) ); } } diff --git a/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php b/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php index 341ee98..cb0caee 100644 --- a/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php +++ b/app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php @@ -12,12 +12,24 @@ public function toOptionArray() { return array( array( - 'value' => 'D2020', - 'label' => 'CVV2 verification failed' + 'value' => 'N', + 'label' => 'Not Matching' ), array( - 'value' => 'D2027', - 'label' => 'AVS and CVV2 failed' + 'value' => 'P', + 'label' => 'Not Processed' + ), + array( + 'value' => 'S', + 'label' => 'Result not present' + ), + array( + 'value' => 'U', + 'label' => 'Issuer not certified' + ), + array( + 'value' => '?', + 'label' => 'CVV unrecognized' ) ); } diff --git a/app/code/community/Hps/Transit/etc/system.xml b/app/code/community/Hps/Transit/etc/system.xml index 92e6a14..a690970 100644 --- a/app/code/community/Hps/Transit/etc/system.xml +++ b/app/code/community/Hps/Transit/etc/system.xml @@ -222,7 +222,7 @@ multiselect - hps_transit/source_avsresultcodes + hps_transit/source_avsResultCodes 68 1 1 @@ -233,7 +233,7 @@ multiselect - hps_transit/source_cvvresultcodes + hps_transit/source_cvvResultCodes 69 1 1