Skip to content

Commit

Permalink
Merge branch 'main' into split-tender
Browse files Browse the repository at this point in the history
  • Loading branch information
mayur-vachchewar authored Feb 25, 2022
2 parents 9e17f49 + 63f7881 commit 8536450
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 38 deletions.
22 changes: 1 addition & 21 deletions assets/frontend/HeartlandGiftFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,7 @@ function applyGiftCard () {
httpRequest.send(post_string);

jQuery('body').trigger('update_checkout');
};

jQuery(document).on( 'click', '.securesubmit-remove-gift-card', function (event) {
event.preventDefault();

var removedCardID = jQuery(this).attr('id');

jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'remove_gift_card',
securesubmit_card_id: removedCardID
}
}).done(function () {
jQuery('body').trigger('update_checkout');
jQuery(".button[name='update_cart']")
.prop("disabled", false)
.trigger("click");
});
});
};

</script>
</div>
Expand Down
2 changes: 2 additions & 0 deletions assets/frontend/js/globalpayments-secure-payment-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@
break;
}
case 'ERROR':
if(reason.message == "IframeField: target cannot be found with given selector")
break;
this.showPaymentError( reason.message );
break;
default:
Expand Down
1 change: 1 addition & 0 deletions globalpayments-gateway-provider-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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.1.6
* Requires PHP: 5.5.9
* WC tested up to: 6.0.0
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Tags: woocommerce, woo, unified, commerce, platform, global, payments, ucp, hear
Requires at least: 5.4
Tested up to: 5.9.0
Stable tag: 1.1.6

License: MIT
License URI: https://github.com/globalpayments/globalpayments-woocommerce/blob/main/LICENSE

Expand Down Expand Up @@ -48,7 +49,13 @@ Access to our Unified Commerce Platform (UCP) requires sandbox credentials which
= 1.1.6 =
* Split-tender - added functionality

= 1.1.3=
= 1.1.5 =
* Bug fix - Heartland gift card error

= 1.1.4 =
* Add dependency for WC checkout frontend scripts.

= 1.1.3 =
* Added composer
* Bug fix - globalpayments_gpapi-checkout_validated displayed although it should be hidden

