Add PaymentNotificationJob
This commit is contained in:
parent
fe7322c5da
commit
ff1a8b92f5
10 changed files with 30 additions and 37 deletions
7
app/jobs/payment_notification_email_donor_job.rb
Normal file
7
app/jobs/payment_notification_email_donor_job.rb
Normal 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
|
7
app/jobs/payment_notification_email_nonprofit_job.rb
Normal file
7
app/jobs/payment_notification_email_nonprofit_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class PaymentNotificationEmailNonprofitJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(*args)
|
||||
# Do something later
|
||||
end
|
||||
end
|
8
app/jobs/payment_notification_job.rb
Normal file
8
app/jobs/payment_notification_job.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class PaymentNotificationJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(donation, locale)
|
||||
PaymentNotificationEmailDonorJob.perform_later donation, locale
|
||||
PaymentNotificaitonEmailNonprofitJob.
|
||||
end
|
||||
end
|
|
@ -18,7 +18,7 @@ class PaymentMailer < BaseMailer
|
|||
def resend_donor_receipt(payment_id)
|
||||
payment = Payment.find(payment_id)
|
||||
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'
|
||||
return TicketMailer.followup(payment.tickets.pluck(:id), payment.charge.id).deliver
|
||||
end
|
||||
|
|
|
@ -44,7 +44,7 @@ module InsertDonation
|
|||
update_donation_keys(result)
|
||||
result['activity'] = InsertActivities.for_one_time_donations([result['payment'].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)
|
||||
result
|
||||
end
|
||||
|
|
|
@ -71,7 +71,7 @@ module InsertRecurringDonation
|
|||
end
|
||||
# Send receipts
|
||||
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'])
|
||||
result
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -94,7 +94,7 @@ module PayRecurringDonation
|
|||
Qexpr.new.update(:recurring_donations, n_failures: 0)
|
||||
.where('id=$id', id: rd_id).returning('*')
|
||||
).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'])
|
||||
InsertActivities.for_recurring_donations([result['payment']['id']])
|
||||
else
|
||||
|
@ -146,6 +146,7 @@ module PayRecurringDonation
|
|||
Qexpr.new.update(:recurring_donations, n_failures: 0)
|
||||
.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']])
|
||||
|
|
|
@ -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
|
|
@ -327,11 +327,12 @@ RSpec.shared_context :shared_rd_donation_value_context do
|
|||
|
||||
def before_each_success(expect_charge = true)
|
||||
expect(InsertDonation).to receive(:insert_donation).and_wrap_original do |m, *args|
|
||||
result = m.call(*args)
|
||||
expect {
|
||||
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_email_queued.with(JobTypes::DonorPaymentNotificationJob, @donation_id, supporter.locale)
|
||||
expect(QueueDonations).to receive(:execute_for_donation).with(@donation_id)
|
||||
|
||||
result
|
||||
|
|
Loading…
Reference in a new issue