Sha256: 5376c6ef6ea911310adf71bb90f7a36efc88d6544c0a429ddbe29d719375143b

Contents?: true

Size: 1.27 KB

Versions: 68

Compression:

Stored size: 1.27 KB

Contents

module CatarsePagarme::BankAccountConcern
  extend ActiveSupport::Concern

  included do

    validate :must_be_valid_on_pagarme

    def must_be_valid_on_pagarme
      pagarme_errors.each do |p_error|
        _attr = attributes_parsed_from_pagarme[p_error.parameter_name.to_sym]
        errors.add(_attr, :invalid)
      end
    end

    private

    def pagarme_errors
      configure_pagarme
      bank_account = ::PagarMe::BankAccount.new(attributes_parsed_to_pagarme)

      begin
        bank_account.create

        []
      rescue Exception => e
        e.errors
      end
    end

    def attributes_parsed_to_pagarme
      {
        bank_code: self.bank.try(:code),
        agencia: self.agency,
        agencia_dv: self.agency_digit,
        conta: self.account,
        conta_dv: self.account_digit,
        legal_name: self.owner_name,
        document_number: self.owner_document
      }
    end

    def attributes_parsed_from_pagarme
      {
        bank_code: :bank,
        agencia: :agency,
        agencia_dv: :agency_digit,
        conta: :account,
        conta_dv: :account_digit,
        legal_name: :owner_name,
        document_number: :owner_document
      }
    end

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

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
catarse_pagarme-2.9.3 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.9.2 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.9.0 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.10 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.9 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.8 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.7 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.6 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.5 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.4 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.3 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.2 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.1 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.8.0 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.7.15 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.7.14 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.7.13 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.7.12 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.7.11 app/models/catarse_pagarme/bank_account_concern.rb
catarse_pagarme-2.7.10 app/models/catarse_pagarme/bank_account_concern.rb