Send email confirmation when BTC payment is confirmed
This commit is contained in:
parent
079ee8833c
commit
54220019bb
@ -4,15 +4,19 @@ class BtcpayCheckDonationJob < ApplicationJob
|
|||||||
def perform(donation)
|
def perform(donation)
|
||||||
return if donation.completed?
|
return if donation.completed?
|
||||||
|
|
||||||
invoice = BtcpayManager::FetchInvoice.call(invoice_id: donation.btcpay_invoice_id)
|
invoice = BtcpayManager::FetchInvoice.call(
|
||||||
|
invoice_id: donation.btcpay_invoice_id
|
||||||
|
)
|
||||||
|
|
||||||
case invoice["status"]
|
case invoice["status"]
|
||||||
when "Settled"
|
when "Settled"
|
||||||
# TODO use time from actual payment confirmation
|
|
||||||
donation.paid_at = DateTime.now
|
donation.paid_at = DateTime.now
|
||||||
donation.payment_status = "settled"
|
donation.payment_status = "settled"
|
||||||
donation.save!
|
donation.save!
|
||||||
# TODO send email
|
|
||||||
|
NotificationMailer.with(user: donation.user)
|
||||||
|
.bitcoin_donation_confirmed
|
||||||
|
.deliver_later
|
||||||
when "Processing"
|
when "Processing"
|
||||||
re_enqueue_job(donation)
|
re_enqueue_job(donation)
|
||||||
end
|
end
|
||||||
|
@ -23,4 +23,11 @@ class NotificationMailer < ApplicationMailer
|
|||||||
@subject = "New invitations added to your account"
|
@subject = "New invitations added to your account"
|
||||||
mail to: @user.email, subject: @subject
|
mail to: @user.email, subject: @subject
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bitcoin_donation_confirmed
|
||||||
|
@user = params[:user]
|
||||||
|
@donation = params[:donation]
|
||||||
|
@subject = "Donation confirmed"
|
||||||
|
mail to: @user.email, subject: @subject
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
Hi <%= @user.display_name.presence || @user.cn %>,
|
||||||
|
|
||||||
|
Your bitcoin donation has been confirmed successfully. <3
|
||||||
|
|
||||||
|
Thank you so much for helping us with keeping the lights on, as well as with continually improving our services for you!
|
||||||
|
|
||||||
|
You can find all of your past financial contributions on this page:
|
||||||
|
|
||||||
|
<%= contributions_donations_url %>
|
||||||
|
|
||||||
|
Have a nice day!
|
@ -6,12 +6,20 @@ RSpec.describe BtcpayCheckDonationJob, type: :job do
|
|||||||
|
|
||||||
let(:donation) do
|
let(:donation) do
|
||||||
user.donations.create!(
|
user.donations.create!(
|
||||||
donation_method: "btcpay", btcpay_invoice_id: "K4e31MhbLKmr3D7qoNYRd3",
|
donation_method: "btcpay",
|
||||||
|
btcpay_invoice_id: "K4e31MhbLKmr3D7qoNYRd3",
|
||||||
paid_at: nil, payment_status: "processing",
|
paid_at: nil, payment_status: "processing",
|
||||||
fiat_amount: 120, fiat_currency: "USD"
|
fiat_amount: 120, fiat_currency: "USD"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(User).to receive(:ldap_entry).and_return({
|
||||||
|
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
|
||||||
|
display_name: nil
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
clear_enqueued_jobs
|
clear_enqueued_jobs
|
||||||
clear_performed_jobs
|
clear_performed_jobs
|
||||||
@ -48,16 +56,24 @@ RSpec.describe BtcpayCheckDonationJob, type: :job do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "updates the donation record" do
|
it "updates the donation record" do
|
||||||
perform_enqueued_jobs { job }
|
perform_enqueued_jobs(only: described_class) { job }
|
||||||
|
|
||||||
donation.reload
|
donation.reload
|
||||||
expect(donation.paid_at).not_to be_nil
|
expect(donation.paid_at).not_to be_nil
|
||||||
expect(donation.payment_status).to eq("settled")
|
expect(donation.payment_status).to eq("settled")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "notifies the user via email" do
|
||||||
|
perform_enqueued_jobs(only: described_class) { job }
|
||||||
|
expect(enqueued_jobs.size).to eq(1)
|
||||||
|
job = enqueued_jobs.select{|j| j['job_class'] == "ActionMailer::MailDeliveryJob"}.first
|
||||||
|
expect(job['arguments'][0]).to eq('NotificationMailer')
|
||||||
|
expect(job['arguments'][1]).to eq('bitcoin_donation_confirmed')
|
||||||
|
expect(job['arguments'][3]['params']['user']['_aj_globalid']).to eq('gid://akkounts/User/1')
|
||||||
|
end
|
||||||
|
|
||||||
it "does not enqueue itself again" do
|
it "does not enqueue itself again" do
|
||||||
expect_any_instance_of(described_class).not_to receive(:re_enqueue_job)
|
expect_any_instance_of(described_class).not_to receive(:re_enqueue_job)
|
||||||
perform_enqueued_jobs { job }
|
perform_enqueued_jobs(only: described_class) { job }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user