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 NonprofitMailer < BaseMailer
def failed_verification_notice ( np )
@nonprofit = np
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_payouts' )
2020-06-10 22:31:47 +00:00
mail ( to : @emails , subject : " We need some further account verification on #{ Houdini . general . name } " )
2018-03-25 17:30:42 +00:00
end
def successful_verification_notice ( np )
@nonprofit = np
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_payouts' )
2020-06-10 22:31:47 +00:00
mail ( to : @emails , subject : " Verification successful on #{ Houdini . general . name } ! " )
2018-03-25 17:30:42 +00:00
end
2019-07-30 21:29:24 +00:00
def refund_notification ( refund_id )
@refund = Refund . find ( refund_id )
@charge = @refund . charge
@nonprofit = @refund . payment . nonprofit
2018-03-25 17:30:42 +00:00
@supporter = @refund . payment . supporter
2019-07-30 21:29:24 +00:00
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_payments' )
mail ( to : @emails , subject : " A new refund has been made for $ #{ Format :: Currency . cents_to_dollars ( @refund . amount ) } " )
end
def new_bank_account_notification ( ba )
@nonprofit = ba . nonprofit
@bank_account = ba
@emails = QueryUsers . all_nonprofit_user_emails ( @nonprofit . id )
mail ( to : @emails , subject : 'We need to confirm the new bank account' )
end
def pending_payout_notification ( payout_id )
@payout = Payout . find ( payout_id )
@nonprofit = @payout . nonprofit
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_payouts' )
mail ( to : @emails , subject : 'Payout of available balance now pending' )
end
def successful_payout_notification ( payout )
@nonprofit = payout . nonprofit
@payout = payout
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_payouts' )
mail ( to : @emails , subject : 'Payout of available balance succeeded' )
end
def failed_payout_notification ( payout )
@nonprofit = payout . nonprofit
@payout = payout
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_payouts' )
mail ( to : @emails , subject : 'Payout could not be completed' )
end
def failed_recurring_donation ( recurring_donation )
@recurring_donation = recurring_donation
@nonprofit = recurring_donation . nonprofit
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_recurring_donations' )
mail ( to : @emails , subject : 'A recurring donation from one of your supporters had a payment failure.' )
end
def cancelled_recurring_donation ( recurring_donation )
@recurring_donation = recurring_donation
@nonprofit = recurring_donation . nonprofit
@emails = QueryUsers . nonprofit_user_emails ( @nonprofit . id , 'notify_recurring_donations' )
mail ( to : @emails , subject : 'A recurring donation from one of your supporters was cancelled.' )
end
def verified_notification ( nonprofit )
@nonprofit = nonprofit
@emails = QueryUsers . all_nonprofit_user_emails ( @nonprofit . id )
mail ( to : @emails , subject : 'Your nonprofit has been verified!' )
end
def button_code ( nonprofit , to_email , to_name , from_email , message , code )
@nonprofit = nonprofit
@to_email = to_email
@to_name = to_name
@from = from_email
@message = message
@code = code
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 : to_email , from : from , reply_to : from_email , subject : 'Please include this donate button code on the website' )
end
2018-03-25 17:30:42 +00:00
def invoice_payment_notification ( nonprofit_id , payment )
@nonprofit = Nonprofit . find ( nonprofit_id )
@payment = payment
@emails = QueryUsers . all_nonprofit_user_emails ( @nonprofit . id , [ :nonprofit_admin ] )
@month_name = Date :: MONTHNAMES [ payment . date . month ]
2020-06-10 22:31:47 +00:00
mail ( to : @emails , subject : " #{ Houdini . general . name } Subscription Receipt for #{ @month_name } " )
2018-03-25 17:30:42 +00:00
end
2019-07-30 21:29:24 +00:00
# pass in all of:
# {is_unsubscribed_from_emails, supporter_email, message, email_unsubscribe_uuid, nonprofit_id, from_email, subject}
def supporter_message ( args )
return if args [ :is_unsubscribed_from_emails ] || args [ :supporter_email ] . blank?
@message = args [ :message ]
@uuid = args [ :email_unsubscribe_uuid ]
@nonprofit = Nonprofit . find args [ :nonprofit_id ]
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 : args [ :supporter_email ] , reply_to : args [ :from_email ] , from : from , subject : args [ :subject ] )
end
2018-03-25 17:30:42 +00:00
def setup_verification ( np_id )
@nonprofit = Nonprofit . find ( np_id )
@emails = QueryUsers . all_nonprofit_user_emails ( np_id , [ :nonprofit_admin ] )
2020-06-10 22:31:47 +00:00
mail ( to : @emails , reply_to : 'support@commitchange.com' , from : " #{ Houdini . general . name } Support " , subject : " Set up automatic payouts on #{ Houdini . general . name } " )
2018-03-25 17:30:42 +00:00
end
def welcome ( np_id )
@nonprofit = Nonprofit . find ( np_id )
@user = @nonprofit . users . first
@token = @user . make_confirmation_token!
@emails = QueryUsers . all_nonprofit_user_emails ( np_id , [ :nonprofit_admin ] )
2020-06-10 22:31:47 +00:00
mail ( to : @emails , reply_to : 'support@commitchange.com' , from : " #{ Houdini . general . name } Support " , subject : " A hearty welcome from the #{ Houdini . general . name } team " )
2018-03-25 17:30:42 +00:00
end
end