Skip to content

Commit

Permalink
resetting card selection when loaded so the UI will not get stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Sosnowski committed Nov 26, 2024
1 parent d86b74e commit 4999c30
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Application/views/frontend/tpl/stripecreditcard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
let displayErrorBox = document.getElementById('stripe_creditcard_error_box');
let displayError = document.getElementById('stripe_creditcard_error');
debugger
cardElement.mount('#stripeCardElement');
cardElement.on('change', ({error}) => {
let stripeUsedCard = '';
Expand Down Expand Up @@ -109,16 +109,32 @@
document.getElementById('stripe_token_id').value = result.token.id;
paymentForm.submit();
}
});
})
.catch(function(error) {
console.error('Stripe token creation failed:', error);
displayError.textContent = 'Payment processing failed. Please try again.';
displayErrorBox.style.display = 'block';
});
;
}
});
}
//Activating card details form after load if stripe card is selected
document.addEventListener('DOMContentLoaded', function() {
$('#payment_stripecreditcard').is(':checked') && !$('#payment_stripecreditcard').parents('dt').next('dd').is(':visible') ?
$('#payment_stripecreditcard').trigger('click')
: false;
const $stripeRadio = $('#payment_stripecreditcard');
const $stripeCardDD = $stripeRadio.parents('dt').next('dd');
const $stripeUsedCardSelect = $stripeCardDD.find('#stripe_used_card');
// Ensure Stripe credit card payment option is expanded if selected
if ($stripeRadio.is(':checked') && !$stripeCardDD.is(':visible')) {
$stripeRadio.trigger('click');
}
// Reset used card selection when Stripe is selected
if ($stripeRadio.is(':checked')) {
$stripeUsedCardSelect.prop('selectedIndex', 0);
}
});
Expand Down

0 comments on commit 4999c30

Please sign in to comment.