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

Use triggers block/unblock the payment request button #1509

Merged
Merged
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
22 changes: 15 additions & 7 deletions assets/js/stripe-payment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,17 @@ jQuery( function( $ ) {
paymentRequest.show();
}
});

$( document.body ).on( 'woocommerce_variation_has_changed', function () {

$( document.body ).on( 'wc_stripe_unblock_payment_request_button', function () {
wc_stripe_payment_request.unblockPaymentRequestButton( prButton );
} );

$( document.body ).on( 'wc_stripe_block_payment_request_button', function () {
wc_stripe_payment_request.blockPaymentRequestButton( prButton );
} );

$( document.body ).on( 'woocommerce_variation_has_changed', function () {
$( document.body ).trigger( 'wc_stripe_block_payment_request_button' );

$.when( wc_stripe_payment_request.getSelectedProductData() ).then( function ( response ) {
$.when(
Expand All @@ -620,33 +628,33 @@ jQuery( function( $ ) {
displayItems: response.displayItems,
} )
).then( function () {
wc_stripe_payment_request.unblockPaymentRequestButton( prButton );
$( document.body ).trigger( 'wc_stripe_unblock_payment_request_button' );
} );
});
} );

// Block the payment request button as soon as an "input" event is fired, to avoid sync issues
// when the customer clicks on the button before the debounced event is processed.
$( '.quantity' ).on( 'input', '.qty', function() {
wc_stripe_payment_request.blockPaymentRequestButton( prButton );
$( document.body ).trigger( 'wc_stripe_block_payment_request_button' );
} );

$( '.quantity' ).on( 'input', '.qty', wc_stripe_payment_request.debounce( 250, function() {
wc_stripe_payment_request.blockPaymentRequestButton( prButton );
$( document.body ).trigger( 'wc_stripe_block_payment_request_button' );
paymentRequestError = [];

$.when( wc_stripe_payment_request.getSelectedProductData() ).then( function ( response ) {
if ( response.error ) {
paymentRequestError = [ response.error ];
wc_stripe_payment_request.unblockPaymentRequestButton( prButton );
$( document.body ).trigger( 'wc_stripe_unblock_payment_request_button' );
} else {
$.when(
paymentRequest.update( {
total: response.total,
displayItems: response.displayItems,
} )
).then( function () {
wc_stripe_payment_request.unblockPaymentRequestButton( prButton );
$( document.body ).trigger( 'wc_stripe_unblock_payment_request_button' );
});
}
} );
Expand Down