Sha256: adc1a24a1188fe9c8fc834c85602414d81f5bdb3db820b096357e2d56258c177

Contents?: true

Size: 854 Bytes

Versions: 19

Compression:

Stored size: 854 Bytes

Contents

module Billing
  class PaymentWithType < Payment
    belongs_to :payment_type, inverse_of: :payments
    
    delegate :fiscal?, :cash?, to: :payment_type, allow_nil: true
    
    validates_presence_of :payment_type
    validates :payment_type, inclusion: { in: :payment_types }
    
    after_initialize on: :create do
      self.payment_type = default_payment_type unless payment_type
    end
    
    def find_payment_type_mapping_for(fiscal_driver)
      payment_type.payment_type_fiscal_driver_mappings.find_by(extface_driver_id: fiscal_driver.id).try(:mapping) if fiscal_driver.fiscal?
    end
    
    private
      def default_payment_type
        if pt = billable.try(:default_payment_type)
          pt
        else
          bill.try(:payment_types).try(:first) unless bill.try(:payment_types).try(:many?)
        end
      end
    
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
billing-0.1.3 app/models/billing/payment_with_type.rb
billing-0.1.2a app/models/billing/payment_with_type.rb
billing-0.1.2 app/models/billing/payment_with_type.rb
billing-0.1.1 app/models/billing/payment_with_type.rb
billing-0.1.0a app/models/billing/payment_with_type.rb
billing-0.1.0 app/models/billing/payment_with_type.rb
billing-0.0.9 app/models/billing/payment_with_type.rb
billing-0.0.8a app/models/billing/payment_with_type.rb
billing-0.0.8 app/models/billing/payment_with_type.rb
billing-0.0.7i app/models/billing/payment_with_type.rb
billing-0.0.7g app/models/billing/payment_with_type.rb
billing-0.0.7f app/models/billing/payment_with_type.rb
billing-0.0.7e app/models/billing/payment_with_type.rb
billing-0.0.7d app/models/billing/payment_with_type.rb
billing-0.0.7c app/models/billing/payment_with_type.rb
billing-0.0.7b app/models/billing/payment_with_type.rb
billing-0.0.7a app/models/billing/payment_with_type.rb
billing-0.0.7 app/models/billing/payment_with_type.rb
billing-0.0.6a app/models/billing/payment_with_type.rb