don't send emails if auth required during checkout

This commit is contained in:
Andy Brett
2021-02-03 10:00:45 -08:00
parent 5160140d88
commit 5d2c612839
3 changed files with 13 additions and 3 deletions

View File

@@ -14,7 +14,8 @@ module Checkout
def path
return unless stripe_payment_method?
payment = OrderManagement::Order::StripeScaPaymentAuthorize.new(@order).call!(full_checkout_path)
payment = OrderManagement::Order::StripeScaPaymentAuthorize.new(@order).
call!(full_checkout_path, false)
raise if @order.errors.any?
field_with_url(payment)

View File

@@ -10,14 +10,14 @@ module OrderManagement
@payment = OrderPaymentFinder.new(@order).last_pending_payment
end
def call!(redirect_url = full_order_path(@order))
def call!(redirect_url = full_order_path(@order), send_emails = true)
return unless @payment&.checkout?
@payment.authorize!(redirect_url)
@order.errors.add(:base, I18n.t('authorization_failure')) unless @payment.pending?
if @payment.cvv_response_message.present?
if send_emails && @payment.cvv_response_message.present?
PaymentMailer.authorize_payment(@payment).deliver_now
PaymentMailer.authorization_required(@payment).deliver_now
end

View File

@@ -78,6 +78,15 @@ module OrderManagement
expect(PaymentMailer).to have_received(:authorization_required)
expect(mail_mock).to have_received(:deliver_now).twice
end
it "doesn't send emails if param is set to false" do
payment_authorize.call!(nil, false)
expect(order.errors.size).to eq 0
expect(PaymentMailer).to_not have_received(:authorize_payment)
expect(PaymentMailer).to_not have_received(:authorization_required)
expect(mail_mock).to_not have_received(:deliver_now)
end
end
end
end