diff --git a/app/jobs/refund_notification_donor_email_job.rb b/app/jobs/refund_notification_donor_email_job.rb new file mode 100644 index 00000000..6a9d70c3 --- /dev/null +++ b/app/jobs/refund_notification_donor_email_job.rb @@ -0,0 +1,7 @@ +class RefundNotificationDonorEmailJob < ApplicationJob + queue_as :default + + def perform(refund) + UserMailer.refund_receipt(refund).deliver_now + end +end diff --git a/app/jobs/refund_notification_job.rb b/app/jobs/refund_notification_job.rb new file mode 100644 index 00000000..ec024089 --- /dev/null +++ b/app/jobs/refund_notification_job.rb @@ -0,0 +1,8 @@ +class RefundNotificationJob < ApplicationJob + queue_as :default + + def perform(refund) + RefundNotificationJobDonorEmail.perform_later(refund) + RefundNotificationJobNonprofitEmail.perform_later(refund) + end +end diff --git a/app/jobs/refund_notification_nonprofit_email_job.rb b/app/jobs/refund_notification_nonprofit_email_job.rb new file mode 100644 index 00000000..67efbeb0 --- /dev/null +++ b/app/jobs/refund_notification_nonprofit_email_job.rb @@ -0,0 +1,7 @@ +class RefundNotificationNonprofitEmailJob < ApplicationJob + queue_as :default + + def perform(*args) + # Do something later + end +end diff --git a/lib/insert/insert_refunds.rb b/lib/insert/insert_refunds.rb index aa589994..2e4ddc44 100644 --- a/lib/insert/insert_refunds.rb +++ b/lib/insert/insert_refunds.rb @@ -66,7 +66,7 @@ module InsertRefunds # Update original payment to increment its refund_total for any future refund attempts Qx.update(:payments).set("refund_total=refund_total + #{h['amount'].to_i}").ts.where(id: original_payment['id']).execute # Send the refund receipts in a delayed job - Delayed::Job.enqueue JobTypes::DonorRefundNotificationJob.new(refund_row['id']) + RefundNotificationJob.perform_later Refund.find(refund_row['id']) Delayed::Job.enqueue JobTypes::NonprofitRefundNotificationJob.new(refund_row['id']) { 'payment' => payment_row, 'refund' => refund_row } end diff --git a/lib/job_types/donor_refund_notification_job.rb b/lib/job_types/donor_refund_notification_job.rb deleted file mode 100644 index 1343427b..00000000 --- a/lib/job_types/donor_refund_notification_job.rb +++ /dev/null @@ -1,15 +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 DonorRefundNotificationJob < EmailJob - attr_reader :refund_id - def initialize(refund_id) - @refund_id = refund_id - end - - def perform - UserMailer.refund_receipt(@refund_id).deliver - end - end -end diff --git a/spec/lib/job_types/donor_refund_notification_job_spec.rb b/spec/lib/job_types/donor_refund_notification_job_spec.rb deleted file mode 100644 index 03431937..00000000 --- a/spec/lib/job_types/donor_refund_notification_job_spec.rb +++ /dev/null @@ -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::DonorRefundNotificationJob do - describe '.perform' do - it 'calls the correct active mailer' do - expect(UserMailer).to receive(:refund_receipt).with(1).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::DonorRefundNotificationJob.new(1) - job.perform - end - end -end