Class: Payment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/payment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.merge_banknotes(payments = nil) ⇒ Object



46
47
48
49
50
51
# File 'app/models/payment.rb', line 46

def self.merge_banknotes(payments=nil)
  payments ||= self.all
  payments.reject{|l| l.banknotes.nil? }.map(&:banknotes).reduce({}) do |result, entry|
    result.merge(entry) {|key, left, right| left.to_i+right.to_i }
  end
end

.merge_cash(payments = nil) ⇒ Object



53
54
55
56
# File 'app/models/payment.rb', line 53

def self.merge_cash(payments=nil)
  payments ||= self.all
  payments.map(&:paid_amount).compact.sum
end

Instance Method Details

#checkObject



76
77
78
79
80
81
# File 'app/models/payment.rb', line 76

def check
  Payments::CheckWorker.new.perform(id)
  reload

  checked?
end

#commission_for(amount) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/payment.rb', line 62

def commission_for(amount)
  return 0 if commissions.blank?

  commission = commissions.select{|x| x.max >= amount && amount >= x.min }.
    sort_by{|x| x[:weight]}.first

  return 0 if commission.blank?

  static  = commission['static_fee'] || 0
  percent = ((commission['percent_fee'] || 0)/100*amount).round(2)

  static+percent
end

#payObject



83
84
85
# File 'app/models/payment.rb', line 83

def pay
  Payments::PayWorker.perform_async(id)
end

#titleObject



58
59
60
# File 'app/models/payment.rb', line 58

def title
  provider.title rescue "-"
end