Skip to content

Commit

Permalink
Merge pull request #18 from apetrovici/feature/globalpayments-woocomm…
Browse files Browse the repository at this point in the history
…erce

v1.2.2
  • Loading branch information
apetrovici authored Jun 9, 2022
2 parents 17432a5 + 70d1dd4 commit 552c4cb
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 101 deletions.
11 changes: 5 additions & 6 deletions assets/frontend/js/globalpayments-applepay.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
( function (
$,
globalpayments_applepay_params,
globalpayments_order,
helper
) {
function ApplePayWoocommerce ( options, order ) {
function ApplePayWoocommerce ( options ) {
/**
* Payment gateway id
*
Expand All @@ -17,7 +16,7 @@
*
* @type {object}
*/
this.order = order;
this.order = {};

/**
* Payment gateway options
Expand Down Expand Up @@ -78,6 +77,7 @@

createApplePaySession: function () {
var self = this;
this.order = helper.order;

try {
var applePaySession = new ApplePaySession( 1, self.getPaymentRequest() );
Expand Down Expand Up @@ -153,7 +153,7 @@
supportedNetworks: this.getAllowedCardNetworks(),
total: {
label: this.getDisplayName(),
amount: this.order.amount
amount: this.order.amount.toString()
},
};
},
Expand Down Expand Up @@ -185,10 +185,9 @@
},
}

new ApplePayWoocommerce( globalpayments_applepay_params, globalpayments_order );
new ApplePayWoocommerce( globalpayments_applepay_params );
}(
( window ).jQuery,
( window ).globalpayments_applepay_params || {},
( window ).globalpayments_order || {},
( window ).GlobalPaymentsHelper
));
13 changes: 6 additions & 7 deletions assets/frontend/js/globalpayments-googlepay.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
( function (
$,
globalpayments_googlepay_params,
globalpayments_order,
helper
) {
function GooglePayWoocommerce ( options, order ) {
function GooglePayWoocommerce ( options ) {
/**
* Payment gateway id
*
Expand All @@ -17,7 +16,7 @@
*
* @type {object}
*/
this.order = order;
this.order = {};

/**
* Payment gateway options
Expand Down Expand Up @@ -156,7 +155,7 @@
getGoogleTransactionInfo: function () {
return {
totalPriceStatus: 'FINAL',
totalPrice: this.order.amount,
totalPrice: this.order.amount.toString(),
currencyCode: this.order.currency
};
},
Expand Down Expand Up @@ -191,7 +190,8 @@
},

onGooglePaymentButtonClicked: function () {
var self = this
var self = this;
this.order = helper.order;
var paymentDataRequest = this.getGooglePaymentDataRequest();
paymentDataRequest.transactionInfo = this.getGoogleTransactionInfo();

Expand All @@ -211,10 +211,9 @@
},
}

new GooglePayWoocommerce( globalpayments_googlepay_params, globalpayments_order );
new GooglePayWoocommerce( globalpayments_googlepay_params );
}(
( window ).jQuery,
( window ).globalpayments_googlepay_params || {},
( window ).globalpayments_order || {},
( window ).GlobalPaymentsHelper
) );
87 changes: 82 additions & 5 deletions assets/frontend/js/globalpayments-helper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
(function (
$
$,
globalpayments_helper_params
) {
function Helper() {};
function Helper( options ) {
/**
* Helper options
*
* @type {object}
*/
this.helperOptions = options;

/**
* The current order
*
* @type {object}
*/
this.order = options.order;

this.attachEventHandlers();
};

Helper.prototype = {
/**
* Add important event handlers for controlling the payment experience during checkout
*
* @returns
*/
attachEventHandlers: function () {
var self = this;

$( document.body ).on(
'applied_coupon_in_checkout removed_coupon_in_checkout',
function () {
self.blockOnSubmit();

$.get( self.helperOptions.orderInfoUrl )
.done( function( result ) {
self.order = result.message;
})
.fail( function( jqXHR, textStatus, errorThrown ) {
console.log(errorThrown);
})
.always( function() {
self.unblockOnError();
});
}
);
},
/**
* Convenience function to get CSS selector for the built-in 'Place Order' button
*
Expand Down Expand Up @@ -147,11 +190,45 @@
}
$( this.getForm() ).submit();
},

/**
* Blocks checkout UI
*
* Implementation pulled from `woocommerce/assets/js/frontend/checkout.js`
*
* @returns
*/
blockOnSubmit: function () {
var $form = $( this.getForm() );
var form_data = $form.data();
if ( 1 !== form_data['blockUI.isBlocked'] ) {
$form.block(
{
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
}
);
}
},

/**
* Unblocks checkout UI
*
* @returns
*/
unblockOnError: function () {
var $form = $( this.getForm() );
$form.unblock();
}
};

if ( ! window.GlobalPaymentsHelper ) {
window.GlobalPaymentsHelper = new Helper();
window.GlobalPaymentsHelper = new Helper( globalpayments_helper_params );
}
} (
( window ).jQuery
) );
( window ).jQuery,
( window ).globalpayments_helper_params || {}
) );
46 changes: 7 additions & 39 deletions assets/frontend/js/globalpayments-secure-payment-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
/**
* Order info
*/
this.order = threeDSecureOptions.order;
this.order = {};

