WIP: Process payments for expired invoices #213
@ -84,21 +84,26 @@ class Contributions::DonationsController < ApplicationController
|
||||
@donation.paid_at = DateTime.now
|
||||
@donation.payment_status = "settled"
|
||||
@donation.save!
|
||||
flash_message = { success: "Thank you!" }
|
||||
msg = { success: "Thank you!" }
|
||||
when "Processing"
|
||||
unless @donation.processing?
|
||||
@donation.payment_status = "processing"
|
||||
@donation.save!
|
||||
flash_message = { success: "Thank you! We will send you an email when the payment is confirmed." }
|
||||
msg = { success: "Thank you! We will send you an email when the payment is confirmed." }
|
||||
BtcpayCheckDonationJob.set(wait: 20.seconds).perform_later(@donation)
|
||||
end
|
||||
when "Expired"
|
||||
flash_message = { warning: "The payment request for this donation has expired" }
|
||||
if invoice["additionalStatus"] &&
|
||||
invoice["additionalStatus"] == "PaidLate"
|
||||
# TODO introduce state machine
|
||||
mark_as_paid(donation)
|
||||
end
|
||||
msg = { warning: "The payment request for this donation has expired" }
|
||||
else
|
||||
flash_message = { warning: "Could not determine status of payment" }
|
||||
msg = { warning: "Could not determine status of payment" }
|
||||
end
|
||||
|
||||
redirect_to contributions_donations_url, flash: flash_message
|
||||
redirect_to contributions_donations_url, flash: msg
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -9,7 +9,23 @@ class BtcpayCheckDonationJob < ApplicationJob
|
||||
)
|
||||
|
||||
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!
|
||||
@ -17,12 +33,5 @@ class BtcpayCheckDonationJob < ApplicationJob
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user