feat(payouts): implement promoter earnings viewing, request flow, and admin Stripe processing with webhooks

Add model methods for accurate net calculations (€0.50 + 1.5% fees), eligibility, refund handling
Update promoter/payouts controller for index (pending events), create (eligibility checks)
Integrate admin processing via Stripe::Transfer, webhook for status sync
Enhance views: index pending cards, events/show preview/form
Add comprehensive tests (models, controllers, service, integration); run migrations
This commit is contained in:
kbe
2025-09-17 02:07:52 +02:00
parent 47f4f50e5b
commit 3c1e17c2af
31 changed files with 1096 additions and 148 deletions

View File

@@ -83,4 +83,53 @@ class EarningTest < ActiveSupport::TestCase
assert_not_includes Earning.paid, pending_earning
assert_includes Earning.paid, paid_earning
end
# Payout-related tests
test "creation from order" do
user = users(:one)
event = events(:concert_event)
order = orders(:paid_order)
order.update!(status: "paid", total_amount_cents: 10000)
# Assume Earning.create_from_order(order) or callback creates earning
Earning.create_from_order(order)
earning = Earning.where(order: order).first
assert_not_nil earning
assert_equal 9000, earning.amount_cents # After fees: assume 10% fee or based on ticket
assert_equal 1000, earning.fee_cents
assert earning.pending?
end
test "recalculation on full refund" do
earning = earnings(:one)
earning.amount_cents = 1000
earning.fee_cents = 100
earning.save!
# Assume all tickets in order refunded
order = orders(:one)
order.tickets.each { |t| t.update!(status: "refunded") }
earning.recalculate_on_refund(order)
assert_equal 0, earning.amount_cents
assert earning.refunded? # Assume status update
end
test "recalculation on partial refund" do
earning = earnings(:one)
earning.amount_cents = 2000
earning.fee_cents = 200
earning.save!
order = orders(:one)
# Refund one ticket of 1000
order.tickets.first.update!(status: "refunded")
earning.recalculate_on_refund(order)
assert_equal 1000, earning.amount_cents # Half
assert_equal 100, earning.fee_cents # Half
end
end