Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avs validation #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/code/community/Hps/Transit/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down
34 changes: 23 additions & 11 deletions app/code/community/Hps/Transit/Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,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') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the code inside the if statement will never be run because response code different than '00' throw an exception. An exception is thrown in checkResponse function (https://github.com/hps/php-sdk/blob/962f6826c5938ec9b7c13dbad911970c019057da/src/Gateways/TransITConnector.php#L573).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slogsdon shall we update the PHP SDK to allow the AVS failure code and handle this in plugin side

// 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');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:

$declinedAvsCodes = explode(',', Mage::getStoreConfig('payment/hps_transit/avs_decline_codes'));
$declinedCvnCodes = explode(',', Mage::getStoreConfig('payment/hps_transit/cvv_decline_codes'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks.. I updated the code with explode function

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') {
Expand All @@ -186,14 +198,14 @@ private function _authorize(Varien_Object $payment, $amount, $capture)
);
}

$this->closeTransaction($payment,$amount,$e);
$this->closeTransaction($payment,$amount,$response, $status);

return;
}

$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);
Expand Down Expand Up @@ -319,12 +331,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cvv and cavv represent two separate ideas. We need cvv in this case.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the response code and message

$details['cvv_response_text'] = $response->cvvResultText;
}

Expand Down
24 changes: 24 additions & 0 deletions app/code/community/Hps/Transit/Model/Source/AvsResultCodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @category Hps
* @package Hps_Transit
* @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
* @license https://github.com/hps/transit-magento-extension/blob/master/LICENSE Custom License
*/

class Hps_Transit_Model_Source_AvsResultCodes
{
public function toOptionArray()
{
return array(
array(
'value' => 'D2018',
'label' => 'AVS FAILED'
),
array(
'value' => 'D2027',
'label' => 'AVS and CVV2 failed'
),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using the individual AVS result codes instead of the gateway's general response code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slogsdon from the available transit documents which you already shared, I found only these 2 result codes related to AVS/CVV, is there any other document available for the result codes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're performing the comparison against the $response->avsResponseCode and $response->cvnResponseCode response properties, which is correct, but the codes in these properties align with the standard AVS/CVV codes (i.e. what I listed in the requirements doc and what you're using in other PRs, WooCommerce as an example)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. updated the result codes

}
24 changes: 24 additions & 0 deletions app/code/community/Hps/Transit/Model/Source/CvvResultCodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @category Hps
* @package Hps_Transit
* @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
* @license https://github.com/hps/transit-magento-extension/blob/master/LICENSE Custom License
*/

class Hps_Transit_Model_Source_CvvResultCodes
{
public function toOptionArray()
{
return array(
array(
'value' => 'D2020',
'label' => 'CVV2 verification failed'
),
array(
'value' => 'D2027',
'label' => 'AVS and CVV2 failed'
)
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using the individual CVV result codes instead of the gateway's general response code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. updated the result codes

}
38 changes: 38 additions & 0 deletions app/code/community/Hps/Transit/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,44 @@
<comment><![CDATA[The amount of time (in minutes) before recent failures are ignored.]]></comment>
<depends><enable_anti_fraud>1</enable_anti_fraud></depends>
</fraud_velocity_timeout>
<avs_cvv_validation translate="label">
<label>AVS/CVV Validation</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>67</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends><enable_anti_fraud>1</enable_anti_fraud></depends>
<comment><![CDATA[Address Verification Service (AVS) and Cardholder Verification Value (CVV) are
simple service offered by the cardholders’ issuing banks. With Heartland’s payment gateway,
you can elect to send automatic reversals for undersired AVS / CVV result codes, freeing you
to focus on your core business logic. As an added bonus, the inclusion of AVS and CVV
information during the request helps your transactions qualify for lower Interchange rates,
further helping to reduce your overall cost of payment acceptance..]]></comment>
</avs_cvv_validation>
<avs_decline_codes translate="label">
<label>AVS Decline Condition</label>
<frontend_type>multiselect</frontend_type>
<source_model>hps_transit/source_avsresultcodes</source_model>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:
<source_model>hps_transit/source_avsResultCodes</source_model>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the model name

<sort_order>68</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends><avs_cvv_validation>1</avs_cvv_validation></depends>
<comment><![CDATA[Select in what scenarios transaction needs to be reversed.]]></comment>
</avs_decline_codes>
<cvv_decline_codes translate="label">
<label>CVV Decline Condition</label>
<frontend_type>multiselect</frontend_type>
<source_model>hps_transit/source_cvvresultcodes</source_model>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:
<source_model>hps_transit/source_cvvResultCodes</source_model>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the model name

<sort_order>69</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends><avs_cvv_validation>1</avs_cvv_validation></depends>
<comment><![CDATA[Select in what scenarios transaction needs to be reversed.]]></comment>
</cvv_decline_codes>
<!-- Misc. -->
<custom_message translate="label">
<label>Custom Error Message</label>
Expand Down