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 cvv support #9

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
38 changes: 37 additions & 1 deletion src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ abstract class AbstractGateway extends WC_Payment_Gateway_Cc {
* @var Clients\ClientInterface
*/
protected $client;

/**
* AVS CVN auto reverse condition
*
* @var bool
*/
public $check_avs_cvv;

/**
* AVS result codes
*
* @var array
*/
public $avs_reject_conditions;

/**
* CVN result codes
*
* @var array
*/
public $cvn_reject_conditions;


public function __construct() {
$this->client = new Clients\SdkClient();
Expand Down Expand Up @@ -168,6 +190,20 @@ abstract public function get_gateway_form_fields();
* @return string
*/
abstract public function get_first_line_support_email();

/**
* Avs Rejection Conditions
*
* @return string
*/
abstract public function avs_rejection_conditions();

/**
* CVV Rejection Conditions
*
* @return string
*/
abstract public function cvn_rejection_conditions();

/**
* Get the current gateway provider
Expand Down Expand Up @@ -625,7 +661,7 @@ protected function submit_request( Requests\RequestInterface $request ) {
* @return bool
*/
protected function handle_response( Requests\RequestInterface $request, Transaction $response ) {
if ($response->responseCode !== '00' && 'SUCCESS' !== $response->responseCode || $response->responseMessage === 'Partially Approved') {
if ($response->responseCode !== '00' && 'SUCCESS' !== $response->responseCode || $response->responseMessage === 'Partially Approved') {
if ($response->responseCode === '10' || $response->responseMessage === 'Partially Approved') {
try {
$response->void()->withDescription('POST_AUTH_USER_DECLINE')->execute();
Expand Down
6 changes: 6 additions & 0 deletions src/Gateways/GeniusGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ public function get_backend_gateway_options() {
'environment' => $this->is_production ? Environment::PRODUCTION : Environment::TEST,
);
}
public function cvn_rejection_conditions()
{}

public function avs_rejection_conditions()
{}

}
6 changes: 6 additions & 0 deletions src/Gateways/GpApiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@ public function mapResponseCodeToFriendlyMessage( $responseCode ) {

return __( 'An error occurred while processing the card.', 'globalpayments-gateway-provider-for-woocommerce' );
}
public function cvn_rejection_conditions()
{}

public function avs_rejection_conditions()
{}

}
78 changes: 74 additions & 4 deletions src/Gateways/HeartlandGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class HeartlandGateway extends AbstractGateway {
*
* @var bool
*/
public $allow_gift_cards;

public $allow_gift_cards;
public function configure_method_settings() {
$this->id = 'globalpayments_heartland';
$this->method_title = __( 'Heartland', 'globalpayments-gateway-provider-for-woocommerce' );
Expand All @@ -49,6 +49,7 @@ public function get_first_line_support_email() {
}

public function get_gateway_form_fields() {

return array(
'public_key' => array(
'title' => __( 'Public Key', 'globalpayments-gateway-provider-for-woocommerce' ),
Expand All @@ -71,6 +72,27 @@ public function get_gateway_form_fields() {
),
'default' => 'no'
),
'check_avs_cvv' => array(
'title' => __( 'Check AVS CVN', 'globalpayments-gateway-provider-for-woocommerce' ),
'label' => __( 'Check AVS/CVN result codes and reverse transaction.', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'checkbox',
'description' => sprintf(
__( 'This will check AVS/CVN result codes and reverse transaction.' )
),
'default' => 'no'
),
'avs_reject_conditions' => array(
'title' => __( 'AVS Reject Conditions', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'multiselect',
'description' => __( 'Choose for which AVS result codes, the transaction must be auto reveresed.'),
'options' => $this->avs_rejection_conditions(),
),
'cvn_reject_conditions' => array(
'title' => __( 'CVN Reject Conditions', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'multiselect',
'description' => __( 'Choose for which CVN result codes, the transaction must be auto reveresed.'),
'options' => $this->cvn_rejection_conditions(),
),
);
}

Expand Down Expand Up @@ -181,11 +203,26 @@ public function payment_fields() {
* @return array *
*/
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
$order = new WC_Order( $order_id );
$request = $this->prepare_request( $this->payment_action, $order );
$response = $this->submit_request( $request );
$is_successful = $this->handle_response( $request, $response );


//reverse incase of AVS/CVN failure
if(!empty($response->transactionReference->transactionId) && !empty($this->check_avs_cvv)){
if(!empty($response->avsResponseCode) || !empty($response->cvnResponseCode)){
//check admin selected decline condtions
if(in_array($response->avsResponseCode, $this->avs_reject_conditions) ||
in_array($response->cvnResponseCode, $this->cvn_reject_conditions)){
Transaction::fromId( $response->transactionReference->transactionId )
->reverse( $request->order->data[ 'total' ] )
->execute();

$is_successful = false;
}
}
}

// Charge HPS gift cards if CC trans succeeds
if ( $is_successful && !empty( WC()->session->get( 'heartland_gift_card_applied' ) ) ) {
$gift_card_order_placement = new HeartlandGiftCardOrder();
Expand All @@ -210,4 +247,37 @@ public function process_payment( $order_id ) {
'redirect' => $is_successful ? $this->get_return_url( $order ) : false,
);
}

public function avs_rejection_conditions()
{
return array(
'A' => 'Address matches, zip No Match',
'N' => 'Neither address or zip code match',
'R' => 'Retry - system unable to respond',
'U' => 'Visa / Discover card AVS not supported',
'S' => 'Master / Amex card AVS not supported',
'Z' => 'Visa / Discover card 9-digit zip code match, address no match',
'W' => 'Master / Amex card 9-digit zip code match, address no match',
'Y' => 'Visa / Discover card 5-digit zip code and address match',
'X' => 'Master / Amex card 5-digit zip code and address match',
'G' => 'Address not verified for International transaction',
'B' => 'Address match, Zip not verified',
'C' => 'Address and zip mismatch',
'D' => 'Address and zip match',
'I' => 'AVS not verified for International transaction',
'M' => 'Street address and postal code matches',
'P' => 'Address and Zip not verified'
);
}

public function cvn_rejection_conditions()
{
return array(
'N' => 'Not Matching',
'P' => 'Not Processed',
'S' => 'Result not present',
'U' => 'Issuer not certified',
'?' => 'CVV unrecognized'
);
}
}
6 changes: 6 additions & 0 deletions src/Gateways/TransitGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,10 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {

return $is_successful;
}
public function cvn_rejection_conditions()
{}

public function avs_rejection_conditions()
{}

}