Add PaymentNotificationJob

This commit is contained in:
Eric Schultz 2019-11-07 12:35:38 -06:00
parent fe7322c5da
commit ff1a8b92f5
10 changed files with 30 additions and 37 deletions

View file

@ -0,0 +1,7 @@
class PaymentNotificationEmailDonorJob < ApplicationJob
queue_as :default
def perform(donation, locale)
DonationMailer.donor_payment_notification(donation.id, locale).deliver_now
end
end

View file

@ -0,0 +1,7 @@
class PaymentNotificationEmailNonprofitJob < ApplicationJob
queue_as :default
def perform(*args)
# Do something later
end
end

View file

@ -0,0 +1,8 @@
class PaymentNotificationJob < ApplicationJob
queue_as :default
def perform(donation, locale)
PaymentNotificationEmailDonorJob.perform_later donation, locale
PaymentNotificaitonEmailNonprofitJob.
end
end

View file

@ -18,7 +18,7 @@ class PaymentMailer < BaseMailer
def resend_donor_receipt(payment_id) def resend_donor_receipt(payment_id)
payment = Payment.find(payment_id) payment = Payment.find(payment_id)
if payment.kind == 'Donation' || payment.kind == 'RecurringDonation' if payment.kind == 'Donation' || payment.kind == 'RecurringDonation'
Delayed::Job.enqueue JobTypes::DonorPaymentNotificationJob.new(payment.donation.id) PaymentNotificationEmailDonorJob.perform_later payment.donation
elsif payment.kind == 'Ticket' elsif payment.kind == 'Ticket'
return TicketMailer.followup(payment.tickets.pluck(:id), payment.charge.id).deliver return TicketMailer.followup(payment.tickets.pluck(:id), payment.charge.id).deliver
end end

View file

@ -44,7 +44,7 @@ module InsertDonation
update_donation_keys(result) update_donation_keys(result)
result['activity'] = InsertActivities.for_one_time_donations([result['payment'].id]) result['activity'] = InsertActivities.for_one_time_donations([result['payment'].id])
EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id) EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id)
EmailJobQueue.queue(JobTypes::DonorPaymentNotificationJob, result['donation'].id, entities[:supporter_id].locale) PaymentNotificationJob.perform_later result['donation'], entities[:supporter_id].locale
QueueDonations.delay.execute_for_donation(result['donation'].id) QueueDonations.delay.execute_for_donation(result['donation'].id)
result result
end end

View file

@ -71,7 +71,7 @@ module InsertRecurringDonation
end end
# Send receipts # Send receipts
EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id) EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id)
EmailJobQueue.queue(JobTypes::DonorPaymentNotificationJob, result['donation'].id, entities[:supporter_id].locale) PaymentNotificationJob.perform_later result['donation'], entities[:supporter_id].locale
QueueDonations.delay.execute_for_donation(result['donation']['id']) QueueDonations.delay.execute_for_donation(result['donation']['id'])
result result
end end

View file

@ -1,16 +0,0 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
module JobTypes
class DonorPaymentNotificationJob < EmailJob
attr_reader :donation_id
def initialize(donation_id, locale = I18n.locale)
@donation_id = donation_id
@locale = locale
end
def perform
DonationMailer.donor_payment_notification(@donation_id, @locale).deliver
end
end
end

View file

@ -94,7 +94,7 @@ module PayRecurringDonation
Qexpr.new.update(:recurring_donations, n_failures: 0) Qexpr.new.update(:recurring_donations, n_failures: 0)
.where('id=$id', id: rd_id).returning('*') .where('id=$id', id: rd_id).returning('*')
).first ).first
Delayed::Job.enqueue JobTypes::DonorPaymentNotificationJob.new(rd['donation_id']) PaymentNotificationJob.perform_later donation, donation&.supporter&.locale || 'en'
Delayed::Job.enqueue JobTypes::NonprofitPaymentNotificationJob.new(rd['donation_id']) Delayed::Job.enqueue JobTypes::NonprofitPaymentNotificationJob.new(rd['donation_id'])
InsertActivities.for_recurring_donations([result['payment']['id']]) InsertActivities.for_recurring_donations([result['payment']['id']])
else else
@ -146,6 +146,7 @@ module PayRecurringDonation
Qexpr.new.update(:recurring_donations, n_failures: 0) Qexpr.new.update(:recurring_donations, n_failures: 0)
.where('id=$id', id: rd_id).returning('*') .where('id=$id', id: rd_id).returning('*')
).first ).first
## add PaymentNotificationJobHere
Delayed::Job.enqueue JobTypes::DonorPaymentNotificationJob.new(rd['donation_id']) Delayed::Job.enqueue JobTypes::DonorPaymentNotificationJob.new(rd['donation_id'])
Delayed::Job.enqueue JobTypes::NonprofitPaymentNotificationJob.new(rd['donation_id']) Delayed::Job.enqueue JobTypes::NonprofitPaymentNotificationJob.new(rd['donation_id'])
InsertActivities.for_recurring_donations([result['payment']['id']]) InsertActivities.for_recurring_donations([result['payment']['id']])

View file

@ -1,15 +0,0 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper.rb'
describe JobTypes::DonorPaymentNotificationJob do
describe '.perform' do
it 'calls the correct active mailer' do
expect(DonationMailer).to receive(:donor_payment_notification).with(1, 2).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer }
job = JobTypes::DonorPaymentNotificationJob.new(1, 2)
job.perform
end
end
end

View file

@ -327,11 +327,12 @@ RSpec.shared_context :shared_rd_donation_value_context do
def before_each_success(expect_charge = true) def before_each_success(expect_charge = true)
expect(InsertDonation).to receive(:insert_donation).and_wrap_original do |m, *args| expect(InsertDonation).to receive(:insert_donation).and_wrap_original do |m, *args|
expect {
result = m.call(*args) result = m.call(*args)
}.to have_enqueued_job(PaymentNotificationJob).with(result, supporter.local)
@donation_id = result.id @donation_id = result.id
expect_email_queued.with(JobTypes::NonprofitPaymentNotificationJob, @donation_id) expect_email_queued.with(JobTypes::NonprofitPaymentNotificationJob, @donation_id)
expect_email_queued.with(JobTypes::DonorPaymentNotificationJob, @donation_id, supporter.locale)
expect(QueueDonations).to receive(:execute_for_donation).with(@donation_id) expect(QueueDonations).to receive(:execute_for_donation).with(@donation_id)
result result