5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/jobs/munificent/payment_assignment_job.rb', line 5
def perform(payment_id, provider:)
payment = Payment.find(payment_id)
donation = case provider
when :stripe
Donation.find_by(stripe_payment_intent_id: payment.stripe_payment_intent_id)
when :paypal
Donation.find_by(paypal_order_id: payment.paypal_order_id)
end
if donation.nil?
Rails.logger.info "Missing donation for `#{payment.stripe_payment_intent_id}`"
return
end
payment.update(donation:) unless payment.donation == donation
if donation.pending?
donation.confirm_payment!
DonatorBundleAssignmentJob.perform_later(donation.donator_id)
NotificationsMailer.donation_received(donation.donator).deliver_later if defined?(NotificationsMailer)
end
end
|