Skip to content
Draft
20 changes: 16 additions & 4 deletions app/legacy_lib/insert_activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,22 @@ def self.insert_tickets_expr
.add_join("events AS event", "event.id=tickets.event_id")
end

def self.for_refunds(payment_ids)
insert_refunds_expr
.and_where("payments.id IN ($ids)", ids: payment_ids)
.execute
def self.for_refunds(*payments)
payments.map do |payment|
refund = payment.refund
Activity.create(
attachment: payment,
supporter: payment.supporter,
nonprofit: payment.nonprofit,
kind: "Refund",
json_data: {
gross_amount: payment.gross_amount,
reason: refund.reason,
email: refund.user&.email
},
user: refund.user
)
end
end

def self.insert_refunds_expr
Expand Down
3 changes: 2 additions & 1 deletion app/legacy_lib/insert_refunds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def self.modern_refund(charge, h)

refund.create_misc_refund_info(is_modern: true, stripe_application_fee_refund_id: results[:stripe_app_fee_refund]&.id)

InsertActivities.for_refunds([payment.id])
InsertActivities.for_refunds(payment)

# Update original payment to increment its refund_total for any future refund attempts
original_payment.refund_total += h["amount"].to_i
original_payment.save!
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/insert/insert_refunds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"reason" => reason
}, charge_date: charge.created_at
).and_return(perform_stripe_refund_result)
expect(InsertActivities).to receive(:for_refunds)
expect(InsertActivities).to receive(:for_refunds).with(an_instance_of(Payment))
end

let!(:modern_refund_call) do
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/query/query_payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def generate_donation(h)
"charge" => charge.stripe_charge_id
}, charge_date: charge.created_at
).and_return(perform_stripe_refund_result)
expect(InsertActivities).to receive(:for_refunds)
expect(InsertActivities).to receive(:for_refunds).with(an_instance_of(Payment))
InsertRefunds.with_stripe(charge.attributes, {amount: 100}.with_indifferent_access)
}

Expand All @@ -196,7 +196,7 @@ def generate_donation(h)
"charge" => charge.stripe_charge_id
}, charge_date: charge.created_at
).and_return(perform_stripe_refund_result)
expect(InsertActivities).to receive(:for_refunds)
expect(InsertActivities).to receive(:for_refunds).with(an_instance_of(Payment))
InsertRefunds.with_stripe(charge.attributes, {amount: 50}.with_indifferent_access)
}

Expand Down Expand Up @@ -681,7 +681,7 @@ def generate_donation(h)
"charge" => charge.stripe_charge_id
}, charge_date: charge.created_at
).and_return(perform_stripe_refund_result)
expect(InsertActivities).to receive(:for_refunds)
expect(InsertActivities).to receive(:for_refunds).with(an_instance_of(Payment))
InsertRefunds.with_stripe(charge.attributes, {amount: 100}.with_indifferent_access)
}

Expand All @@ -693,7 +693,7 @@ def generate_donation(h)
"charge" => charge.stripe_charge_id
}, charge_date: charge.created_at
).and_return(perform_stripe_refund_result)
expect(InsertActivities).to receive(:for_refunds)
expect(InsertActivities).to receive(:for_refunds).with(an_instance_of(Payment))
InsertRefunds.with_stripe(charge.attributes, {amount: 50}.with_indifferent_access)
}

Expand Down Expand Up @@ -774,7 +774,7 @@ def generate_donation(h)
"charge" => charge.stripe_charge_id
}, charge_date: charge.created_at
).and_return(perform_stripe_refund_result)
expect(InsertActivities).to receive(:for_refunds)
expect(InsertActivities).to receive(:for_refunds).with(an_instance_of(Payment))
InsertRefunds.with_stripe(charge.attributes, {amount: 50}.with_indifferent_access)
}

Expand Down
Loading