feat(promotion-code): Complete promotion code integration and testing

- Add comprehensive promotion code methods to Order model
- Implement Stripe invoice integration for promotion code discounts
- Display promotion codes on invoice with proper discount breakdown
- Fix and enhance all unit tests for promotion code functionality
- Add discount calculation with capping to prevent negative totals
- Ensure promotion codes work across entire order lifecycle

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kbe
2025-09-29 20:33:54 +02:00
parent 87ccebf229
commit 635644b55a
7 changed files with 558 additions and 30 deletions

View File

@@ -96,7 +96,7 @@ class Order < ApplicationRecord
discount_total = promotion_codes.sum(:discount_amount_cents)
# Ensure total doesn't go below zero
final_total = [ticket_total - discount_total, 0].max
final_total = [ ticket_total - discount_total, 0 ].max
update!(total_amount_cents: final_total)
end
@@ -110,9 +110,9 @@ class Order < ApplicationRecord
subtotal_amount_cents / 100.0
end
# Total discount amount from all promotion codes
# Total discount amount from all promotion codes (capped at subtotal)
def discount_amount_cents
promotion_codes.sum(:discount_amount_cents)
[ promotion_codes.sum(:discount_amount_cents), subtotal_amount_cents ].min
end
# Discount amount in euros