Skip to content

Commit

Permalink
Merge pull request globalpayments#5 from apetrovici/v1.0.0
Browse files Browse the repository at this point in the history
V1.0.0
  • Loading branch information
securesubmit-buildmaster authored Jun 17, 2021
2 parents c739cab + fa04109 commit b75db2d
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 66 deletions.
15 changes: 15 additions & 0 deletions assets/frontend/js/globalpayments-secure-payment-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@
this.showValidationError( 'card-cvv' );
break;
case 'MANDATORY_DATA_MISSING':
var n = reason.message.search( "card type" );
if ( n>=0 ) {
this.showValidationError( 'card-number' );
break;
}
var n = reason.message.search( "expiry_year" );
if ( n>=0 ) {
this.showValidationError( 'card-expiration' );
break;
}
var n = reason.message.search( "expiry_month" );
if ( n>=0 ) {
this.showValidationError( 'card-expiration' );
Expand All @@ -558,6 +568,11 @@
this.showValidationError( 'card-cvv' );
break;
}
var n = reason.message.search( "expiry_year" );
if ( n>=0 ) {
this.showValidationError( 'card-expiration' );
break;
}
case 'SYSTEM_ERROR_DOWNSTREAM':
var n = reason.message.search( "card expdate" );
if ( n>=0 ) {
Expand Down
2 changes: 1 addition & 1 deletion globalpayments-gateway-provider-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: GlobalPayments WooCommerce
* Plugin URI: https://github.com/globalpayments/globalpayments-woocommerce
* Description: This extension allows WooCommerce to use the available Global Payments payment gateways. All card data is tokenized using the respective gateway's tokenization service.
* Version: 1.0.0-b.2
* Version: 1.0.0
* Requires PHP: 5.5.9
* WC tested up to: 5.0.0
* Author: Global Payments
Expand Down
18 changes: 17 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: globalpayments
Tags: woocommerce, woo, commerce, global, payments, heartland, payment, systems, tsys, genius, gpapi, gp-api, 3DS, gateway, token, tokenize, save cards
Requires at least: 5.4
Tested up to: 5.7
Stable tag: 1.0.0-b.2
Stable tag: 1.0.0
License: MIT
License URI: https://github.com/globalpayments/globalpayments-woocommerce/blob/main/LICENSE

Expand Down Expand Up @@ -35,8 +35,24 @@ After you have installed and configured the main WooCommerce plugin use the foll
2. Click Install, once installed click Activate
3. Configure and Enable gateways in WooCommerce by adding your public and secret Api Keys

== GP-API Sandbox credentials ==
Access to our GP-API requires sandbox credentials which you can retrieve yourself via our <a href="https://developer.globalpay.com/" target="_blank">Developer Portal</a>:

1. First go to the Developer Portal and make sure the green GP-API button is selected in the top right corner.
2. Click on the icon in the top right and click Register.
3. Once registered, click on the same icon in top right corner and click MyApps. Here we are going to create an app which is a set of GP API credentials used to access the API and generate access tokens.
4. Click ‘Create

== Changelog ==

= 1.0.0 =
* Add GP-API instructions for sandbox credentials
* Handle new errors for card expiry_year
* Move Heartland hooks to gateway class
* Card saving admin note
* Validate refund amount
* Add missing invalid card icons

= 1.0.0-b.2 =
* Fix toggleSubmitButton
* Fix 3DS events
Expand Down
84 changes: 45 additions & 39 deletions src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GlobalPayments\Api\Entities\Enums\GatewayProvider;
use GlobalPayments\Api\Entities\Exceptions\ApiException;
use GlobalPayments\Api\Entities\Reporting\TransactionSummary;
use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\Requests\RequestArg;
use WC_Payment_Gateway_CC;
use WC_Order;
use GlobalPayments\Api\Entities\Transaction;
Expand Down Expand Up @@ -348,7 +349,7 @@ public function init_form_fields() {
'title' => __( 'Payment Action', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'select',
'description' => __( 'Choose whether you wish to capture funds immediately or authorize payment only for a delayed capture.', 'globalpayments-gateway-provider-for-woocommerce' ),
'default' => 'sale',
'default' => self::TXN_TYPE_SALE,
'desc_tip' => true,
'options' => array(
self::TXN_TYPE_SALE => __( 'Authorize + Capture', 'globalpayments-gateway-provider-for-woocommerce' ),
Expand All @@ -362,7 +363,7 @@ public function init_form_fields() {
'type' => 'checkbox',
'description' => sprintf(
/* translators: %s: Email address of support team */
__( 'Note: to use the card saving feature, you must have multi-use token support enabled on your account. Please contact <a href="mailto:%s?Subject=WooCommerce%%20Transaction%%20Descriptor%%20Option">support</a> with any questions regarding this option.', 'globalpayments-gateway-provider-for-woocommerce' ),
__( 'Note: to use the card saving feature, you must have multi-use token support enabled on your account. Please contact <a href="mailto:%s?Subject=WooCommerce%%20Card%%20Saving%%20Option">support</a> with any questions regarding this option.', 'globalpayments-gateway-provider-for-woocommerce' ),
$this->get_first_line_support_email()
),
'default' => 'no',
Expand Down Expand Up @@ -490,65 +491,64 @@ protected function secure_payment_fields_styles() {
),
'.card-cvv' => array(
'background' => 'transparent url(' . $image_base . '/cvv.png) no-repeat right',
'background-size' => '60px'
'background-size' => '63px 40px'
),
'.card-cvv.card-type-amex' => array(
'background' => 'transparent url(' . $image_base . '/cvv-amex.png) no-repeat right',
'background-size' => '60px'
'background-size' => '63px 40px'
),
'.card-number' => array(
'background' => 'transparent url(' . $image_base . '/[email protected]) no-repeat right',
'background-size' => '52px'
'background-size' => '55px 35px'
),
'.card-number.invalid.card-type-amex' => array(
'background' => 'transparent url(' . $image_base . '/amex-invalid.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '38px'
'background' => 'transparent url(' . $image_base . '/[email protected]) no-repeat right',
'background-position-y' => '-41px',
'background-size' => '50px 90px'
),
'.card-number.invalid.card-type-discover' => array(
'background' => 'transparent url(' . $image_base . '/discover-invalid.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '60px'
'background' => 'transparent url(' . $image_base . '/[email protected]) no-repeat right',
'background-position-y' => '-44px',
'background-size' => '85px 90px'
),
'.card-number.invalid.card-type-jcb' => array(
'background' => 'transparent url(' . $image_base . '/jcb-invalid.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '38px'
'background' => 'transparent url(' . $image_base . '/[email protected]) no-repeat right',
'background-position-y' => '-44px',
'background-size' => '55px 94px'
),
'.card-number.invalid.card-type-mastercard' => array(
'background' => 'transparent url(' . $image_base . '/mastercard-invalid.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '40px'
'background' => 'transparent url(' . $image_base . '/[email protected]) no-repeat right',
'background-position-y' => '-41px',
'background-size' => '82px 86px'
),
'.card-number.invalid.card-type-visa' => array(
'background' => 'transparent url(' . $image_base . '/visa-invalid.svg) no-repeat center',
'background-position-x' => '98%',
'background-size' => '50px',
'background' => 'transparent url(' . $image_base . '/[email protected]) no-repeat right',
'background-position-y' => '-44px',
'background-size' => '83px 88px',
),
'.card-number.valid.card-type-amex' => array(
'background' => 'transparent url(' . $image_base . '/amex.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '38px',
'background' => 'transparent url(' . $image_base . '/logo-amex@2x.png) no-repeat right',
'background-position-y' => '3px',
'background-size' => '50px 90px',
),
'.card-number.valid.card-type-discover' => array(
'background' => 'transparent url(' . $image_base . '/discover.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '60px'
'background' => 'transparent url(' . $image_base . '/logo-discover@2x.png) no-repeat right',
'background-position-y' => '1px',
'background-size' => '85px 90px'
),
'.card-number.valid.card-type-jcb' => array(
'background' => 'transparent url(' . $image_base . '/jcb.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '38px'
'background' => 'transparent url(' . $image_base . '/logo-jcb@2x.png) no-repeat right top',
'background-position-y' => '2px',
'background-size' => '55px 94px'
),
'.card-number.valid.card-type-mastercard' => array(
'background' => 'transparent url(' . $image_base . '/mastercard.svg) no-repeat center',
'background-position-x' => '98%',
'background-size' => '40px'
'background' => 'transparent url(' . $image_base . '/logo-mastercard@2x.png) no-repeat right',
'background-position-y' => '2px',
'background-size' => '82px 86px'
),
'.card-number.valid.card-type-visa' => array(
'background' => 'transparent url(' . $image_base . '/visa.svg) no-repeat right center',
'background-position-x' => '98%',
'background-size' => '50px'
'background' => 'transparent url(' . $image_base . '/[email protected]) no-repeat right top',
'background-size' => '82px 86px'
),
'.card-number::-ms-clear' => array(
'display' => 'none',
Expand Down Expand Up @@ -618,8 +618,10 @@ protected function secure_payment_field_html_format() {
*/
protected function add_hooks() {
// hooks always active for the gateway
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, array( $this, 'admin_enforce_single_gateway' ) );
if ( is_admin() ) {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, array( $this, 'admin_enforce_single_gateway' ) );
}

if ( 'no' === $this->enabled ) {
return;
Expand Down Expand Up @@ -691,8 +693,12 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
$is_order_txn_id_active = $this->is_transaction_active( $details );
$txn_type = $is_order_txn_id_active ? self::TXN_TYPE_REVERSAL : self::TXN_TYPE_REFUND;

$order = new WC_Order( $order_id );
$request = $this->prepare_request( $txn_type, $order );
$order = new WC_Order( $order_id );
$request = $this->prepare_request( $txn_type, $order );
$request_args = $request->get_args();
if ( empty( $request_args[ RequestArg::AMOUNT ] ) ) {
throw new Exception( __( 'Refund amount must be greater than zero.', 'globalpayments-gateway-provider-for-woocommerce' ) );
}
$response = $this->submit_request( $request );
$is_successful = $this->handle_response( $request, $response );

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/Handlers/PaymentTokenHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class PaymentTokenHandler extends AbstractHandler {
public function handle() {
if ( ! $this->response->token ) {
return;
if ( empty( $this->response->token ) ) {
return;
}

( new PaymentTokenData( $this->request ) )->save_new_token( $this->response->token, $this->response->cardBrandTransactionId );
Expand Down
22 changes: 22 additions & 0 deletions src/Gateways/HeartlandGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GlobalPayments\WooCommercePaymentGatewayProvider\Gateways;

use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGiftCards\HeartlandGiftGateway;
use WC_Order;
use GlobalPayments\Api\Entities\Enums\GatewayProvider;
use GlobalPayments\Api\Entities\Reporting\TransactionSummary;
Expand Down Expand Up @@ -88,6 +89,27 @@ public function get_backend_gateway_options() {
);
}

protected function add_hooks() {
parent::add_hooks();

if ($this->allow_gift_cards === true) {
$HeartlandGiftGateway = new HeartlandGiftGateway();

add_action('wp_ajax_nopriv_use_gift_card', array($HeartlandGiftGateway, 'applyGiftCard'));
add_action('wp_ajax_use_gift_card', array($HeartlandGiftGateway, 'applyGiftCard'));
add_action('woocommerce_review_order_before_order_total', array($HeartlandGiftGateway, 'addGiftCards'));
add_action('woocommerce_cart_totals_before_order_total', array($HeartlandGiftGateway, 'addGiftCards'));
add_filter('woocommerce_calculated_total', array($HeartlandGiftGateway, 'updateOrderTotal'), 10, 2);
add_action('wp_ajax_nopriv_remove_gift_card', array($HeartlandGiftGateway, 'removeGiftCard'));
add_action('wp_ajax_remove_gift_card', array($HeartlandGiftGateway, 'removeGiftCard'));

$gcthing = new HeartlandGiftCardOrder();

add_filter('woocommerce_get_order_item_totals', array( $gcthing, 'addItemsToPostOrderDisplay'), PHP_INT_MAX - 1, 2);
add_action('woocommerce_checkout_order_processed', array( $gcthing, 'processGiftCardsZeroTotal'), PHP_INT_MAX, 2);
}
}

protected function is_transaction_active( TransactionSummary $details ) {
// @phpcs:ignore WordPress.NamingConventions.ValidVariableName
return 'A' === $details->transactionStatus;
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Requests/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function get_args() {

return array(
RequestArg::CURRENCY => $this->order->get_currency(),
RequestArg::AMOUNT => $refund_amount,
RequestArg::AMOUNT => ! empty( $refund_amount ) ? $refund_amount : null,
RequestArg::GATEWAY_ID => $gateway_id,
RequestArg::DESCRIPTION => $description,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public function get_args() {

protected function getToken( $requestData ) {
if ( ! isset( $requestData->wcTokenId ) && ! isset( $requestData->tokenResponse ) ) {
throw new \Exception( __( 'Not enough data to perform 3DS. Unable to retrieve token.') );
throw new \Exception( __( 'Not enough data to perform 3DS. Unable to retrieve token.' ) );
}

if ( isset( $requestData->wcTokenId ) && 'new' !== $requestData->wcTokenId ) {
$tokenResponse = \WC_Payment_Tokens::get( $requestData->wcTokenId );
if ( empty( $tokenResponse ) ) {
throw new \Exception( __( 'Not enough data to perform 3DS. Unable to retrieve token.') );
throw new \Exception( __( 'Not enough data to perform 3DS. Unable to retrieve token.' ) );
}

return $token = $tokenResponse->get_token();
return $tokenResponse->get_token();
}

$tokenResponse = json_decode( $requestData->tokenResponse );
if ( empty( $tokenResponse->paymentReference ) ) {
throw new \Exception( __( 'Not enough data to perform 3DS. Unable to retrieve token.') );
throw new \Exception( __( 'Not enough data to perform 3DS. Unable to retrieve token.' ) );
}

return $tokenResponse->paymentReference;
Expand Down
18 changes: 0 additions & 18 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ public static function init() {
add_action( 'woocommerce_order_actions', array( Gateways\AbstractGateway::class, 'addCaptureOrderAction' ) );
add_action( 'woocommerce_order_action_capture_credit_card_authorization', array( Gateways\AbstractGateway::class, 'capture_credit_card_authorization' ) );

$HeartlandGateway = new HeartlandGateway();

if ($HeartlandGateway->allow_gift_cards === true) {
$HeartlandGiftGateway = new HeartlandGiftGateway();

add_action('wp_ajax_nopriv_use_gift_card', array($HeartlandGiftGateway, 'applyGiftCard'));
add_action('wp_ajax_use_gift_card', array($HeartlandGiftGateway, 'applyGiftCard'));
add_action('woocommerce_review_order_before_order_total', array($HeartlandGiftGateway, 'addGiftCards'));
add_action('woocommerce_cart_totals_before_order_total', array($HeartlandGiftGateway, 'addGiftCards'));
add_filter('woocommerce_calculated_total', array($HeartlandGiftGateway, 'updateOrderTotal'), 10, 2);
add_action('wp_ajax_nopriv_remove_gift_card', array($HeartlandGiftGateway, 'removeGiftCard'));
add_action('wp_ajax_remove_gift_card', array($HeartlandGiftGateway, 'removeGiftCard'));

$gcthing = new HeartlandGiftCardOrder();

add_filter('woocommerce_get_order_item_totals', array( $gcthing, 'addItemsToPostOrderDisplay'), PHP_INT_MAX - 1, 2);
add_action('woocommerce_checkout_order_processed', array( $gcthing, 'processGiftCardsZeroTotal'), PHP_INT_MAX, 2);
}
add_filter( 'admin_enqueue_scripts', array( Gateways\AbstractGateway::class, 'admin_enqueue_scripts' ) );
}

Expand Down

0 comments on commit b75db2d

Please sign in to comment.