mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-22 05:18:51 +00:00
move controller and mailer outside of spree namespace; use haml in template
This commit is contained in:
29
app/controllers/payments_controller.rb
Normal file
29
app/controllers/payments_controller.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PaymentsController < BaseController
|
||||
ssl_required :redirect_to_authorize
|
||||
|
||||
respond_to :html
|
||||
|
||||
prepend_before_action :require_logged_in, only: :redirect_to_authorize
|
||||
|
||||
def redirect_to_authorize
|
||||
@payment = Spree::Payment.find(params[:id])
|
||||
authorize! :show, @payment
|
||||
|
||||
if url = @payment.cvv_response_message
|
||||
redirect_to url
|
||||
else
|
||||
redirect_to order_url(@payment.order)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_logged_in
|
||||
return if session[:access_token] || params[:token] || spree_current_user
|
||||
|
||||
flash[:error] = I18n.t("spree.orders.edit.login_to_view_order")
|
||||
redirect_to main_app.root_path(anchor: "login?after_login=#{request.env['PATH_INFO']}")
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PaymentsController < BaseController
|
||||
ssl_required :redirect_to_authorize
|
||||
|
||||
respond_to :html
|
||||
|
||||
prepend_before_action :require_logged_in, only: :redirect_to_authorize
|
||||
|
||||
def redirect_to_authorize
|
||||
@payment = Spree::Payment.find(params[:id])
|
||||
authorize! :show, @payment.order
|
||||
|
||||
if url = @payment.cvv_response_message
|
||||
redirect_to url
|
||||
else
|
||||
redirect_to order_url(@payment.order)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_logged_in
|
||||
return if session[:access_token] || params[:token] || spree_current_user
|
||||
|
||||
flash[:error] = I18n.t("spree.orders.edit.login_to_view_order")
|
||||
redirect_to main_app.root_path(anchor: "login?after_login=#{request.env['PATH_INFO']}")
|
||||
end
|
||||
end
|
||||
@@ -1,31 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class PaymentsController < Spree::StoreController
|
||||
ssl_required :redirect_to_authorize
|
||||
|
||||
respond_to :html
|
||||
|
||||
prepend_before_action :require_logged_in, only: :redirect_to_authorize
|
||||
|
||||
def redirect_to_authorize
|
||||
@payment = Spree::Payment.find(params[:id])
|
||||
authorize! :show, @payment
|
||||
|
||||
if url = @payment.cvv_response_message
|
||||
redirect_to url
|
||||
else
|
||||
redirect_to order_url(@payment.order)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_logged_in
|
||||
return if session[:access_token] || params[:token] || spree_current_user
|
||||
|
||||
flash[:error] = I18n.t("spree.orders.edit.login_to_view_order")
|
||||
redirect_to main_app.root_path(anchor: "login?after_login=#{request.env['PATH_INFO']}")
|
||||
end
|
||||
end
|
||||
end
|
||||
14
app/mailers/payment_mailer.rb
Normal file
14
app/mailers/payment_mailer.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PaymentMailer < Spree::BaseMailer
|
||||
include I18nHelper
|
||||
|
||||
def authorize_payment(payment)
|
||||
@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)
|
||||
end
|
||||
end
|
||||
@@ -1,16 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Spree
|
||||
class PaymentMailer < BaseMailer
|
||||
include I18nHelper
|
||||
|
||||
def authorize_payment(payment)
|
||||
@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)
|
||||
end
|
||||
end
|
||||
end
|
||||
3
app/views/payment_mailer/authorize_payment.text.haml
Normal file
3
app/views/payment_mailer/authorize_payment.text.haml
Normal file
@@ -0,0 +1,3 @@
|
||||
= t('.instructions', distributor: @payment.order.distributor.name, amount: @payment.display_amount)
|
||||
|
||||
= main_app.authorize_payment_url(@payment)
|
||||
@@ -1,2 +0,0 @@
|
||||
<%= t('.instructions', distributor: @payment.order.distributor.name, amount: @payment.display_amount) %>
|
||||
<%= main_app.authorize_payment_url(@payment) %>
|
||||
@@ -29,7 +29,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
patch "/cart", :to => "spree/orders#update", :as => :update_cart
|
||||
put "/cart/empty", :to => 'spree/orders#empty', :as => :empty_cart
|
||||
get '/orders/:id/token/:token' => 'spree/orders#show', :as => :token_order
|
||||
get '/payments/:id/authorize' => 'spree/payments#redirect_to_authorize', as: "authorize_payment"
|
||||
get '/payments/:id/authorize' => 'payments#redirect_to_authorize', as: "authorize_payment"
|
||||
|
||||
resource :cart, controller: "cart" do
|
||||
post :populate
|
||||
|
||||
Reference in New Issue
Block a user