feat: Add promotion code functionality to ticket orders
This commit is contained in:
@@ -118,6 +118,16 @@
|
||||
<p class="text-sm text-gray-600">Procédez au paiement pour finaliser votre commande</p>
|
||||
</div>
|
||||
|
||||
<!-- Promotion Code Section -->
|
||||
<%= form_tag checkout_order_path(@order), method: :get, class: "mb-6" do %>
|
||||
<div class="flex items-center bg-gray-50 border border-gray-200 rounded-lg p-3">
|
||||
<%= text_field_tag :promotion_code, params[:promotion_code], class: "flex-1 border-none bg-transparent focus:ring-0 text-sm", placeholder: "Code promotionnel (optionnel)" %>
|
||||
<%= button_tag type: "submit", class: "ml-2 btn btn-secondary py-2 px-4 text-sm" do %>
|
||||
Appliquer
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @checkout_session.present? %>
|
||||
<!-- Stripe Checkout -->
|
||||
<div class="space-y-6">
|
||||
@@ -131,13 +141,13 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
id="checkout-button"
|
||||
data-order-id="<%= @order.id %>"
|
||||
data-increment-url="/api/v1/orders/<%= @order.id %>/increment_payment_attempt"
|
||||
data-session-id="<%= @checkout_session.id if @checkout_session.present? %>"
|
||||
class="w-full btn btn-primary py-4 px-6 rounded-xl transition-all duration-200 transform hover:scale-105 active:scale-95 shadow-lg hover:shadow-xl"
|
||||
>
|
||||
<button
|
||||
id="checkout-button"
|
||||
data-order-id="<%= @order.id %>"
|
||||
data-increment-url="/api/v1/orders/<%= @order.id %>/increment_payment_attempt"
|
||||
data-session-id="<%= @checkout_session.id if @checkout_session.present? %>"
|
||||
class="w-full btn btn-primary py-4 px-6 rounded-xl transition-all duration-200 transform hover:scale-105 active:scale-95 shadow-lg hover:shadow-xl"
|
||||
>
|
||||
<div class="flex items-center justify-center">
|
||||
<i data-lucide="credit-card" class="w-5 h-5 mr-2"></i>
|
||||
Payer <%= @order.total_amount_euros %>€
|
||||
@@ -194,16 +204,16 @@
|
||||
|
||||
try {
|
||||
// Increment payment attempt counter
|
||||
const orderId = checkoutButton.dataset.orderId;
|
||||
const incrementUrl = checkoutButton.dataset.incrementUrl;
|
||||
console.log('Incrementing payment attempt for order:', orderId);
|
||||
const response = await fetch(incrementUrl, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': document.querySelector('[name=csrf-token]').content
|
||||
}
|
||||
});
|
||||
const orderId = checkoutButton.dataset.orderId;
|
||||
const incrementUrl = checkoutButton.dataset.incrementUrl;
|
||||
console.log('Incrementing payment attempt for order:', orderId);
|
||||
const response = await fetch(incrementUrl, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': document.querySelector('[name=csrf-token]').content
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Payment attempt increment failed:', response.status, response.statusText);
|
||||
@@ -224,11 +234,11 @@
|
||||
`;
|
||||
|
||||
// Redirect to Stripe
|
||||
const sessionId = checkoutButton.dataset.sessionId;
|
||||
console.log('Redirecting to Stripe with session ID:', sessionId);
|
||||
const stripeResult = await stripe.redirectToCheckout({
|
||||
sessionId: sessionId
|
||||
});
|
||||
const sessionId = checkoutButton.dataset.sessionId;
|
||||
console.log('Redirecting to Stripe with session ID:', sessionId);
|
||||
const stripeResult = await stripe.redirectToCheckout({
|
||||
sessionId: sessionId
|
||||
});
|
||||
|
||||
if (stripeResult.error) {
|
||||
throw new Error(stripeResult.error.message);
|
||||
|
||||
Reference in New Issue
Block a user