update state transitions for new requires_authorization state

This commit is contained in:
Andy Brett
2021-06-16 17:50:53 -07:00
parent dd0375aed4
commit b41302d5d8
5 changed files with 11 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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!

View File

@@ -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