Sha256: b134302bedfcb6036d4bbf4cb9d97aee06ab9914f0653ba0533bedf612a5cc81

Contents?: true

Size: 951 Bytes

Versions: 10

Compression:

Stored size: 951 Bytes

Contents

module Tienda
  class PaymentsController < ApplicationController

    before_filter { @order = Tienda::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: t('tienda.payments.create_notice')
      else
        redirect_to @order, alert: payment.errors.full_messages.to_sentence
      end
    end

    def destroy
      @payment.destroy
      redirect_to @order, notice: t('tienda.payments.destroy_notice')
    end

    def refund
      if request.post?
        @payment.refund!(params[:amount])
        redirect_to @order, notice: t('tienda.payments.refund_notice')
      else
        render layout: false
      end
    rescue Tienda::Errors::RefundFailed => e
      redirect_to @order, alert: e.message
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tienda-2.1.3 app/controllers/tienda/payments_controller.rb
tienda-2.1.2 app/controllers/tienda/payments_controller.rb
tienda-2.1.1 app/controllers/tienda/payments_controller.rb
tienda-2.1.0 app/controllers/tienda/payments_controller.rb
tienda-2.0.2 app/controllers/tienda/payments_controller.rb
tienda-2.0.1 app/controllers/tienda/payments_controller.rb
tienda-1.1.2 app/controllers/tienda/payments_controller.rb
tienda-1.1.1 app/controllers/tienda/payments_controller.rb
tienda-1.1.0 app/controllers/tienda/payments_controller.rb
tienda-1.0.0 app/controllers/tienda/payments_controller.rb