Class: Spree::Admin::PaymentsController
- Inherits:
-
BaseController
- Object
- BaseController
- BaseController
- Spree::Admin::PaymentsController
- Defined in:
- app/controllers/spree/admin/payments_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/spree/admin/payments_controller.rb', line 22 def create @payment = PaymentCreate.new(@order, object_params).build if @payment.payment_method.source_required? && params[:card].present? && params[:card] != 'new' @payment.source = @payment.payment_method.payment_source_class.find_by_id(params[:card]) end begin if @payment.save if @order.completed? # If the order was already complete then go ahead and process the payment # (auth and/or capture depending on payment method configuration) @payment.process! if @payment.checkout? else # Transition order as far as it will go. while @order.next; end end flash[:success] = (@payment, :successfully_created) redirect_to admin_order_payments_path(@order) else flash[:error] = Spree.t(:payment_could_not_be_created) render :new end rescue Spree::Core::GatewayError => e flash[:error] = e..to_s redirect_to new_admin_order_payment_path(@order) end end |
#fire ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/spree/admin/payments_controller.rb', line 51 def fire return unless (event = params[:e]) && @payment.payment_source # Because we have a transition method also called void, we do this to avoid conflicts. event = "void_transaction" if event == "void" if @payment.send("#{event}!") flash[:success] = Spree.t(:payment_updated) else flash[:error] = Spree.t(:cannot_perform_operation) end rescue Spree::Core::GatewayError => ge flash[:error] = ge..to_s ensure redirect_to admin_order_payments_path(@order) end |
#index ⇒ Object
12 13 14 15 16 |
# File 'app/controllers/spree/admin/payments_controller.rb', line 12 def index @payments = @order.payments.includes(refunds: :reason) @refunds = @payments.flat_map(&:refunds) redirect_to new_admin_order_payment_url(@order) if @payments.empty? end |
#new ⇒ Object
18 19 20 |
# File 'app/controllers/spree/admin/payments_controller.rb', line 18 def new @payment = @order.payments.build end |