Simplify StripeScaPaymentAuthorize and clarify both return URL types (checkout and off-session)

This commit is contained in:
Matt-Yorkley
2021-12-16 23:10:10 +00:00
parent 7b8e1f5c30
commit 3f3bfadb59
4 changed files with 10 additions and 11 deletions

View File

@@ -175,8 +175,7 @@ module Spree
return unless @payment.payment_method.instance_of?(Spree::Gateway::StripeSCA)
OrderManagement::Order::StripeScaPaymentAuthorize.
new(@order, payment: @payment, off_session: true).
call!(full_order_path(@order))
new(@order, payment: @payment, off_session: true).call!
raise Spree::Core::GatewayError, I18n.t('authorization_failure') if @order.errors.any?

View File

@@ -10,8 +10,4 @@ module FullUrlHelper
def full_checkout_path
URI.join(url_helpers.root_url, url_helpers.checkout_path).to_s
end
def full_order_path(order)
URI.join(url_helpers.root_url, url_helpers.order_path(order)).to_s
end
end

View File

@@ -14,7 +14,7 @@ module Checkout
def path
return unless stripe_payment_method?
payment = payment_authorizer.call!(return_url)
payment = payment_authorizer.call!(checkout_return_url)
return if order.errors.any?
@@ -33,7 +33,7 @@ module Checkout
OrderManagement::Order::StripeScaPaymentAuthorize.new(order)
end
def return_url
def checkout_return_url
payment_gateways_confirm_stripe_url
end

View File

@@ -8,7 +8,7 @@
module OrderManagement
module Order
class StripeScaPaymentAuthorize
include FullUrlHelper
include Rails.application.routes.url_helpers
def initialize(order, payment: nil, off_session: false, notify_hub: false)
@order = order
@@ -17,10 +17,10 @@ module OrderManagement
@notify_hub = notify_hub
end
def call!(redirect_url = full_order_path(order))
def call!(return_url = off_session_return_url)
return unless payment&.checkout?
payment.authorize!(redirect_url)
payment.authorize!(return_url)
order.errors.add(:base, I18n.t('authorization_failure')) unless successfully_processed?
send_auth_emails if requires_authorization_emails?
@@ -44,6 +44,10 @@ module OrderManagement
PaymentMailer.authorize_payment(payment).deliver_now
PaymentMailer.authorization_required(payment).deliver_now if notify_hub
end
def off_session_return_url
order_url(order)
end
end
end
end