develop #3

Merged
kbe merged 227 commits from develop into main 2025-09-16 14:35:23 +00:00
7 changed files with 79 additions and 24 deletions
Showing only changes of commit 0ede98efa4 - Show all commits

View File

@@ -270,6 +270,19 @@ class OrdersController < ApplicationController
} }
end end
# Add service fee as a separate line item
line_items << {
price_data: {
currency: "eur",
product_data: {
name: "Frais de service",
description: "Frais de traitement de la commande"
},
unit_amount: 100 # 1€ in cents
},
quantity: 1
}
Stripe::Checkout::Session.create( Stripe::Checkout::Session.create(
payment_method_types: [ "card" ], payment_method_types: [ "card" ],
line_items: line_items, line_items: line_items,

View File

@@ -88,9 +88,11 @@ class Order < ApplicationRecord
end end
end end
# Calculate total from tickets # Calculate total from tickets plus 1€ service fee
def calculate_total! def calculate_total!
update!(total_amount_cents: tickets.sum(:price_cents)) ticket_total = tickets.sum(:price_cents)
fee_cents = 100 # 1€ in cents
update!(total_amount_cents: ticket_total + fee_cents)
end end
# Create Stripe invoice for accounting records # Create Stripe invoice for accounting records

View File

@@ -118,10 +118,20 @@
<!-- Order Total --> <!-- Order Total -->
<div class="border-t border-gray-200 pt-6"> <div class="border-t border-gray-200 pt-6">
<div class="flex items-center justify-between text-lg"> <div class="space-y-2">
<div class="flex items-center justify-between">
<span class="text-gray-600">Sous-total</span>
<span class="text-gray-900"><%= @order.total_amount_euros - 1.0 %>€</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600">Frais de service</span>
<span class="text-gray-900">1.00€</span>
</div>
<div class="flex items-center justify-between text-lg pt-2 border-t border-gray-200">
<span class="font-medium text-gray-900">Total</span> <span class="font-medium text-gray-900">Total</span>
<span class="font-bold text-2xl text-purple-600"><%= @order.total_amount_euros %>€</span> <span class="font-bold text-2xl text-purple-600"><%= @order.total_amount_euros %>€</span>
</div> </div>
</div>
<p class="text-xs text-gray-500 mt-2">TVA incluse</p> <p class="text-xs text-gray-500 mt-2">TVA incluse</p>
</div> </div>
</div> </div>

View File

@@ -130,13 +130,23 @@
<!-- Total --> <!-- Total -->
<div class="border-t border-gray-200 pt-6 mt-6"> <div class="border-t border-gray-200 pt-6 mt-6">
<div class="flex items-center justify-between text-lg"> <div class="space-y-2">
<div class="flex items-center justify-between">
<span class="text-gray-600">Sous-total</span>
<span class="text-gray-900"><%= @order.total_amount_euros - 1.0 %>€</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600">Frais de service</span>
<span class="text-gray-900">1.00€</span>
</div>
<div class="flex items-center justify-between text-lg pt-2 border-t border-gray-200">
<span class="font-medium text-gray-900">Total à payer</span> <span class="font-medium text-gray-900">Total à payer</span>
<span class="font-bold text-2xl text-red-600"> <span class="font-bold text-2xl text-red-600">
<%= @order.total_amount_euros %>€ <%= @order.total_amount_euros %>€
</span> </span>
</div> </div>
</div> </div>
</div>
<% end %> <% end %>
</div> </div>

View File

@@ -125,7 +125,16 @@
<!-- Total --> <!-- Total -->
<div class="border-t border-gray-200 pt-6 mt-6"> <div class="border-t border-gray-200 pt-6 mt-6">
<div class="flex items-center justify-between text-lg"> <div class="space-y-2">
<div class="flex items-center justify-between">
<span class="text-gray-600">Sous-total</span>
<span class="text-gray-900"><%= @order.total_amount_euros - 1.0 %>€</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600">Frais de service</span>
<span class="text-gray-900">1.00€</span>
</div>
<div class="flex items-center justify-between text-lg pt-2 border-t border-gray-200">
<span class="font-medium text-gray-900">Total payé</span> <span class="font-medium text-gray-900">Total payé</span>
<span class="font-bold text-2xl text-green-600"> <span class="font-bold text-2xl text-green-600">
<%= @order.total_amount_euros %>€ <%= @order.total_amount_euros %>€
@@ -133,6 +142,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<!-- Actions & Ticket Access --> <!-- Actions & Ticket Access -->
<div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 h-fit"> <div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 h-fit">

View File

@@ -135,7 +135,16 @@
<!-- Total --> <!-- Total -->
<div class="border-t border-gray-200 pt-6 mt-6"> <div class="border-t border-gray-200 pt-6 mt-6">
<div class="flex items-center justify-between text-lg"> <div class="space-y-2">
<div class="flex items-center justify-between">
<span class="text-gray-600">Sous-total</span>
<span class="text-gray-900"><%= @order.total_amount_euros - 1.0 %>€</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600">Frais de service</span>
<span class="text-gray-900">1.00€</span>
</div>
<div class="flex items-center justify-between text-lg pt-2 border-t border-gray-200">
<span class="font-medium text-gray-900">Total <%= @order.status == 'paid' || @order.status == 'completed' ? 'payé' : 'à payer' %></span> <span class="font-medium text-gray-900">Total <%= @order.status == 'paid' || @order.status == 'completed' ? 'payé' : 'à payer' %></span>
<span class="font-bold text-2xl <%= @order.status == 'paid' || @order.status == 'completed' ? 'text-green-600' : 'text-purple-600' %>"> <span class="font-bold text-2xl <%= @order.status == 'paid' || @order.status == 'completed' ? 'text-green-600' : 'text-purple-600' %>">
<%= @order.total_amount_euros %>€ <%= @order.total_amount_euros %>€
@@ -143,6 +152,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<!-- Actions & Ticket Access --> <!-- Actions & Ticket Access -->
<div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 h-fit"> <div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 h-fit">
@@ -226,7 +236,7 @@
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg> </svg>
Retour au Tableau de Bord Retour au tableau de bord
</div> </div>
<% end %> <% end %>
<%= link_to event_path(@order.event.slug, @order.event), class: "block w-full text-center py-3 px-4 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors" do %> <%= link_to event_path(@order.event.slug, @order.event), class: "block w-full text-center py-3 px-4 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors" do %>
@@ -234,7 +244,7 @@
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg> </svg>
Voir l'Événement Complet Voir la page d'évenement
</div> </div>
<% end %> <% end %>
</div> </div>

View File

@@ -469,7 +469,7 @@ class OrderTest < ActiveSupport::TestCase
assert_equal "active", ticket2.status assert_equal "active", ticket2.status
end end
test "calculate_total! should sum ticket prices" do test "calculate_total! should sum ticket prices plus 1€ service fee" do
order = Order.create!( order = Order.create!(
user: @user, event: @event, total_amount_cents: 0, user: @user, event: @event, total_amount_cents: 0,
status: "draft", payment_attempts: 0 status: "draft", payment_attempts: 0
@@ -506,7 +506,7 @@ class OrderTest < ActiveSupport::TestCase
order.calculate_total! order.calculate_total!
order.reload order.reload
assert_equal 3000, order.total_amount_cents # 2 tickets * 1500 cents assert_equal 3100, order.total_amount_cents # 2 tickets * 1500 cents + 100 cents (1€ fee)
end end
# === Stripe Integration Tests (Mock) === # === Stripe Integration Tests (Mock) ===