27 lines
610 B
Ruby
27 lines
610 B
Ruby
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"
|
|
donation.complete!
|
|
|
|
NotificationMailer.with(user: donation.user)
|
|
.bitcoin_donation_confirmed
|
|
.deliver_later
|
|
when "Processing"
|
|
re_enqueue_job(donation)
|
|
end
|
|
end
|
|
|
|
def re_enqueue_job(donation)
|
|
self.class.set(wait: 20.seconds).perform_later(donation)
|
|
end
|
|
end
|