mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add failed payment email to StandingOrderMailer
This commit is contained in:
@@ -21,6 +21,11 @@ class StandingOrderMailer < Spree::BaseMailer
|
||||
send_mail(order)
|
||||
end
|
||||
|
||||
def failed_payment_email(order)
|
||||
@order = order
|
||||
send_mail(order)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send_mail(order)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
= render 'header', intro: t("email_so_failed_payment_intro_html")
|
||||
|
||||
%p.callout
|
||||
= t("email_so_failed_payment_explainer_html", distributor: @order.distributor.name)
|
||||
= t("email_so_edit_false_html",
|
||||
orders_close_at: l(@order.order_cycle.orders_close_at, format: "%a %b %d @ %l:%M%p"),
|
||||
order_url: spree.order_url(@order))
|
||||
= t("email_so_contact_distributor_html", distributor: @order.distributor.name, email: @order.distributor.email)
|
||||
|
||||
- if @order.errors.any?
|
||||
%p
|
||||
%h4
|
||||
= t :email_confirm_customer_number_html, number: @order.number
|
||||
%p
|
||||
= t("email_so_failed_payment_details_html", distributor: @order.distributor.name)
|
||||
- @order.errors.full_messages.each do |message|
|
||||
= message
|
||||
%br
|
||||
|
||||
= render 'spree/order_mailer/signoff'
|
||||
@@ -1234,6 +1234,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
email_so_empty_intro_html: "We tried to place a new order with <strong>%{distributor}</strong>, but had some problems..."
|
||||
email_so_empty_explainer_html: "Unfortunately, none of products that you ordered were available, so no order has been placed. The original quantities that you requested appear crossed-out below."
|
||||
email_so_empty_details_html: "Here are the details of the unplaced order for <strong>%{distributor}</strong>:"
|
||||
email_so_failed_payment_intro_html: "We tried to process a payment, but had some problems..."
|
||||
email_so_failed_payment_explainer_html: "The payment for your subscription with <strong>%{distributor}</strong> failed because of a problem with your credit card. <strong>%{distributor}</strong> has been notified of this failed payment."
|
||||
email_so_failed_payment_details_html: "Here are the details of the failure provided by the payment gateway:"
|
||||
email_shipping_delivery_details: Delivery details
|
||||
email_shipping_delivery_time: "Delivery on:"
|
||||
email_shipping_delivery_address: "Delivery address:"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe StandingOrderMailer do
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
|
||||
let!(:mail_method) { create(:mail_method, preferred_mails_from: 'spree@example.com') }
|
||||
|
||||
describe "order placement" do
|
||||
@@ -77,4 +79,28 @@ describe StandingOrderMailer do
|
||||
expect(body).to include "Unfortunately, none of products that you ordered were available"
|
||||
end
|
||||
end
|
||||
|
||||
describe "failed payment notification" do
|
||||
let(:standing_order) { create(:standing_order, with_items: true) }
|
||||
let(:proxy_order) { create(:proxy_order, standing_order: standing_order) }
|
||||
let!(:order) { proxy_order.initialise_order! }
|
||||
|
||||
before do
|
||||
order.errors.add(:base, "This is a payment failure error")
|
||||
|
||||
expect do
|
||||
StandingOrderMailer.failed_payment_email(order).deliver
|
||||
end.to change{StandingOrderMailer.deliveries.count}.by(1)
|
||||
end
|
||||
|
||||
it "sends the email" do
|
||||
body = strip_tags(StandingOrderMailer.deliveries.last.body.encoded)
|
||||
expect(body).to include I18n.t("email_so_failed_payment_intro_html")
|
||||
explainer = I18n.t("email_so_failed_payment_explainer_html", distributor: standing_order.shop.name)
|
||||
expect(body).to include strip_tags(explainer)
|
||||
details = I18n.t("email_so_failed_payment_details_html", distributor: standing_order.shop.name)
|
||||
expect(body).to include strip_tags(details)
|
||||
expect(body).to include "This is a payment failure error"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user