Class: Dune::Balanced::Creditcard::Payment
- Inherits:
-
Object
- Object
- Dune::Balanced::Creditcard::Payment
- Defined in:
- app/models/dune/balanced/creditcard/payment.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#customer ⇒ Object
readonly
Returns the value of attribute customer.
-
#engine_name ⇒ Object
readonly
Returns the value of attribute engine_name.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #amount_in_cents ⇒ Object
- #checkout! ⇒ Object
- #debit ⇒ Object
- #fee_calculator ⇒ Object
-
#initialize(engine_name, customer, resource, attrs = {}) ⇒ Payment
constructor
A new instance of Payment.
- #successful? ⇒ Boolean
Constructor Details
#initialize(engine_name, customer, resource, attrs = {}) ⇒ Payment
Returns a new instance of Payment.
5 6 7 8 9 10 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 5 def initialize(engine_name, customer, resource, attrs = {}) @engine_name = engine_name @customer = customer @resource = resource @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 3 def attrs @attrs end |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
3 4 5 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 3 def customer @customer end |
#engine_name ⇒ Object (readonly)
Returns the value of attribute engine_name.
3 4 5 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 3 def engine_name @engine_name end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
3 4 5 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 3 def resource @resource end |
Instance Method Details
#amount_in_cents ⇒ Object
27 28 29 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 27 def amount_in_cents (fee_calculator.gross_amount * 100).round end |
#checkout! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 12 def checkout! perform_debit! resource.confirm! rescue Balanced::PaymentRequired resource.cancel! ensure resource.update_attributes( payment_id: @debit.try(:id), payment_method: engine_name, payment_service_fee: fee_calculator.fees, payment_service_fee_paid_by_user: attrs[:pay_fee] ) (@debit) if @debit end |
#debit ⇒ Object
43 44 45 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 43 def debit @debit.try(:sanitize) end |
#fee_calculator ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 31 def fee_calculator @fee_calculator and return @fee_calculator calculator_class = if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include? attrs[:pay_fee] TransactionAdditionalFeeCalculator else TransactionInclusiveFeeCalculator end @fee_calculator = calculator_class.new(resource.value) end |
#successful? ⇒ Boolean
47 48 49 |
# File 'app/models/dune/balanced/creditcard/payment.rb', line 47 def successful? %w(pending succeeded).include? @debit.try(:status) end |