9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/spree/admin/payments_controller_decorator.rb', line 9
def create
invoke_callbacks(:create, :before)
@payment ||= @order.payments.build(object_params)
if @payment.payment_method.source_required?
if params[:card].present? && params[:card] != 'new'
@payment.source = @payment.payment_method.payment_source_class.find_by_id(params[:card])
end
elsif @payment.payment_source.is_a?(Spree::Gateway::BraintreeVzeroBase)
@payment.braintree_token = params[:payment_method_token]
@payment.braintree_nonce = params[:payment_method_nonce]
@payment.source = Spree::BraintreeCheckout.create!(admin_payment: true)
end
begin
if @payment.save
invoke_callbacks(:create, :after)
while @order.next; end
@payment.process! if @order.completed? && @payment.checkout?
flash[:success] = flash_message_for(@payment, :successfully_created)
redirect_to admin_order_payments_path(@order)
else
invoke_callbacks(:create, :fails)
flash[:error] = Spree.t(:payment_could_not_be_created)
render :new
end
rescue Spree::Core::GatewayError => e
invoke_callbacks(:create, :fails)
flash[:error] = e.message.to_s
redirect_to new_admin_order_payment_path(@order)
end
end
|