Skip to content

Commit

Permalink
Merge pull request #25 from apetrovici/release/next-release
Browse files Browse the repository at this point in the history
v1.3.0 (#29)
  • Loading branch information
securesubmit-buildmaster authored Aug 2, 2022
2 parents 80492c5 + 72441fb commit ce62048
Show file tree
Hide file tree
Showing 23 changed files with 693 additions and 182 deletions.
19 changes: 19 additions & 0 deletions assets/admin/css/globalpayments-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,22 @@
margin:0;
}

.woocommerce-globalpayments-checkout-error {
background-color:#e2401c;
margin-left:0;
margin-bottom:10px;
border-radius:4px;
color:#fff;
clear:both;
padding:6px 12px;
position:relative;
list-style:none outside;
display:block;
width:100%;
font-size:14px;
}

.globalpayments.card-submit iframe {
min-height:32px;
width:auto;
}
53 changes: 53 additions & 0 deletions assets/admin/js/globalpayments-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,59 @@
*/
attachEventHandlers: function () {
$( document ).on( 'change', this.getLiveModeSelector(), this.toggleCredentialsSettings.bind( this ) );

// Admin Pay for Order
$( '#customer_user' ).on( 'change', this.updatePaymentMethods );
$( '.wc-globalpayments-pay-order' ).on( 'click', this.payForOrder );
$( document.body ).on('wc_backbone_modal_loaded', this.modalLoaded.bind( this ) );
},

updatePaymentMethods: function ( e ) {
// fetch user payment tokens
var customer_id = $( e.target ).val();
globalpayments_admin_params.payment_methods = [];
if ( customer_id > 0 && typeof globalpayments_admin_params !== "undefined" ) {
var data = {
_wpnonce: globalpayments_admin_params._wpnonce,
customer_id: customer_id
};
$( '.wc-globalpayments-pay-order' ).prop( 'disabled', true );
$.get( globalpayments_admin_params.payment_methods_url, data, function ( response ) {
globalpayments_admin_params.payment_methods = response;
$( '.wc-globalpayments-pay-order' ).prop( 'disabled', false );
}, 'json' );
}
},

/**
* Enable modal template.
*
* @param e
*/
payForOrder: function( e ) {
e.preventDefault();
$( this ).WCGlobalPaymentsPayOrderBackboneModal({
template: 'wc-globalpayments-pay-order-modal',
variable: {
customer_id: $( '#customer_user' ).val(),
payment_methods: globalpayments_admin_params.payment_methods,
}
});
},

/**
* Render modal content.
*
* @param e
* @param target
*/
modalLoaded: function ( e, target ) {
switch ( target ) {
case 'wc-globalpayments-pay-order-modal':
$( document.body ).trigger( 'globalpayments_pay_order_modal_loaded' );
$( document.body ).trigger( 'wc-credit-card-form-init' );
break;
}
},

/**
Expand Down
70 changes: 70 additions & 0 deletions assets/admin/js/globalpayments-modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*global jQuery */
( function( $ ) {
'use strict';

/**
* WooCommerce Backbone Global Payments Modal plugin
*
* @param {object} options
*/
$.fn.WCGlobalPaymentsPayOrderBackboneModal = function( options ) {
return this.each( function() {
( new $.WCGlobalPaymentsPayOrderBackboneModal( $( this ), options ) );
} );
};

/**
* Initialize the Backbone Modal
*
* @param {object} element [description]
* @param {object} options [description]
*/
$.WCGlobalPaymentsPayOrderBackboneModal = function( element, options ) {
var settings = $.extend( {}, $.WCBackboneModal.defaultOptions, options );

if ( settings.template ) {
new $.WCGlobalPaymentsPayOrderBackboneModal.View( {
target: settings.template,
string: settings.variable
} );
}
};

$.WCGlobalPaymentsPayOrderBackboneModal.View = $.WCBackboneModal.View.extend( {
events: _.extend( $.WCBackboneModal.View.prototype.events, {
'click #place_order': 'payOrder'
} ),
payOrder: function( e ) {
e.preventDefault();
this.block();
$.ajax( {
url: globalpayments_admin_params.payorder_url,
method: 'POST',
data: this.getFormData(),
} ).done( function ( response ) {
if ( response.error ) {
this.unblock();
$( document.body ).trigger( 'globalpayments_pay_order_modal_error', [ response.message ] );
} else {
window.location.href = window.location.href;
}
}.bind( this ) ).fail( function ( xhr, textStatus, errorThrown ) {
this.unblock();
$( document.body ).trigger( 'globalpayments_pay_order_modal_error', [ errorThrown ] );
}.bind( this ) )
$( document.body ).trigger( 'globalpayments_pay_order_modal_response', [ this ] );
},
block: function() {
this.$el.find( '.wc-backbone-modal-content' ).block( {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
} );
},
unblock: function() {
this.$el.find( '.wc-backbone-modal-content' ).unblock();
},
} );
} )( jQuery );
9 changes: 8 additions & 1 deletion assets/frontend/js/globalpayments-applepay.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
if ( 1 == wc_checkout_params.is_checkout ) {
$( document.body ).on( 'updated_checkout', this.initialize.bind( this ) );
}

