mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
update state transitions for new requires_authorization state
This commit is contained in:
@@ -137,7 +137,7 @@ class CheckoutController < ::BaseController
|
||||
|
||||
last_payment = OrderPaymentFinder.new(@order).last_payment
|
||||
@order.state == "payment" &&
|
||||
last_payment&.state == "pending" &&
|
||||
last_payment&.state == "requires_authorization" &&
|
||||
last_payment&.response_code == params["payment_intent"]
|
||||
end
|
||||
|
||||
|
||||
@@ -364,6 +364,7 @@ module Spree
|
||||
# These are both valid states to process the payment
|
||||
def pending_payments
|
||||
(payments.select(&:pending?) +
|
||||
payments.select(&:requires_authorization?) +
|
||||
payments.select(&:processing?) +
|
||||
payments.select(&:checkout?)).uniq
|
||||
end
|
||||
|
||||
@@ -57,11 +57,11 @@ module Spree
|
||||
state_machine initial: :checkout do
|
||||
# With card payments, happens before purchase or authorization happens
|
||||
event :started_processing do
|
||||
transition from: [:checkout, :pending, :completed, :processing], to: :processing
|
||||
transition from: [:checkout, :pending, :completed, :processing, :requires_authorization], to: :processing
|
||||
end
|
||||
# When processing during checkout fails
|
||||
event :failure do
|
||||
transition from: [:pending, :processing], to: :failed
|
||||
transition from: [:pending, :processing, :requires_authorization], to: :failed
|
||||
end
|
||||
# With card payments this represents authorizing the payment
|
||||
event :pend do
|
||||
@@ -69,7 +69,7 @@ module Spree
|
||||
end
|
||||
# With card payments this represents completing a purchase or capture transaction
|
||||
event :complete do
|
||||
transition from: [:processing, :pending, :checkout], to: :completed
|
||||
transition from: [:processing, :pending, :checkout, :requires_authorization], to: :completed
|
||||
end
|
||||
event :void do
|
||||
transition from: [:pending, :completed, :checkout], to: :void
|
||||
|
||||
@@ -26,7 +26,7 @@ class ProcessPaymentIntent
|
||||
def initialize(payment_intent, order)
|
||||
@payment_intent = payment_intent
|
||||
@order = order
|
||||
@payment = order.payments.pending.with_payment_intent(payment_intent).first
|
||||
@payment = order.payments.requires_authorization.with_payment_intent(payment_intent).first
|
||||
end
|
||||
|
||||
def call!
|
||||
|
||||
@@ -17,7 +17,7 @@ describe ProcessPaymentIntent do
|
||||
cvv_response_message: "https://stripe.com/redirect",
|
||||
response_code: "pi_123",
|
||||
order: order,
|
||||
state: "pending")
|
||||
state: "requires_authorization")
|
||||
}
|
||||
let(:validator) { instance_double(Stripe::PaymentIntentValidator) }
|
||||
|
||||
@@ -41,7 +41,7 @@ describe ProcessPaymentIntent do
|
||||
|
||||
it "does not complete the payment" do
|
||||
service.call!
|
||||
expect(payment.reload.state).to eq("pending")
|
||||
expect(payment.reload.state).to eq("requires_authorization")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ describe ProcessPaymentIntent do
|
||||
|
||||
it "does not complete the payment" do
|
||||
service.call!
|
||||
expect(payment.reload.state).to eq("pending")
|
||||
expect(payment.reload.state).to eq("requires_authorization")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -171,9 +171,9 @@ describe ProcessPaymentIntent do
|
||||
expect(result.error).to eq(I18n.t("payment_could_not_complete"))
|
||||
end
|
||||
|
||||
it "does not complete the payment" do
|
||||
it "does fails the payment" do
|
||||
service.call!
|
||||
expect(payment.reload.state).to eq("pending")
|
||||
expect(payment.reload.state).to eq("failed")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user