2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
class DonationMailer < BaseMailer
|
2019-07-30 21:29:24 +00:00
|
|
|
# Used for both one-time and recurring donations
|
2018-03-25 17:30:42 +00:00
|
|
|
# can pass in array of admin user_ids to send to only some -- if falsey/empty, will send to all
|
2019-07-30 21:29:24 +00:00
|
|
|
def donor_payment_notification(donation_id, locale = I18n.locale)
|
|
|
|
@donation = Donation.find(donation_id)
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
if @donation.campaign && ActionView::Base.full_sanitizer.sanitize(@donation.campaign.receipt_message).present?
|
2018-03-25 17:30:42 +00:00
|
|
|
@thank_you_note = @donation.campaign.receipt_message
|
|
|
|
else
|
2019-07-30 21:29:24 +00:00
|
|
|
@thank_you_note = Format::Interpolate.with_hash(@nonprofit.thank_you_note, 'NAME' => @donation.supporter.name)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
@charge = @donation.charges.last
|
2019-07-30 21:29:24 +00:00
|
|
|
reply_to = @nonprofit.email.blank? ? @nonprofit.users.first.email : @nonprofit.email
|
2018-03-25 17:30:42 +00:00
|
|
|
from = Format::Name.email_from_np(@nonprofit.name)
|
|
|
|
I18n.with_locale(locale) do
|
2019-07-30 21:29:24 +00:00
|
|
|
mail(
|
|
|
|
to: @donation.supporter.email,
|
|
|
|
from: from,
|
|
|
|
reply_to: reply_to,
|
|
|
|
subject: I18n.t('mailer.donations.donor_direct_debit_notification.subject', nonprofit_name: @nonprofit.name)
|
|
|
|
)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def donor_direct_debit_notification(donation_id, locale = I18n.locale)
|
2018-03-25 17:30:42 +00:00
|
|
|
@donation = Donation.find(donation_id)
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
if @donation.campaign && ActionView::Base.full_sanitizer.sanitize(@donation.campaign.receipt_message).present?
|
2018-03-25 17:30:42 +00:00
|
|
|
@thank_you_note = @donation.campaign.receipt_message
|
|
|
|
else
|
2019-07-30 21:29:24 +00:00
|
|
|
@thank_you_note = Format::Interpolate.with_hash(@nonprofit.thank_you_note, 'NAME' => @donation.supporter.name)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
reply_to = @nonprofit.email.blank? ? @nonprofit.users.first.email : @nonprofit.email
|
|
|
|
from = Format::Name.email_from_np(@nonprofit.name)
|
|
|
|
I18n.with_locale(locale) do
|
|
|
|
mail(
|
|
|
|
to: @donation.supporter.email,
|
|
|
|
from: from,
|
|
|
|
reply_to: reply_to,
|
|
|
|
subject: I18n.t('mailer.donations.donor_direct_debit_notification.subject', nonprofit_name: @nonprofit.name)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# Used for both one-time and recurring donations
|
|
|
|
def nonprofit_payment_notification(donation_id, user_id = nil)
|
|
|
|
@donation = Donation.find(donation_id)
|
|
|
|
@charge = @donation.charges.last
|
|
|
|
@nonprofit = @donation.nonprofit
|
2018-03-25 17:30:42 +00:00
|
|
|
@emails = QueryUsers.nonprofit_user_emails(@nonprofit.id, @donation.campaign ? 'notify_campaigns' : 'notify_payments')
|
|
|
|
if user_id
|
|
|
|
em = User.find(user_id).email
|
|
|
|
# return unless @emails.include?(em)
|
|
|
|
@emails = [em]
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
mail(to: @emails, subject: "Donation receipt for #{@donation.supporter.name}")
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def nonprofit_failed_recurring_donation(donation_id)
|
2019-07-30 21:29:24 +00:00
|
|
|
@donation = Donation.find(donation_id)
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
@charge = @donation.charges.last
|
2018-03-25 17:30:42 +00:00
|
|
|
@emails = QueryUsers.nonprofit_user_emails(@nonprofit.id, @donation.campaign ? 'notify_campaigns' : 'notify_payments')
|
2019-07-30 21:29:24 +00:00
|
|
|
mail(to: @emails, subject: "Recurring donation payment failure for #{@donation.supporter.name || @donation.supporter.email}")
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def donor_failed_recurring_donation(donation_id)
|
2019-07-30 21:29:24 +00:00
|
|
|
@donation = Donation.find(donation_id)
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
@charge = @donation.charges.last
|
|
|
|
reply_to = @nonprofit.email.blank? ? @nonprofit.users.first.email : @nonprofit.email
|
2018-03-25 17:30:42 +00:00
|
|
|
from = Format::Name.email_from_np(@nonprofit.name)
|
2019-07-30 21:29:24 +00:00
|
|
|
mail(to: @donation.supporter.email, from: from, reply_to: reply_to, subject: "Donation payment failure for #{@nonprofit.name}")
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def nonprofit_recurring_donation_cancellation(donation_id)
|
2019-07-30 21:29:24 +00:00
|
|
|
@donation = Donation.find(donation_id)
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
@charge = @donation.charges.last
|
2018-03-25 17:30:42 +00:00
|
|
|
@emails = QueryUsers.nonprofit_user_emails(@nonprofit.id, @donation.campaign ? 'notify_campaigns' : 'notify_payments')
|
2019-07-30 21:29:24 +00:00
|
|
|
mail(to: @emails, subject: "Recurring donation cancelled for #{@donation.supporter.name || @donation.supporter.email}")
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def nonprofit_recurring_donation_change_amount(donation_id, previous_amount = nil)
|
|
|
|
@donation = RecurringDonation.find(donation_id).donation
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
@emails = QueryUsers.nonprofit_user_emails(@nonprofit.id, 'notify_recurring_donations')
|
|
|
|
@previous_amount = previous_amount
|
|
|
|
mail(to: @emails, subject: "Recurring donation amount changed for #{@donation.supporter.name || @donation.supporter.email}")
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def donor_recurring_donation_change_amount(donation_id, previous_amount = nil)
|
|
|
|
@donation = RecurringDonation.find(donation_id).donation
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
reply_to = @nonprofit.email.blank? ? @nonprofit.users.first.email : @nonprofit.email
|
|
|
|
if @nonprofit.miscellaneous_np_info && ActionView::Base.full_sanitizer.sanitize(@nonprofit.miscellaneous_np_info.change_amount_message).present?
|
|
|
|
@thank_you_note = @nonprofit.miscellaneous_np_info.change_amount_message
|
|
|
|
else
|
|
|
|
@thank_you_note = nil
|
|
|
|
end
|
|
|
|
from = Format::Name.email_from_np(@nonprofit.name)
|
|
|
|
@previous_amount = previous_amount
|
|
|
|
mail(to: @donation.supporter.email, from: from, reply_to: reply_to, subject: "Recurring donation amount changed for #{@nonprofit.name}")
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def nonprofit_recurring_donation_change_amount(donation_id, previous_amount = nil)
|
|
|
|
@donation = RecurringDonation.find(donation_id).donation
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
@emails = QueryUsers.nonprofit_user_emails(@nonprofit.id, 'notify_recurring_donations')
|
|
|
|
@previous_amount = previous_amount
|
|
|
|
mail(to: @emails, subject: "Recurring donation amount changed for #{@donation.supporter.name || @donation.supporter.email}")
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def donor_recurring_donation_change_amount(donation_id, previous_amount = nil)
|
|
|
|
@donation = RecurringDonation.find(donation_id).donation
|
|
|
|
@nonprofit = @donation.nonprofit
|
|
|
|
reply_to = @nonprofit.email.blank? ? @nonprofit.users.first.email : @nonprofit.email
|
|
|
|
if @nonprofit.miscellaneous_np_info && ActionView::Base.full_sanitizer.sanitize(@nonprofit.miscellaneous_np_info.change_amount_message).present?
|
|
|
|
@thank_you_note = @nonprofit.miscellaneous_np_info.change_amount_message
|
|
|
|
else
|
|
|
|
@thank_you_note = nil
|
|
|
|
end
|
|
|
|
from = Format::Name.email_from_np(@nonprofit.name)
|
|
|
|
@previous_amount = previous_amount
|
|
|
|
mail(to: @donation.supporter.email, from: from, reply_to: reply_to, subject: "Recurring donation amount changed for #{@nonprofit.name}")
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|