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 all 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 @@ -163,12 +163,24 @@ 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 = 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) {}
$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,13 +331,13 @@ 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;
$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));
Expand Down
80 changes: 80 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,80 @@
<?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' => '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' => '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'
)
);
}
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

}
36 changes: 36 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,36 @@
<?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' => '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'
)
);
}
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>
<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>
<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