From 0d70861a197e94fc5e341fb8c9448e3a0987cf94 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 7 Nov 2019 14:06:12 -0600 Subject: [PATCH] Add PaymentNotificationEmailNonprofitJob --- ...ayment_notification_email_nonprofit_job.rb | 4 ++-- app/mailers/payment_mailer.rb | 2 +- lib/insert/insert_donation.rb | 2 -- lib/insert/insert_recurring_donation.rb | 4 +--- .../nonprofit_payment_notification_job.rb | 16 -------------- lib/pay_recurring_donation.rb | 3 --- ...nonprofit_payment_notification_job_spec.rb | 22 ------------------- .../shared_rd_donation_value_context.rb | 2 -- 8 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 lib/job_types/nonprofit_payment_notification_job.rb delete mode 100644 spec/lib/job_types/nonprofit_payment_notification_job_spec.rb diff --git a/app/jobs/payment_notification_email_nonprofit_job.rb b/app/jobs/payment_notification_email_nonprofit_job.rb index 98c8d2f7..30d99c72 100644 --- a/app/jobs/payment_notification_email_nonprofit_job.rb +++ b/app/jobs/payment_notification_email_nonprofit_job.rb @@ -1,7 +1,7 @@ class PaymentNotificationEmailNonprofitJob < ApplicationJob queue_as :default - def perform(*args) - # Do something later + def perform(donation, user=nil) + DonationMailer.nonprofit_payment_notification(donation.id, user&.id).deliver_now end end diff --git a/app/mailers/payment_mailer.rb b/app/mailers/payment_mailer.rb index 7b0a1162..e44879ee 100644 --- a/app/mailers/payment_mailer.rb +++ b/app/mailers/payment_mailer.rb @@ -7,7 +7,7 @@ class PaymentMailer < BaseMailer def resend_admin_receipt(payment_id, user_id) payment = Payment.find(payment_id) if payment.kind == 'Donation' || payment.kind == 'RecurringDonation' - return Delayed::Job.enqueue JobTypes::NonprofitPaymentNotificationJob.new(payment.donation.id, user_id) + PaymentNotificationEmailNonprofitJob.perform_later(payment.donation, User.find(user_id)) elsif payment.kind == 'Ticket' return TicketMailer.receipt_admin(payment.donation.id, user_id).deliver end diff --git a/lib/insert/insert_donation.rb b/lib/insert/insert_donation.rb index 84637159..05d57b15 100644 --- a/lib/insert/insert_donation.rb +++ b/lib/insert/insert_donation.rb @@ -43,7 +43,6 @@ module InsertDonation result['donation'] = insert_donation(data, entities) update_donation_keys(result) result['activity'] = InsertActivities.for_one_time_donations([result['payment'].id]) - EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id) PaymentNotificationJob.perform_later result['donation'], entities[:supporter_id].locale QueueDonations.delay.execute_for_donation(result['donation'].id) result @@ -107,7 +106,6 @@ module InsertDonation update_donation_keys(result) DirectDebitCreateJob.perform_later(result['donation'].id, locale_for_supporter(result['donation'].supporter.id)) - EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id) QueueDonations.delay.execute_for_donation(result['donation'].id) # do this for making test consistent diff --git a/lib/insert/insert_recurring_donation.rb b/lib/insert/insert_recurring_donation.rb index 603ffa97..f48bdf5b 100644 --- a/lib/insert/insert_recurring_donation.rb +++ b/lib/insert/insert_recurring_donation.rb @@ -70,7 +70,6 @@ module InsertRecurringDonation result['activity'] = InsertActivities.for_recurring_donations([result['payment'].id]) end # Send receipts - EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id) PaymentNotificationJob.perform_later result['donation'], entities[:supporter_id].locale QueueDonations.delay.execute_for_donation(result['donation']['id']) result @@ -95,8 +94,7 @@ module InsertRecurringDonation InsertDonation.update_donation_keys(result) if result['payment'] - DonationMailer.delay.nonprofit_payment_notification(result['donation']['id']) - DonationMailer.delay.donor_direct_debit_notification(result['donation']['id'], locale_for_supporter(result['donation']['supporter_id'])) + DonorDirectDebitNotificationJob.perform_later(Donation.find(result['donation']['id']), locale_for_supporter(result['donation']['supporter_id']); QueueDonations.delay.execute_for_donation(result['donation']['id']) diff --git a/lib/job_types/nonprofit_payment_notification_job.rb b/lib/job_types/nonprofit_payment_notification_job.rb deleted file mode 100644 index 5d328e03..00000000 --- a/lib/job_types/nonprofit_payment_notification_job.rb +++ /dev/null @@ -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 NonprofitPaymentNotificationJob < EmailJob - attr_reader :donation_id, :user_id - def initialize(donation_id, user_id = nil) - @donation_id = donation_id - @user_id = user_id - end - - def perform - DonationMailer.nonprofit_payment_notification(@donation_id, @user_id).deliver - end - end -end diff --git a/lib/pay_recurring_donation.rb b/lib/pay_recurring_donation.rb index 1330113b..ec412b4b 100644 --- a/lib/pay_recurring_donation.rb +++ b/lib/pay_recurring_donation.rb @@ -95,7 +95,6 @@ module PayRecurringDonation .where('id=$id', id: rd_id).returning('*') ).first PaymentNotificationJob.perform_later donation, donation&.supporter&.locale || 'en' - Delayed::Job.enqueue JobTypes::NonprofitPaymentNotificationJob.new(rd['donation_id']) InsertActivities.for_recurring_donations([result['payment']['id']]) else result['recurring_donation'] = Psql.execute( @@ -147,8 +146,6 @@ module PayRecurringDonation .where('id=$id', id: rd_id).returning('*') ).first ## add PaymentNotificationJobHere - Delayed::Job.enqueue JobTypes::DonorPaymentNotificationJob.new(rd['donation_id']) - Delayed::Job.enqueue JobTypes::NonprofitPaymentNotificationJob.new(rd['donation_id']) InsertActivities.for_recurring_donations([result['payment']['id']]) else result['recurring_donation'] = Psql.execute( diff --git a/spec/lib/job_types/nonprofit_payment_notification_job_spec.rb b/spec/lib/job_types/nonprofit_payment_notification_job_spec.rb deleted file mode 100644 index 66efd7e0..00000000 --- a/spec/lib/job_types/nonprofit_payment_notification_job_spec.rb +++ /dev/null @@ -1,22 +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::NonprofitPaymentNotificationJob do - describe '.perform' do - it 'calls the correct active mailer' do - expect(DonationMailer).to receive(:nonprofit_payment_notification).with(1, nil).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::NonprofitPaymentNotificationJob.new(1) - job.perform - end - - it 'calls the correct active mailer, with user id' do - expect(DonationMailer).to receive(:nonprofit_payment_notification).with(1, 2).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::NonprofitPaymentNotificationJob.new(1, 2) - job.perform - end - end -end diff --git a/spec/support/contexts/shared_rd_donation_value_context.rb b/spec/support/contexts/shared_rd_donation_value_context.rb index f46a39ff..9510a40c 100644 --- a/spec/support/contexts/shared_rd_donation_value_context.rb +++ b/spec/support/contexts/shared_rd_donation_value_context.rb @@ -331,7 +331,6 @@ RSpec.shared_context :shared_rd_donation_value_context do result = m.call(*args) }.to have_enqueued_job(PaymentNotificationJob).with(result, supporter.local) @donation_id = result.id - expect_email_queued.with(JobTypes::NonprofitPaymentNotificationJob, @donation_id) expect(QueueDonations).to receive(:execute_for_donation).with(@donation_id) @@ -378,7 +377,6 @@ RSpec.shared_context :shared_rd_donation_value_context do @donation_id = result.id - expect_email_queued.with(JobTypes::NonprofitPaymentNotificationJob, @donation_id) expect(QueueDonations).to receive(:execute_for_donation).with(@donation_id) result end