Class: Spree::Admin::PaymentsController

Inherits:
BaseController show all
Defined in:
app/controllers/spree/admin/payments_controller.rb

Instance Method Summary collapse

Methods included from Core::ControllerHelpers::Common

included

Methods included from Core::ControllerHelpers::Auth

#current_ability, included, #redirect_back_or_default, #store_location, #try_spree_current_user, #unauthorized

Instance Method Details

#createObject



21
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
50
51
# File 'app/controllers/spree/admin/payments_controller.rb', line 21

def create
  @payment = @order.payments.build(object_params)
  if @payment.payment_method.is_a?(Spree::Gateway) && @payment.payment_method.payment_profiles_supported? && params[:card].present? and params[:card] != 'new'
    @payment.source = CreditCard.find_by_id(params[:card])
  end

  begin
    unless @payment.save
      respond_with(@payment) { |format| format.html { redirect_to admin_order_payments_path(@order) } }
      return
    end

    if @order.completed?
      @payment.process!
      flash[:success] = flash_message_for(@payment, :successfully_created)

      respond_with(@payment) { |format| format.html { redirect_to admin_order_payments_path(@order) } }
    else
      #This is the first payment (admin created order)
      until @order.completed?
        @order.next!
      end
      flash[:success] = t(:new_order_completed)
      respond_with(@payment) { |format| format.html { redirect_to admin_order_url(@order) } }
    end

  rescue Spree::Core::GatewayError => e
    flash[:error] = "#{e.message}"
    respond_with(@payment) { |format| format.html { redirect_to new_admin_order_payment_path(@order) } }
  end
end

#fireObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/spree/admin/payments_controller.rb', line 53

def fire
  return unless event = params[:e] and @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] = t(:payment_updated)
  else
    flash[:error] = t(:cannot_perform_operation)
  end
rescue Spree::Core::GatewayError => ge
  flash[:error] = "#{ge.message}"
ensure
  respond_with(@payment) { |format| format.html { redirect_to admin_order_payments_path(@order) } }
end

#indexObject



10
11
12
13
14
# File 'app/controllers/spree/admin/payments_controller.rb', line 10

def index
  @payments = @order.payments

  respond_with(@payments)
end

#newObject



16
17
18
19
# File 'app/controllers/spree/admin/payments_controller.rb', line 16

def new
  @payment = @order.payments.build
  respond_with(@payment)
end