develop #3

Merged
kbe merged 227 commits from develop into main 2025-09-16 14:35:23 +00:00
Showing only changes of commit ec5095d372 - Show all commits

View File

@@ -178,9 +178,25 @@
<script src="https://js.stripe.com/v3/"></script> <script src="https://js.stripe.com/v3/"></script>
<script> <script>
// Wait for Stripe library to load and DOM to be ready
function initializeStripeCheckout() {
if (typeof Stripe === 'undefined') {
console.log('Waiting for Stripe library to load...');
setTimeout(initializeStripeCheckout, 100);
return;
}
console.log('Initializing Stripe with publishable key:', '<%= Rails.application.config.stripe[:publishable_key] %>');
const stripe = Stripe('<%= Rails.application.config.stripe[:publishable_key] %>'); const stripe = Stripe('<%= Rails.application.config.stripe[:publishable_key] %>');
document.getElementById('checkout-button').addEventListener('click', async function() { const checkoutButton = document.getElementById('checkout-button');
if (!checkoutButton) {
console.error('Checkout button not found');
return;
}
checkoutButton.addEventListener('click', async function() {
console.log('Checkout button clicked');
const button = this; const button = this;
button.disabled = true; button.disabled = true;
button.innerHTML = ` button.innerHTML = `
@@ -195,6 +211,7 @@
try { try {
// Increment payment attempt counter // Increment payment attempt counter
console.log('Incrementing payment attempt for order:', '<%= @order.id %>');
const response = await fetch('<%= increment_payment_attempt_order_path(@order) %>', { const response = await fetch('<%= increment_payment_attempt_order_path(@order) %>', {
method: 'POST', method: 'POST',
headers: { headers: {
@@ -204,9 +221,12 @@
}); });
if (!response.ok) { if (!response.ok) {
console.error('Payment attempt increment failed:', response.status, response.statusText);
throw new Error('Failed to increment payment attempt'); throw new Error('Failed to increment payment attempt');
} }
console.log('Payment attempt incremented successfully');
// Update button text for redirect // Update button text for redirect
button.innerHTML = ` button.innerHTML = `
<div class="flex items-center justify-center"> <div class="flex items-center justify-center">
@@ -219,6 +239,7 @@
`; `;
// Redirect to Stripe // Redirect to Stripe
console.log('Redirecting to Stripe with session ID:', '<%= @checkout_session&.id %>');
const stripeResult = await stripe.redirectToCheckout({ const stripeResult = await stripe.redirectToCheckout({
sessionId: '<%= @checkout_session.id %>' sessionId: '<%= @checkout_session.id %>'
}); });
@@ -228,6 +249,7 @@
} }
} catch (error) { } catch (error) {
console.error('Checkout error:', error);
// Reset button on error // Reset button on error
button.disabled = false; button.disabled = false;
button.innerHTML = ` button.innerHTML = `
@@ -241,6 +263,14 @@
alert('Erreur: ' + error.message); alert('Erreur: ' + error.message);
} }
}); });
}
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeStripeCheckout);
} else {
initializeStripeCheckout();
}
</script> </script>
</div> </div>
<% else %> <% else %>