Sha256: 7dc510f185a4c9f062d705e78af3dd2eacfff81a535b5cd63823d3bf2c19503b

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require "pagarme"

module CatarsePagarme
  class ApplicationController < ActionController::Base

    before_filter :authenticate_user!
    before_filter :configure_pagarme
    layout :false

    protected
    def configure_pagarme
      PagarMe.api_key = CatarsePagarme.configuration.api_key
    end

    def authenticate_user!
      unless defined?(current_user) && current_user
        raise Exception.new('invalid user')
      end
    end

    def permited_attrs(attributes)
      attrs = ActionController::Parameters.new(attributes)
      attrs.permit([
        slip_payment: [:payment_method, :amount, :postback_url,
                       customer: [:name, :email]
        ],
        user: [
          bank_account_attributes: [
            :name, :account, :account_digit, :agency,
            :agency_digit, :owner_name, :owner_document
          ]
        ]
      ])
    end

    def contribution
      conditions = {id: params[:id] }

      unless params[:controller] == 'catarse_pagarme/notifications'
        conditions.merge!({user_id: current_user.id}) unless current_user.admin
      end

      @contribution ||= PaymentEngines.find_payment(conditions)
    end

    def delegator
      contribution.pagarme_delegator
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
catarse_pagarme-2.5.1 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.5.0 app/controllers/catarse_pagarme/application_controller.rb