mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
Combine SendAuthorizationEmails and StripeScaPaymentAuthorize
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user