2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
shared_context 'payments for a payout' do
|
2019-07-30 21:29:24 +00:00
|
|
|
before(:each) { @expect_marked = { charges: [], disputes: [], refunds: [], payouts_records: [] } }
|
|
|
|
let(:all_payments) do
|
2018-03-25 17:30:42 +00:00
|
|
|
payment_with_charge_to_output
|
|
|
|
partial_refunded_payment
|
|
|
|
refunded_payment
|
|
|
|
disputed_payment
|
|
|
|
late_payment
|
|
|
|
paid_out_payment
|
|
|
|
paid_out_refund
|
|
|
|
paid_out_dispute
|
|
|
|
other_np_payment
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 1600
|
|
|
|
let(:payment_with_charge_to_output) do
|
2018-03-25 17:30:42 +00:00
|
|
|
p = create_marked_payment
|
|
|
|
create_marked_charge(payment: p, amount: 2000, fee: -400, status: 'available')
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 1100
|
|
|
|
let(:partial_refunded_payment) do
|
2018-03-25 17:30:42 +00:00
|
|
|
p = create_marked_payment
|
|
|
|
c = create_marked_charge(payment: p, amount: 2000, fee: -400, status: 'available')
|
|
|
|
|
|
|
|
refund_payment = create_marked_payment(gross_amount: -500, fee_total: 0, net_amount: -500)
|
|
|
|
create_marked_refund(charge: c, payment: refund_payment, amount: 500)
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 0
|
|
|
|
let(:refunded_payment) do
|
2018-03-25 17:30:42 +00:00
|
|
|
p = create_marked_payment
|
|
|
|
c = create_marked_charge(payment: p, amount: 2000, status: 'available')
|
|
|
|
refund_payment = create_marked_payment(gross_amount: -2000, fee_total: 400, net_amount: -1600)
|
|
|
|
create_marked_refund(charge: c, payment: refund_payment, amount: 2000, disbursed: false)
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 0
|
|
|
|
let(:disputed_payment) do
|
2018-03-25 17:30:42 +00:00
|
|
|
p = create_marked_payment
|
|
|
|
c = create_marked_charge(payment: p, amount: 2000, status: 'available')
|
|
|
|
|
|
|
|
p2 = create_marked_payment(gross_amount: -2000, fee_total: 400, net_amount: -1600)
|
|
|
|
create_marked_dispute(charge: c, payment: p2, gross_amount: 2000, status: 'lost')
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 1600
|
|
|
|
let(:late_payment) do
|
2018-03-25 17:30:42 +00:00
|
|
|
is_this_marked = Time.now.beginning_of_day <= date_for_marking.beginning_of_day
|
|
|
|
p = create_payment(date: Time.now, marked: is_this_marked)
|
|
|
|
c = create_charge(payment: p, amount: 2000, status: 'available', marked: is_this_marked)
|
|
|
|
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 0
|
|
|
|
let(:paid_out_payment) do
|
2018-03-25 17:30:42 +00:00
|
|
|
p = create_payment
|
|
|
|
c = create_charge(payment: p, amount: 2000, status: 'disbursed')
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 0
|
|
|
|
let(:paid_out_refund) do
|
2018-03-25 17:30:42 +00:00
|
|
|
p = create_payment
|
|
|
|
c = create_charge(payment: p, amount: 2000, status: 'disbursed')
|
|
|
|
refunded_payment = create_payment(gross_amount: -2000, fee_total: 400, net_amount: -1600)
|
|
|
|
refund = create_refund(payment: refunded_payment, disbursed: true)
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# net amount: 0
|
|
|
|
let(:paid_out_dispute) do
|
2018-03-25 17:30:42 +00:00
|
|
|
p = create_payment
|
|
|
|
c = create_charge(payment: p, amount: 2000, status: 'disbursed')
|
|
|
|
dispute_payment = create_payment(gross_amount: -2000, fee_total: 400, net_amount: -1600)
|
|
|
|
dispute = create_dispute(charge: c, payment: dispute_payment, gross_amount: 2000, status: 'lost_and_paid')
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:other_np_payment) do
|
2020-04-17 19:02:07 +00:00
|
|
|
p = create_payment(nonprofit: force_create(:fv_poverty))
|
2018-03-25 17:30:42 +00:00
|
|
|
create_charge(payment: p, amount: 2000, fee: -400, status: 'available')
|
|
|
|
return p
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def create_marked_payment(args = {})
|
2019-07-30 21:29:24 +00:00
|
|
|
create_payment(args.merge(marked: true))
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_payment(args = {})
|
|
|
|
expect_payment = args[:marked]
|
2019-07-30 21:29:24 +00:00
|
|
|
p = force_create(:payment, { nonprofit: np, date: Time.now - 1.day, gross_amount: 2000, fee_total: -400, net_amount: 1600 }.merge(args.except(:marked)))
|
|
|
|
@expect_marked[:payouts_records].push(p) if expect_payment
|
2018-03-25 17:30:42 +00:00
|
|
|
p
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_marked_refund(args = {})
|
2019-07-30 21:29:24 +00:00
|
|
|
create_refund(args.merge(marked: true))
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_refund(args = {})
|
|
|
|
expect_refund = args[:marked]
|
|
|
|
r = force_create(:refund, args.except(:marked))
|
2019-07-30 21:29:24 +00:00
|
|
|
@expect_marked[:refunds].push(r) if expect_refund
|
2018-03-25 17:30:42 +00:00
|
|
|
r
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_marked_charge(args = {})
|
2019-07-30 21:29:24 +00:00
|
|
|
create_charge(args.merge(marked: true))
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_charge(args = {})
|
|
|
|
expect_charge = args[:marked]
|
|
|
|
c = force_create(:charge, args.except(:marked))
|
2019-07-30 21:29:24 +00:00
|
|
|
@expect_marked[:charges].push(c) if expect_charge
|
2018-03-25 17:30:42 +00:00
|
|
|
c
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_marked_dispute(args = {})
|
2019-07-30 21:29:24 +00:00
|
|
|
create_dispute(args.merge(marked: true))
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_dispute(args = {})
|
|
|
|
expect_dispute = args[:marked]
|
|
|
|
d = force_create(:dispute, args.except(:marked))
|
2019-07-30 21:29:24 +00:00
|
|
|
@expect_marked[:disputes].push(d) if expect_dispute
|
2018-03-25 17:30:42 +00:00
|
|
|
d
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# provide let(date_for_marking)
|
|
|
|
end
|