Expand Down
8 changes: 4 additions & 4 deletions src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function tokenization_script() {
wp_enqueue_script(
'globalpayments-secure-payment-fields',
Plugin::get_url( '/assets/frontend/js/globalpayments-secure-payment-fields.js' ),
array( 'globalpayments-secure-payment-fields-lib', 'jquery' ),
array( 'globalpayments-secure-payment-fields-lib', 'wc-checkout' ),
WC()->version,
true
);
Expand Down Expand Up @@ -719,8 +719,8 @@ protected function add_hooks() {
// hooks only active when the gateway is enabled
add_filter( 'woocommerce_credit_card_form_fields', array( $this, 'woocommerce_credit_card_form_fields' ) );

add_action( 'wp_enqueue_scripts', array( $this, 'tokenization_script' ) );
if ( is_add_payment_method_page() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'tokenization_script' ) );
add_filter( 'woocommerce_available_payment_gateways', array( $this, 'woocommerce_available_payment_gateways') );
}
}
Expand Down Expand Up @@ -953,8 +953,8 @@ protected function handle_response( Requests\RequestInterface $request, Transact
if(!empty($response->transactionReference->transactionId) && $this->get_option('check_avs_cvv') === 'yes'){
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)){
if(in_array($response->avsResponseCode, $this->get_option('avs_reject_conditions')) ||
in_array($response->cvnResponseCode, $this->get_option('cvn_reject_conditions'))){
Transaction::fromId( $response->transactionReference->transactionId )
->reverse( $request->order->data[ 'total' ] )
->execute();
Expand Down
11 changes: 6 additions & 5 deletions src/Gateways/HeartlandGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GlobalPayments\Api\Entities\Reporting\TransactionSummary;
use GlobalPayments\Api\Entities\Transaction;
use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGiftCards\HeartlandGiftCardOrder;
use GlobalPayments\WooCommercePaymentGatewayProvider\Plugin;

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -148,15 +149,16 @@ 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'));
$HeartlandGiftGateway = new HeartlandGiftGateway($this);

add_action('wp_ajax_use_gift_card', array($HeartlandGiftGateway, 'applyGiftCard'));
add_action('wp_ajax_nopriv_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'));
wp_enqueue_style('heartland-gift-cards', Plugin::get_url('/assets/frontend/css/heartland-gift-cards.css'));

$gcthing = new HeartlandGiftCardOrder();

Expand Down Expand Up @@ -245,8 +247,7 @@ public function payment_fields() {
if ( $this->allow_gift_cards === true ) {
$path = dirname(plugin_dir_path(__FILE__));

include_once $path . '/../assets/frontend/HeartlandGiftFields.php';
wp_enqueue_style('heartland-gift-cards', $path . '/../assets/frontend/css/heartland-gift-cards.css');
include_once $path . '/../assets/frontend/HeartlandGiftFields.php';
}
}

Expand Down
41 changes: 36 additions & 5 deletions src/Gateways/HeartlandGiftCards/HeartlandGiftGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
use GlobalPayments\Api\Entities\Transaction;
use GlobalPayments\Api\ServiceConfigs\Gateways\PorticoConfig;
use GlobalPayments\Api\ServicesContainer;
use GlobalPayments\WooCommercePaymentGatewayProvider\Plugin;
use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGateway;


defined('ABSPATH') || exit;

class HeartlandGiftGateway
{
function __construct()
function __construct($heartlandGateway = null)
{
$HeartlandGateway = new HeartlandGateway();
$this->secret_api_key = $HeartlandGateway->get_backend_gateway_options()['secretApiKey'];
if(is_null($heartlandGateway)){
$heartlandGateway = new HeartlandGateway();
}
$this->secret_api_key = $heartlandGateway->get_backend_gateway_options()['secretApiKey'];
}

protected $temp_balance;
Expand Down Expand Up @@ -249,8 +252,36 @@ public function addGiftCards()
WC()->session->set('securesubmit_data', $securesubmit_data);

$message = __('Total Before Gift Cards', 'wc_securesubmit');

$order_total_html = '<tr id="securesubmit_order_total" class="order-total">';

$ajaxUrl = admin_url('admin-ajax.php');
$order_total_html = <<<EOT
<script data-cfasync="false" type="text/javascript">
if( typeof ajaxurl === "undefined") {
var ajaxurl = "{$ajaxUrl}";
};
jQuery(document).on( 'click', '.securesubmit-remove-gift-card', function (event) {
event.preventDefault();
var removedCardID = jQuery(this).attr('id');
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'remove_gift_card',
securesubmit_card_id: removedCardID
}
}).done(function () {
jQuery('body').trigger('update_checkout');
jQuery(".button[name='update_cart']")
.prop("disabled", false)
.trigger("click");
});
});
</script>
EOT;

$order_total_html .= '<tr id="securesubmit_order_total" class="order-total">';
$order_total_html .= '<th>' . $message . '</th>';
$order_total_html .= '<td data-title="' . esc_attr($message) . '">' . wc_price($original_total) . '</td>';
$order_total_html .= '</tr>';
Expand Down
10 changes: 8 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
namespace GlobalPayments\WooCommercePaymentGatewayProvider;

use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGateway;
use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGiftCards\HeartlandGiftGateway;
use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGiftCards\HeartlandGiftCardOrder;

defined( 'ABSPATH' ) || exit;

Expand All @@ -32,6 +30,14 @@ public static function init() {
return;
}

//initialize gift related hooks for Heartland ajax requests
if(wp_doing_ajax() === true || !empty( $_GET['wc-ajax'])){
$heartlandSettings = get_option( 'woocommerce_globalpayments_heartland_settings' );
if($heartlandSettings['enabled'] === 'yes' && $heartlandSettings['allow_gift_cards'] === 'yes'){
new HeartlandGateway();
}
}

add_filter( 'woocommerce_payment_gateways', array( self::class, 'add_gateways' ) );
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' ) );
Expand Down

0 comments on commit 8536450

Please sign in to comment.