Sha256: f9024ff7bba99a141163224a9c8a8c808ad75bda7b2e7e5464aa52eb1e0da2c1

Contents?: true

Size: 1003 Bytes

Versions: 8

Compression:

Stored size: 1003 Bytes

Contents

module Shoppe
  class PaymentsController < ApplicationController
    
    before_filter { @order = Shoppe::Order.find(params[:order_id]) }
    before_filter { params[:id] && @payment = @order.payments.find(params[:id]) }
    
    def create
      payment = @order.payments.build(params[:payment].permit(:amount, :method, :reference))
      if payment.save
        redirect_to @order, :notice => "Payment has been added successfully"
      else
        redirect_to @order, :alert => payment.errors.full_messages.to_sentence
      end
    end
    
    def destroy
      @payment.destroy
      redirect_to @order, :notice => "Payment has been removed successfully"
    end
    
    def refund
      if request.post?
        @payment.refund!(params[:amount])
        redirect_to @order, :notice => "Refund has been processed successfully."
      else
        render :layout => false
      end
    rescue Shoppe::Errors::RefundFailed => e
      redirect_to @order, :alert => e.message
    end
    
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shoppe-1.0.2 app/controllers/shoppe/payments_controller.rb
shoppe-1.0.1 app/controllers/shoppe/payments_controller.rb
shoppe-1.0.0 app/controllers/shoppe/payments_controller.rb
shoppe-0.0.21 app/controllers/shoppe/payments_controller.rb
shoppe-0.0.20 app/controllers/shoppe/payments_controller.rb
shoppe-0.0.19 app/controllers/shoppe/payments_controller.rb
shoppe-0.0.18 app/controllers/shoppe/payments_controller.rb
shoppe-0.0.17 app/controllers/shoppe/payments_controller.rb