Class: CryptocoinPayable::CoinPayment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CryptocoinPayable::CoinPayment
- Defined in:
- lib/cryptocoin_payable/coin_payment.rb
Instance Method Summary collapse
- #adapter ⇒ Object
- #calculate_coin_amount_due ⇒ Object
- #coin_amount_paid ⇒ Object
- #coin_amount_paid_subunit ⇒ Object
- #currency_amount_due ⇒ Object
- #currency_amount_paid ⇒ Object
- #transactions_confirmed? ⇒ Boolean
Instance Method Details
#adapter ⇒ Object
106 107 108 |
# File 'lib/cryptocoin_payable/coin_payment.rb', line 106 def adapter @adapter ||= Adapters.for(coin_type) end |
#calculate_coin_amount_due ⇒ Object
95 96 97 98 |
# File 'lib/cryptocoin_payable/coin_payment.rb', line 95 def calculate_coin_amount_due rate = CurrencyConversion.where(coin_type: coin_type).last.price adapter.convert_main_to_subunit(currency_amount_due / rate.to_f).ceil end |
#coin_amount_paid ⇒ Object
73 74 75 |
# File 'lib/cryptocoin_payable/coin_payment.rb', line 73 def coin_amount_paid transactions.sum { |tx| adapter.convert_subunit_to_main(tx.estimated_value) } end |
#coin_amount_paid_subunit ⇒ Object
77 78 79 |
# File 'lib/cryptocoin_payable/coin_payment.rb', line 77 def coin_amount_paid_subunit transactions.sum(&:estimated_value) end |
#currency_amount_due ⇒ Object
91 92 93 |
# File 'lib/cryptocoin_payable/coin_payment.rb', line 91 def currency_amount_due price - currency_amount_paid end |
#currency_amount_paid ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/cryptocoin_payable/coin_payment.rb', line 82 def currency_amount_paid cents = transactions.inject(0) do |sum, tx| sum + (adapter.convert_subunit_to_main(tx.estimated_value) * tx.coin_conversion) end # Round to 0 decimal places so there aren't any partial cents. cents.round(0) end |
#transactions_confirmed? ⇒ Boolean
100 101 102 103 104 |
# File 'lib/cryptocoin_payable/coin_payment.rb', line 100 def transactions_confirmed? transactions.all? do |t| t.confirmations >= CryptocoinPayable.configuration.send(coin_type).confirmations end end |