Class: Spree::Admin::PaymentsController
Instance Method Summary
collapse
#set_user_language_locale_key
Instance Method Details
#create ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/spree/admin/payments_controller.rb', line 28
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?
@payment.process! if @payment.checkout?
else
while @order.next; end
end
flash[:success] = flash_message_for(@payment, :successfully_created)
redirect_to admin_order_payments_path(@order)
else
flash[:error] = t('spree.payment_could_not_be_created')
render :new
end
rescue Spree::Core::GatewayError => error
flash[:error] = error.message.to_s
redirect_to new_admin_order_payment_path(@order)
end
end
|
#fire ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/spree/admin/payments_controller.rb', line 57
def fire
return unless (event = params[:e]) && @payment.payment_source
event = "void_transaction" if event == "void"
if @payment.send("#{event}!")
flash[:success] = t('spree.payment_updated')
else
flash[:error] = t('spree.cannot_perform_operation')
end
rescue Spree::Core::GatewayError => ge
flash[:error] = ge.message.to_s
ensure
redirect_to admin_order_payments_path(@order)
end
|
#index ⇒ Object
18
19
20
21
22
|
# File 'app/controllers/spree/admin/payments_controller.rb', line 18
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
24
25
26
|
# File 'app/controllers/spree/admin/payments_controller.rb', line 24
def new
@payment = @order.payments.build(amount: @order.outstanding_balance)
end
|