diff --git a/app/mailers/payment_mailer.rb b/app/mailers/payment_mailer.rb index b0c4a4bbff..253d7b794a 100644 --- a/app/mailers/payment_mailer.rb +++ b/app/mailers/payment_mailer.rb @@ -7,8 +7,22 @@ class PaymentMailer < Spree::BaseMailer @payment = payment subject = I18n.t('spree.payment_mailer.authorize_payment.subject', distributor: @payment.order.distributor.name) - mail(to: payment.order.user.email, - from: from_address, - subject: subject) + I18n.with_locale valid_locale(@payment.order.user) do + mail(to: payment.order.user.email, + from: from_address, + subject: subject) + end + end + + def authorization_required(payment) + @payment = payment + shop_owner = @payment.order.distributor.owner + subject = I18n.t('spree.payment_mailer.authorization_required.subject', + order: @payment.order) + I18n.with_locale valid_locale(shop_owner) do + mail(to: shop_owner.email, + from: from_address, + subject: subject) + end end end diff --git a/app/views/payment_mailer/authorization_required.html.haml b/app/views/payment_mailer/authorization_required.html.haml new file mode 100644 index 0000000000..080a88de06 --- /dev/null +++ b/app/views/payment_mailer/authorization_required.html.haml @@ -0,0 +1,2 @@ += t('spree.payment_mailer.authorization_required.message', order_number: @payment.order.number) += link_to spree.edit_admin_order_url(@payment.order), spree.edit_admin_order_url(@payment.order) diff --git a/app/views/payment_mailer/authorization_required.text.haml b/app/views/payment_mailer/authorization_required.text.haml new file mode 100644 index 0000000000..b084ca2755 --- /dev/null +++ b/app/views/payment_mailer/authorization_required.text.haml @@ -0,0 +1,3 @@ += t('spree.payment_mailer.authorization_required.message', order_number: @payment.order.number) + += link_to spree.edit_admin_order_url(@payment.order), spree.edit_admin_order_url(@payment.order) diff --git a/config/locales/en.yml b/config/locales/en.yml index a39ac74bd8..d714884095 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3658,6 +3658,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using authorize_payment: subject: "Please authorize your payment to %{distributor} on OFN" instructions: "Your payment of %{amount} to %{distributor} requires additional authentication. Please visit the following URL to authorize your payment:" + authorization_required: + subject: "A payment requires authorization from the customer" + message: "A payment for order %{order_number} requires additional authorization from the customer. The customer has been notified via email and the payment will appear as pending until it is authorized." shipment_mailer: shipped_email: dear_customer: "Dear Customer," diff --git a/engines/order_management/app/services/order_management/subscriptions/stripe_sca_payment_authorize.rb b/engines/order_management/app/services/order_management/subscriptions/stripe_sca_payment_authorize.rb index 87b55889e8..5f6dea721c 100644 --- a/engines/order_management/app/services/order_management/subscriptions/stripe_sca_payment_authorize.rb +++ b/engines/order_management/app/services/order_management/subscriptions/stripe_sca_payment_authorize.rb @@ -17,6 +17,7 @@ module OrderManagement if @payment.cvv_response_message.present? PaymentMailer.authorize_payment(@payment).deliver_now + PaymentMailer.authorization_required(@payment).deliver_now end @payment diff --git a/engines/order_management/spec/services/order_management/subscriptions/stripe_sca_payment_authorize_spec.rb b/engines/order_management/spec/services/order_management/subscriptions/stripe_sca_payment_authorize_spec.rb index 4240ecc0e8..3bae4da0f4 100644 --- a/engines/order_management/spec/services/order_management/subscriptions/stripe_sca_payment_authorize_spec.rb +++ b/engines/order_management/spec/services/order_management/subscriptions/stripe_sca_payment_authorize_spec.rb @@ -63,18 +63,20 @@ module OrderManagement before do allow(PaymentMailer).to receive(:authorize_payment) { mail_mock } + allow(PaymentMailer).to receive(:authorization_required) { mail_mock } allow(payment).to receive(:authorize!) { payment.state = "pending" payment.cvv_response_message = "https://stripe.com/redirect" } end - it "adds sends an email requesting authorization" do + it "sends an email requesting authorization and an email notifying the shop owner" do payment_authorize.call! expect(order.errors.size).to eq 0 expect(PaymentMailer).to have_received(:authorize_payment) - expect(mail_mock).to have_received(:deliver_now) + expect(PaymentMailer).to have_received(:authorization_required) + expect(mail_mock).to have_received(:deliver_now).twice end end end diff --git a/spec/services/checkout/stripe_redirect_spec.rb b/spec/services/checkout/stripe_redirect_spec.rb index d85152ecbf..05b46dfe25 100644 --- a/spec/services/checkout/stripe_redirect_spec.rb +++ b/spec/services/checkout/stripe_redirect_spec.rb @@ -43,6 +43,7 @@ describe Checkout::StripeRedirect do stripe_payment.state = 'pending' true end + allow(stripe_payment.order).to receive(:distributor) { distributor } test_redirect_url = "http://stripe_auth_url/" allow(stripe_payment).to receive(:cvv_response_message).and_return(test_redirect_url)