/**
*
Expand Down Expand Up @@ -122,7 +122,7 @@
*/
initThreeDSecure: function ( e ) {
e.preventDefault;
this.blockOnSubmit();
helper.blockOnSubmit();

var self = this;

Expand All @@ -134,6 +134,7 @@
.done( function( result ) {
if ( -1 !== result.messages.indexOf( self.id + '_checkout_validated' ) ) {
helper.createInputElement( self.id, 'checkout_validated', 1 );
self.order = helper.order;
self.threeDSecure();
} else {
self.showPaymentError( result.messages );
Expand Down Expand Up @@ -217,7 +218,7 @@
styles: this.getStyleConfiguration()
}
);
this.cardForm.on( 'submit', 'click', this.blockOnSubmit.bind( this ) );
this.cardForm.on( 'submit', 'click', helper.blockOnSubmit.bind( this ) );
this.cardForm.on( 'token-success', this.handleResponse.bind( this ) );
this.cardForm.on( 'token-error', this.handleErrors.bind( this ) );
this.cardForm.on( 'error', this.handleErrors.bind( this ) );
Expand Down Expand Up @@ -284,7 +285,7 @@
* 3DS Process
*/
threeDSecure: function () {
this.blockOnSubmit();
helper.blockOnSubmit();

var self = this;
var _form = helper.getForm();
Expand Down Expand Up @@ -425,7 +426,7 @@
showValidationError: function (fieldType) {
$( '.' + this.id + '.' + fieldType + ' .woocommerce-globalpayments-validation-error' ).show();

this.unblockOnError();
helper.unblockOnError();
},

/**
Expand All @@ -450,7 +451,7 @@
scrollTop: ( $form.offset().top - 100 )
}, 1000 );

this.unblockOnError();
helper.unblockOnError();

$( document.body ).trigger( 'checkout_error' );
},
Expand Down Expand Up @@ -589,39 +590,6 @@
*/
getSubmitButtonText: function () {
return $( '#place_order' ).data( 'value' ) || $( '#place_order' ).attr( 'value' );
},

/**
* Blocks checkout UI
*
* Implementation pulled from `woocommerce/assets/js/frontend/checkout.js`
*
* @returns
*/
blockOnSubmit: function () {
var $form = $( helper.getForm() );
var form_data = $form.data();
if ( 1 !== form_data['blockUI.isBlocked'] ) {
$form.block(
{
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
}
);
}
},

/**
* Unblocks checkout UI
*
* @returns
*/
unblockOnError: function () {
var $form = $( helper.getForm() );
$form.unblock();
}
};

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.2.1
* Version: 1.2.2
* Requires PHP: 5.5.9
* WC tested up to: 6.3.1
* Author: Global Payments
Expand Down
5 changes: 4 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, unified, commerce, platform, global, payments, heartland, payment, systems, tsys, genius, 3DS, gateway, token, tokenize, save cards
Requires at least: 5.4
Tested up to: 5.9.3
Stable tag: 1.2.1
Stable tag: 1.2.2
License: MIT
License URI: https://github.com/globalpayments/globalpayments-woocommerce/blob/main/LICENSE

Expand Down Expand Up @@ -47,6 +47,9 @@ Access to our Unified Payments requires sandbox credentials which you can retrie

== Changelog ==

= 1.2.2 =
* Bug fix - 3DS/Digital Wallets amount not updated when a customer added/removed a coupon

= 1.2.1 =
* Renamed Unified Commerce Platform (UCP) to Unified Payments
* Bug fix - Live mode toggle in Digital Wallets javascript
Expand Down
Loading

0 comments on commit 552c4cb

Please sign in to comment.