Combine SendAuthorizationEmails and StripeScaPaymentAuthorize

This commit is contained in:
Matt-Yorkley
2021-12-16 17:13:16 +00:00
parent fd94f26765
commit bbdbf387b7
4 changed files with 26 additions and 30 deletions

View File

@@ -88,9 +88,7 @@ class SubscriptionConfirmJob < ActiveJob::Base
def authorize_payment!(order)
return if order.subscription.payment_method.class != Spree::Gateway::StripeSCA
OrderManagement::Order::StripeScaPaymentAuthorize.new(order).
extend(OrderManagement::Order::SendAuthorizationEmails).
call!
OrderManagement::Order::StripeScaPaymentAuthorize.new(order, off_session: true).call!
end
def send_confirmation_email(order)

View File

@@ -1,16 +0,0 @@
# frozen_string_literal: true
module OrderManagement
module Order
module SendAuthorizationEmails
def call!(redirect_url = full_order_path(@order))
super(redirect_url)
return unless @payment.requires_authorization?
PaymentMailer.authorize_payment(@payment).deliver_now
PaymentMailer.authorization_required(@payment).deliver_now
end
end
end
end

View File

@@ -5,9 +5,10 @@ module OrderManagement
class StripeScaPaymentAuthorize
include FullUrlHelper
def initialize(order)
def initialize(order, off_session: false)
@order = order
@payment = OrderPaymentFinder.new(@order).last_pending_payment
@off_session = off_session
end
def call!(redirect_url = full_order_path(@order))
@@ -19,8 +20,15 @@ module OrderManagement
@order.errors.add(:base, I18n.t('authorization_failure'))
end
@payment
return @payment unless @payment.requires_authorization? && off_session
PaymentMailer.authorize_payment(@payment).deliver_now
PaymentMailer.authorization_required(@payment).deliver_now
end
private
attr_reader :off_session
end
end
end

View File

@@ -70,15 +70,6 @@ module OrderManagement
}
end
it "sends an email requesting authorization and an email notifying the shop owner when requested" do
payment_authorize.extend(OrderManagement::Order::SendAuthorizationEmails).call!
expect(order.errors.size).to eq 0
expect(PaymentMailer).to have_received(:authorize_payment)
expect(PaymentMailer).to have_received(:authorization_required)
expect(mail_mock).to have_received(:deliver_now).twice
end
it "doesn't send emails by default" do
payment_authorize.call!
@@ -87,6 +78,21 @@ module OrderManagement
expect(PaymentMailer).to_not have_received(:authorization_required)
expect(mail_mock).to_not have_received(:deliver_now)
end
context "when the processing is off-session (via backoffice/subscription)" do
let(:payment_authorize) {
OrderManagement::Order::StripeScaPaymentAuthorize.new(order, off_session: true)
}
it "sends an email requesting authorization and an email notifying the shop owner when requested" do
payment_authorize.call!
expect(order.errors.size).to eq 0
expect(PaymentMailer).to have_received(:authorize_payment)
expect(PaymentMailer).to have_received(:authorization_required)
expect(mail_mock).to have_received(:deliver_now).twice
end
end
end
end
end