38 lines
890 B
Ruby
38 lines
890 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 "Processing"
|
|
re_enqueue_job(donation)
|
|
when "Settled"
|
|
mark_as_paid(donation)
|
|
when "Expired"
|
|
if invoice["additionalStatus"] &&
|
|
invoice["additionalStatus"] == "PaidLate"
|
|
mark_as_paid(donation)
|
|
end
|
|
end
|
|
end
|
|
|
|
def re_enqueue_job(donation)
|
|
self.class.set(wait: 20.seconds).perform_later(donation)
|
|
end
|
|
|
|
def mark_as_paid(donation)
|
|
donation.paid_at = DateTime.now
|
|
donation.payment_status = "settled"
|
|
donation.save!
|
|
|
|
NotificationMailer.with(user: donation.user)
|
|
.bitcoin_donation_confirmed
|
|
.deliver_later
|
|
end
|
|
end
|