WIP Process payments for expired invoices
This commit is contained in:
parent
7df56479a4
commit
aca13a25c3
@ -84,21 +84,26 @@ class Contributions::DonationsController < ApplicationController
|
|||||||
@donation.paid_at = DateTime.now
|
@donation.paid_at = DateTime.now
|
||||||
@donation.payment_status = "settled"
|
@donation.payment_status = "settled"
|
||||||
@donation.save!
|
@donation.save!
|
||||||
flash_message = { success: "Thank you!" }
|
msg = { success: "Thank you!" }
|
||||||
when "Processing"
|
when "Processing"
|
||||||
unless @donation.processing?
|
unless @donation.processing?
|
||||||
@donation.payment_status = "processing"
|
@donation.payment_status = "processing"
|
||||||
@donation.save!
|
@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)
|
BtcpayCheckDonationJob.set(wait: 20.seconds).perform_later(@donation)
|
||||||
end
|
end
|
||||||
when "Expired"
|
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
|
else
|
||||||
flash_message = { warning: "Could not determine status of payment" }
|
msg = { warning: "Could not determine status of payment" }
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to contributions_donations_url, flash: flash_message
|
redirect_to contributions_donations_url, flash: msg
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -9,20 +9,29 @@ class BtcpayCheckDonationJob < ApplicationJob
|
|||||||
)
|
)
|
||||||
|
|
||||||
case invoice["status"]
|
case invoice["status"]
|
||||||
when "Settled"
|
|
||||||
donation.paid_at = DateTime.now
|
|
||||||
donation.payment_status = "settled"
|
|
||||||
donation.save!
|
|
||||||
|
|
||||||
NotificationMailer.with(user: donation.user)
|
|
||||||
.bitcoin_donation_confirmed
|
|
||||||
.deliver_later
|
|
||||||
when "Processing"
|
when "Processing"
|
||||||
re_enqueue_job(donation)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def re_enqueue_job(donation)
|
def re_enqueue_job(donation)
|
||||||
self.class.set(wait: 20.seconds).perform_later(donation)
|
self.class.set(wait: 20.seconds).perform_later(donation)
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user