refactor(pricing): implement hybrid fee model (€0.50 + 1.5%) deducted from promoter payout
- Remove 1€ fixed fee from orders and Stripe invoices - Add platform_fee_cents, promoter_payout_cents methods to Order model - Update views to show clean ticket totals without added fees - Update tests for new fee calculation logic - Update pricing docs with implemented model
This commit is contained in:
@@ -469,7 +469,7 @@ class OrderTest < ActiveSupport::TestCase
|
||||
assert_equal "active", ticket2.status
|
||||
end
|
||||
|
||||
test "calculate_total! should sum ticket prices plus 1€ service fee" do
|
||||
test "calculate_total! should sum ticket prices only (platform fee deducted from promoter payout)" do
|
||||
order = Order.create!(
|
||||
user: @user, event: @event, total_amount_cents: 0,
|
||||
status: "draft", payment_attempts: 0
|
||||
@@ -506,7 +506,80 @@ class OrderTest < ActiveSupport::TestCase
|
||||
order.calculate_total!
|
||||
order.reload
|
||||
|
||||
assert_equal 3100, order.total_amount_cents # 2 tickets * 1500 cents + 100 cents (1€ fee)
|
||||
assert_equal 3000, order.total_amount_cents # 2 tickets * 1500 cents (no service fee added to customer)
|
||||
end
|
||||
|
||||
test "platform_fee_cents should calculate €0.50 + 1.5% per ticket" do
|
||||
order = Order.create!(
|
||||
user: @user, event: @event, total_amount_cents: 0,
|
||||
status: "draft", payment_attempts: 0
|
||||
)
|
||||
|
||||
ticket_type1 = TicketType.create!(
|
||||
name: "Cheap Ticket",
|
||||
description: "Cheap ticket type",
|
||||
price_cents: 1000, # €10
|
||||
quantity: 10,
|
||||
sale_start_at: Time.current,
|
||||
sale_end_at: Time.current + 1.day,
|
||||
requires_id: false,
|
||||
event: @event
|
||||
)
|
||||
|
||||
ticket_type2 = TicketType.create!(
|
||||
name: "Expensive Ticket",
|
||||
description: "Expensive ticket type",
|
||||
price_cents: 5000, # €50
|
||||
quantity: 10,
|
||||
sale_start_at: Time.current,
|
||||
sale_end_at: Time.current + 1.day,
|
||||
requires_id: false,
|
||||
event: @event
|
||||
)
|
||||
|
||||
ticket1 = Ticket.create!(order: order, ticket_type: ticket_type1, status: "draft", first_name: "John", last_name: "Doe")
|
||||
ticket2 = Ticket.create!(order: order, ticket_type: ticket_type2, status: "draft", first_name: "Jane", last_name: "Doe")
|
||||
|
||||
expected_fee = (50 + (1000 * 0.015).to_i) + (50 + (5000 * 0.015).to_i) # 50+15 + 50+75 = 190
|
||||
assert_equal 190, order.platform_fee_cents
|
||||
end
|
||||
|
||||
test "promoter_payout_cents should be total minus platform fee" do
|
||||
order = Order.create!(
|
||||
user: @user, event: @event, total_amount_cents: 3000,
|
||||
status: "paid", payment_attempts: 0
|
||||
)
|
||||
|
||||
ticket_type = TicketType.create!(
|
||||
name: "Test Ticket",
|
||||
description: "Test ticket",
|
||||
price_cents: 1500,
|
||||
quantity: 10,
|
||||
sale_start_at: Time.current,
|
||||
sale_end_at: Time.current + 1.day,
|
||||
requires_id: false,
|
||||
event: @event
|
||||
)
|
||||
|
||||
Ticket.create!(order: order, ticket_type: ticket_type, status: "active", first_name: "John", last_name: "Doe")
|
||||
Ticket.create!(order: order, ticket_type: ticket_type, status: "active", first_name: "Jane", last_name: "Doe")
|
||||
|
||||
order.calculate_total! # Should still be 3000
|
||||
expected_payout = 3000 - (50 + (1500 * 0.015).to_i) * 2 # 3000 - (50+22.5≈22)*2 = 3000 - 144 = 2856
|
||||
assert_equal 2856, order.promoter_payout_cents
|
||||
end
|
||||
|
||||
test "platform_fee_euros should convert cents to euros" do
|
||||
order = Order.new(total_amount_cents: 0)
|
||||
# Assuming one €10 ticket: 50 + 150 = 200 cents = €2.00
|
||||
def order.platform_fee_cents; 200; end
|
||||
assert_equal 2.0, order.platform_fee_euros
|
||||
end
|
||||
|
||||
test "promoter_payout_euros should convert cents to euros" do
|
||||
order = Order.new(total_amount_cents: 10000)
|
||||
def order.platform_fee_cents; 500; end
|
||||
assert_equal 95.0, order.promoter_payout_euros
|
||||
end
|
||||
|
||||
# === Stripe Integration Tests (Mock) ===
|
||||
|
||||
@@ -151,7 +151,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
mock_invoice.stubs(:finalize_invoice).returns(mock_invoice)
|
||||
mock_invoice.expects(:pay)
|
||||
Stripe::Invoice.expects(:create).returns(mock_invoice)
|
||||
Stripe::InvoiceItem.expects(:create).twice # Once for tickets, once for service fee
|
||||
Stripe::InvoiceItem.expects(:create).once # Only for tickets, no service fee
|
||||
|
||||
result = @service.create_post_payment_invoice
|
||||
assert_not_nil result
|
||||
@@ -173,7 +173,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
mock_invoice.stubs(:finalize_invoice).returns(mock_invoice)
|
||||
mock_invoice.expects(:pay)
|
||||
Stripe::Invoice.expects(:create).returns(mock_invoice)
|
||||
Stripe::InvoiceItem.expects(:create).twice # Once for tickets, once for service fee
|
||||
Stripe::InvoiceItem.expects(:create).once # Only for tickets, no service fee
|
||||
|
||||
result = @service.create_post_payment_invoice
|
||||
assert_not_nil result
|
||||
@@ -261,7 +261,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
mock_invoice.expects(:pay)
|
||||
|
||||
Stripe::Invoice.expects(:create).with(expected_invoice_data).returns(mock_invoice)
|
||||
Stripe::InvoiceItem.expects(:create).twice # Once for tickets, once for service fee
|
||||
Stripe::InvoiceItem.expects(:create).once # Only for tickets, no service fee
|
||||
|
||||
result = @service.create_post_payment_invoice
|
||||
assert_not_nil result
|
||||
@@ -300,7 +300,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
})
|
||||
|
||||
Stripe::Invoice.expects(:create).returns(mock_invoice)
|
||||
Stripe::InvoiceItem.expects(:create).twice # Once for tickets, once for service fee
|
||||
Stripe::InvoiceItem.expects(:create).once # Only for tickets, no service fee
|
||||
mock_invoice.expects(:finalize_invoice).returns(mock_finalized_invoice)
|
||||
|
||||
result = @service.create_post_payment_invoice
|
||||
|
||||
Reference in New Issue
Block a user