mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
add requires_authorization as a possible payment_state on Orders
This commit is contained in:
@@ -172,6 +172,8 @@ module OrderManagement
|
||||
'failed'
|
||||
elsif canceled_and_not_paid_for?
|
||||
'void'
|
||||
elsif requires_authorization?
|
||||
'requires_authorization'
|
||||
else
|
||||
infer_payment_state_from_balance
|
||||
end
|
||||
@@ -220,6 +222,10 @@ module OrderManagement
|
||||
|
||||
order.create_tax_charge!
|
||||
end
|
||||
|
||||
def requires_authorization?
|
||||
payments.requires_authorization.any? && payments.completed.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -150,6 +150,26 @@ module OrderManagement
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order has a payment that requires authorization" do
|
||||
let!(:payment) { create(:payment, order: order, state: "requires_authorization") }
|
||||
|
||||
it "returns requires_authorization" do
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
}.to change { order.payment_state }.to 'requires_authorization'
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order has a payment that requires authorization and a completed payment" do
|
||||
let!(:payment) { create(:payment, order: order, state: "requires_authorization") }
|
||||
let!(:completed_payment) { create(:payment, order: order, state: "completed") }
|
||||
|
||||
it "returns paid" do
|
||||
updater.update_payment_state
|
||||
expect(order.payment_state).to_not eq("requires_authorization")
|
||||
end
|
||||
end
|
||||
|
||||
context "payment total is greater than order total" do
|
||||
it "is credit_owed" do
|
||||
order.payment_total = 2
|
||||
@@ -203,6 +223,7 @@ module OrderManagement
|
||||
order.total = 30
|
||||
allow(order).to receive_message_chain(:payments, :valid, :empty?) { false }
|
||||
allow(order).to receive_message_chain(:payments, :completed, :empty?) { false }
|
||||
allow(order).to receive_message_chain(:payments, :requires_authorization, :any?) { false }
|
||||
|
||||
expect {
|
||||
updater.update_payment_state
|
||||
|
||||
Reference in New Issue
Block a user