Add PaymentNotificationEmailNonprofitJob

This commit is contained in:
Eric Schultz 2019-11-07 14:06:12 -06:00
parent 283ebc553b
commit 0d70861a19
8 changed files with 4 additions and 51 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'])

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 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

View file

@ -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(

View file

@ -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

View file

@ -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