Added refund create and recurring donation create

This commit is contained in:
Eric Schultz 2020-01-07 11:07:48 -06:00
parent 985f14688e
commit 31e4a69a22
4 changed files with 26 additions and 9 deletions

View file

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

View file

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

View file

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

View file

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