Sha256: 002f102977cb78ffc48fee199920fb49bfeb0c1be78ea801fd74d8d359950aab

Contents?: true

Size: 1.34 KB

Versions: 32

Compression:

Stored size: 1.34 KB

Contents

require "pagarme"

module CatarsePagarme
  class ApplicationController < ActionController::Base

    before_filter :authenticate_user!
    before_filter :configure_pagarme
    helper_method :payment
    layout :false

    protected
    def metadata_attributes
      {
        key: payment.generate_key,
        contribution_id: payment.contribution.id
      }
    end

    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
      @contribution ||= PaymentEngines.find_contribution(params[:id])
    end

    def payment
      attributes = {contribution: contribution, value: contribution.value}
      @payment ||= PaymentEngines.new_payment(attributes)
    end

    def delegator
      payment.pagarme_delegator
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
catarse_pagarme-2.9.6 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.9.5 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.9.4 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.9.3 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.9.2 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.9.0 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.10 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.9 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.8 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.7 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.6 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.5 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.4 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.3 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.2 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.1 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.8.0 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.7.15 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.7.14 app/controllers/catarse_pagarme/application_controller.rb
catarse_pagarme-2.7.13 app/controllers/catarse_pagarme/application_controller.rb