// Order Pay
if ( $( document.body ).hasClass( 'woocommerce-order-pay' ) ) {
$( document ).ready( this.initialize.bind( this ) );
return;
}
},

initialize: function () {
Expand All @@ -61,7 +67,8 @@

var self = this
var paymentButton = document.createElement( 'div' );
paymentButton.className = 'apple-pay-button apple-pay-button-white-with-line';

paymentButton.className = 'apple-pay-button apple-pay-button-' + this.gatewayOptions.button_color;
paymentButton.title = 'Pay with Apple Pay';
paymentButton.alt = 'Pay with Apple Pay';
paymentButton.id = self.id;
Expand Down
6 changes: 6 additions & 0 deletions assets/frontend/js/globalpayments-googlepay.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
if ( 1 == wc_checkout_params.is_checkout ) {
$( document.body ).on( 'updated_checkout', this.initialize.bind( this ) );
}

// Order Pay
if ( $( document.body ).hasClass( 'woocommerce-order-pay' ) ) {
$( document ).ready( this.initialize.bind( this ) );
return;
}
},

initialize: function () {
Expand Down
5 changes: 3 additions & 2 deletions assets/frontend/js/globalpayments-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
var savedCardsAvailable = $( this.getStoredPaymentMethodsRadioSelector( selectedPaymentGatewayId ) + '[value!="new"]' ).length > 0;
// user selects (new) card as payment method
var newSavedCardSelected = 'new' === $( this.getStoredPaymentMethodsRadioSelector( selectedPaymentGatewayId ) + ':checked' ).val();

// selected payment method is card or digital wallet
if ( ! savedCardsAvailable || savedCardsAvailable && newSavedCardSelected ) {
$( this.getSubmitButtonTargetSelector( selectedPaymentGatewayId ) ).show();
Expand All @@ -133,7 +132,9 @@
// Checkout
'form[name="checkout"]',
// Add payment method
'form#add_payment_method'
'form#add_payment_method',
// Admin Order Pay
'form#wc-globalpayments-pay-order-form',
];
var forms = document.querySelectorAll( checkoutForms.join( ',' ) );

Expand Down
15 changes: 12 additions & 3 deletions assets/frontend/js/globalpayments-secure-payment-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
$( document ).ready( this.renderPaymentFields.bind( this ) );
return;
}

// Admin Pay for Order
$( document.body ).on( 'globalpayments_pay_order_modal_loaded', this.renderPaymentFields.bind( this ) );
$( document.body ).on( 'globalpayments_pay_order_modal_error', function( event, message ) {
self.showPaymentError( message );
} );
},

/**
Expand Down Expand Up @@ -453,7 +459,9 @@

helper.unblockOnError();

$( document.body ).trigger( 'checkout_error' );
if ( 1 == wc_checkout_params.is_checkout ) {
$( document.body ).trigger( 'checkout_error' );
}
},

/**
Expand Down Expand Up @@ -589,8 +597,9 @@
* @returns {string}
*/
getSubmitButtonText: function () {
return $( '#place_order' ).data( 'value' ) || $( '#place_order' ).attr( 'value' );
}
var selector = helper.getPlaceOrderButtonSelector();
return $( selector ).data( 'value' ) || $( selector ).attr( 'value' );
},
};

new GlobalPaymentsWooCommerce( globalpayments_secure_payment_fields_params, globalpayments_secure_payment_threedsecure_params );
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"require": {
"globalpayments/php-sdk": "3.0.5",
"globalpayments/php-sdk": "4.0.4",
"psr/log": "^1.1"
},
"require-dev": {
Expand Down
Loading

0 comments on commit ce62048

Please sign in to comment.