fix(promotion code): Cap the minimum invoice for Stripe

Stripe does not support negative invoices, so to
allow correct invoice generation, we apply dismiss
negative invoices.
This commit is contained in:
kbe
2025-09-29 23:55:21 +02:00
parent 635644b55a
commit 66fffa8676
3 changed files with 351 additions and 62 deletions

View File

@@ -21,6 +21,9 @@ class Order < ApplicationRecord
validates :payment_attempts, presence: true,
numericality: { greater_than_or_equal_to: 0 }
# Custom validation to prevent duplicate promotion codes
validate :no_duplicate_promotion_codes
# Stripe invoice ID for accounting records
attr_accessor :stripe_invoice_id
@@ -188,4 +191,12 @@ class Order < ApplicationRecord
def draft?
status == "draft"
end
# Prevent duplicate promotion codes on the same order
def no_duplicate_promotion_codes
promotion_code_ids = promotion_codes.map(&:id)
if promotion_code_ids.size != promotion_code_ids.uniq.size
errors.add(:promotion_codes, "ne peuvent pas contenir de codes en double")
end
end
end