Implement bitcoin donations via BTCPay
This commit is contained in:
24
app/jobs/btcpay_check_donation_job.rb
Normal file
24
app/jobs/btcpay_check_donation_job.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class BtcpayCheckDonationJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(donation)
|
||||
return if donation.completed?
|
||||
|
||||
invoice = BtcpayManager::FetchInvoice.call(invoice_id: donation.btcpay_invoice_id)
|
||||
|
||||
case invoice["status"]
|
||||
when "Settled"
|
||||
# TODO use time from actual payment confirmation
|
||||
donation.paid_at = DateTime.now
|
||||
donation.payment_status = "settled"
|
||||
donation.save!
|
||||
# TODO send email
|
||||
when "Processing"
|
||||
re_enqueue_job(donation)
|
||||
end
|
||||
end
|
||||
|
||||
def re_enqueue_job(donation)
|
||||
self.class.set(wait: 20.seconds).perform_later(donation)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user