Module: Spree::Admin::PaymentsControllerDecorator

Defined in:
app/controllers/spree/admin/payments_controller_decorator.rb

Instance Method Summary collapse

Instance Method Details

#paypal_checkout_refundObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/spree/admin/payments_controller_decorator.rb', line 2

def paypal_checkout_refund
  if request.get?
    if @payment.source.state == 'refunded'
      flash[:error] = Spree.t(:already_refunded, :scope => 'paypal')
      redirect_to admin_order_payment_path(@order, @payment)
    end
  elsif request.post?
    response = @payment.payment_method.refund(@payment, params[:refund_amount])
    if response['status']=='COMPLETED'
      flash[:success] = Spree.t(:refund_successful, :scope => 'paypal')
      redirect_to admin_order_payments_path(@order)
    else
      flash.now[:error] = Spree.t(:refund_unsuccessful, :scope => 'paypal') + " (#{response.errors.first.long_message})"
      render
    end
  end
end