Class: Dune::Balanced::Bankaccount::PaymentGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/models/dune/balanced/bankaccount/payment_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(customer, resource, attrs = {}) ⇒ PaymentGenerator

Returns a new instance of PaymentGenerator.



7
8
9
10
11
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 7

def initialize(customer, resource, attrs = {})
  @customer      = customer
  @resource      = resource
  @attrs         = attrs
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



3
4
5
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 3

def attrs
  @attrs
end

#customerObject (readonly)

Returns the value of attribute customer.



3
4
5
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 3

def customer
  @customer
end

#resourceObject (readonly)

Returns the value of attribute resource.



3
4
5
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 3

def resource
  @resource
end

Instance Method Details

#can_debit_resource?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 30

def can_debit_resource?
  debit_resource..to_a.first.try(:verification_status).eql? 'succeeded'
end

#completeObject



13
14
15
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 13

def complete
  payment.checkout!
end

#debit_resourceObject



34
35
36
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 34

def debit_resource
  @debit_resource ||= ::Balanced::BankAccount.find(@attrs.fetch(:use_bank))
end

#paymentObject



17
18
19
20
21
22
23
24
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 17

def payment
  @payment ||= payment_class.new(
    'balanced-bankaccount',
    customer,
    resource,
    attrs
  )
end

#payment_classObject



26
27
28
# File 'app/models/dune/balanced/bankaccount/payment_generator.rb', line 26

def payment_class
  @payment_class ||= can_debit_resource? ? Dune::Balanced::Bankaccount::Payment : Dune::Balanced::Bankaccount::DelayedPayment
end