Add some payment record maintainance code
This commit is contained in:
parent
ea22a24e9a
commit
45f8923382
1 changed files with 24 additions and 0 deletions
24
lib/maintain/maintain_payment_records.rb
Normal file
24
lib/maintain/maintain_payment_records.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
module MaintainPaymentRecords
|
||||||
|
# For records which have no associated charge, refund, nonprofit, supporter, donation or a gross_amount
|
||||||
|
# The record is basically useless
|
||||||
|
def self.find_records_which_are_really_bad
|
||||||
|
Payment.includes(:charges).includes(:refund).where('payments.nonprofit_id IS NULL AND payments.supporter_id IS NULL AND payments.donation_id IS NULL AND payments.gross_amount IS NULL AND charges.id IS NULL AND refunds.id IS NULL')
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.set_payment_supporter_and_nonprofit_though_charge_refund(i)
|
||||||
|
p = Payment.includes(:refund => :charge).find(i)
|
||||||
|
p.supporter_id = p.refund.charge.supporter_id
|
||||||
|
p.nonprofit_id = p.refund.charge.nonprofit_id
|
||||||
|
p.refund.disbursed = true
|
||||||
|
p.refund.save!
|
||||||
|
p.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.delete_payment_and_offsite_payment_record(id)
|
||||||
|
p = Payment.includes(:offsite_payment).find(id)
|
||||||
|
if (p.offsite_payment)
|
||||||
|
p.offsite_payment.destroy
|
||||||
|
end
|
||||||
|
p.destroy
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue