diff --git a/app/listeners/credit_card_payment_listener.rb b/app/listeners/credit_card_payment_listener.rb index 20eec3ae..5563b1c7 100644 --- a/app/listeners/credit_card_payment_listener.rb +++ b/app/listeners/credit_card_payment_listener.rb @@ -7,6 +7,13 @@ class CreditCardPaymentListener end def recurring_donation_create(donation, locale, user=nil) - + if donation.payment_provider == :credit_card + PaymentNotificationEmailDonorJob.perform_later donation, locale + PaymentNotificationEmailNonprofitJob.perform_later donation, user + end + end + + def refund_create(refund) + RefundNotificationJob.perform_later refund end end diff --git a/lib/insert/insert_recurring_donation.rb b/lib/insert/insert_recurring_donation.rb index 6d4b00d9..343cc854 100644 --- a/lib/insert/insert_recurring_donation.rb +++ b/lib/insert/insert_recurring_donation.rb @@ -70,7 +70,7 @@ module InsertRecurringDonation result['activity'] = InsertActivities.for_recurring_donations([result['payment'].id]) end # Send receipts - PaymentNotificationJob.perform_later result['donation'], entities[:supporter_id].locale + HoudiniEventPublisher.call(:recurring_donation_create, result['donation'], entities[:supporter_id].locale) result end @@ -93,7 +93,7 @@ module InsertRecurringDonation InsertDonation.update_donation_keys(result) if result['payment'] - DonorDirectDebitNotificationJob.perform_later(Donation.find(result['donation']['id']), locale_for_supporter(result['donation']['supporter_id'])); + HoudiniEventPublisher.call(:recurring_donation_create, result['donation'], entities[:supporter_id].locale) { status: 200, json: result } end diff --git a/lib/insert/insert_refunds.rb b/lib/insert/insert_refunds.rb index 46fcd035..35f30b93 100644 --- a/lib/insert/insert_refunds.rb +++ b/lib/insert/insert_refunds.rb @@ -66,7 +66,7 @@ module InsertRefunds # Update original payment to increment its refund_total for any future refund attempts Qx.update(:payments).set("refund_total=refund_total + #{h['amount'].to_i}").ts.where(id: original_payment['id']).execute # Send the refund receipts in a delayed job - RefundNotificationJob.perform_later Refund.find(refund_row['id']) + HoudiniEventPublisher.call(:create_refund, Refund.find(refund_row['id'])) { 'payment' => payment_row, 'refund' => refund_row } 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 0f99f376..4cf74f43 100644 --- a/spec/support/contexts/shared_rd_donation_value_context.rb +++ b/spec/support/contexts/shared_rd_donation_value_context.rb @@ -375,8 +375,11 @@ RSpec.shared_context :shared_rd_donation_value_context do def process_event_donation(data = {}) pay_method = data[:sepa] ? direct_debit_detail : card - expect(HoudiniEventPublisher).to receive(:call).with(:donation_create,instance_of(Donation), supporter.locale ) - + unless (data[:recurring_donation]) + expect(HoudiniEventPublisher).to receive(:call).with(:donation_create,instance_of(Donation), supporter.locale ) + else + expect(HoudiniEventPublisher).to receive(:call).with(:recurring_donation_create,instance_of(Donation), supporter.locale ) + end result = yield expected = generate_expected(@donation_id, result['payment'].id, result['charge'].id, pay_method, supporter, nonprofit, @stripe_charge_id, event: event, recurring_donation_expected: data[:recurring_donation], recurring_donation: result['recurring_donation']) @@ -395,8 +398,11 @@ RSpec.shared_context :shared_rd_donation_value_context do def process_campaign_donation(data = {}) pay_method = data[:sepa] ? direct_debit_detail : card - expect(HoudiniEventPublisher).to receive(:call).with(:donation_create,instance_of(Donation), supporter.locale ) - + unless (data[:recurring_donation]) + expect(HoudiniEventPublisher).to receive(:call).with(:donation_create,instance_of(Donation), supporter.locale ) + else + expect(HoudiniEventPublisher).to receive(:call).with(:recurring_donation_create,instance_of(Donation), supporter.locale ) + end result = yield expected = generate_expected(@donation_id, result['payment'].id, result['charge'].id, pay_method, supporter, nonprofit, @stripe_charge_id, campaign: campaign, recurring_donation_expected: data[:recurring_donation], recurring_donation: result['recurring_donation']) @@ -413,7 +419,11 @@ RSpec.shared_context :shared_rd_donation_value_context do def process_general_donation(data = {}) pay_method = data[:sepa] ? direct_debit_detail : card - expect(HoudiniEventPublisher).to receive(:call).with(:donation_create,instance_of(Donation), supporter.locale ) + unless (data[:recurring_donation]) + expect(HoudiniEventPublisher).to receive(:call).with(:donation_create,instance_of(Donation), supporter.locale ) + else + expect(HoudiniEventPublisher).to receive(:call).with(:recurring_donation_create,instance_of(Donation), supporter.locale ) + end result = yield expect_payment = nil_or_true(data[:expect_payment]) expect_charge = nil_or_true(data[:expect_charge])