Class: BankPayments::Beneficiary

Inherits:
Object
  • Object
show all
Defined in:
lib/bank_payments/beneficiary.rb

Overview

Encapulates all the information about the destination of a payment. We choose this class name since this is what Swedbank seems to call it on their english homepage. Another viable option is also “Payee”.

Author:

  • Michael Litton

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Beneficiary

Creates a new Beneficiary object with defaults for part of the Swedbank payments

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
31
32
33
34
# File 'lib/bank_payments/beneficiary.rb', line 27

def initialize
  yield self if block_given?

  # Set sensible defaults
  @account_type ||= BankPayments::SwedbankExport::AccountType::CURRENCY_ACCOUNT
  @cost_carrier ||= BankPayments::SwedbankExport::CostResponsibility::OWN_EXPENSES
  @priority     ||= BankPayments::SwedbankExport::Priority::NORMAL
end

Instance Attribute Details

#accountObject

IBAN



20
21
22
# File 'lib/bank_payments/beneficiary.rb', line 20

def 
  @account
end

#account_typeObject

Configuration used for the address record in Swedbank SPISU



23
24
25
# File 'lib/bank_payments/beneficiary.rb', line 23

def 
  @account_type
end

#addressObject

Required regular fields



11
12
13
# File 'lib/bank_payments/beneficiary.rb', line 11

def address
  @address
end

#bank_idObject

The BIC (Bank Identification Code) for countires within EU



14
15
16
# File 'lib/bank_payments/beneficiary.rb', line 14

def bank_id
  @bank_id
end

#bank_nameObject

Can be empty for European payments



17
18
19
# File 'lib/bank_payments/beneficiary.rb', line 17

def bank_name
  @bank_name
end

#cost_carrierObject

Configuration used for the address record in Swedbank SPISU



23
24
25
# File 'lib/bank_payments/beneficiary.rb', line 23

def cost_carrier
  @cost_carrier
end

#country_codeObject

Required regular fields



11
12
13
# File 'lib/bank_payments/beneficiary.rb', line 11

def country_code
  @country_code
end

#nameObject

Required regular fields



11
12
13
# File 'lib/bank_payments/beneficiary.rb', line 11

def name
  @name
end

#priorityObject

Configuration used for the address record in Swedbank SPISU



23
24
25
# File 'lib/bank_payments/beneficiary.rb', line 23

def priority
  @priority
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/bank_payments/beneficiary.rb', line 36

def eql?(other)
  instance_values == other.instance_values
end

#hashObject



40
41
42
# File 'lib/bank_payments/beneficiary.rb', line 40

def hash
  instance_values.hash
end

#instance_valuesObject



44
45
46
47
48
# File 'lib/bank_payments/beneficiary.rb', line 44

def instance_values
  Hash[instance_variables.map do |variable|
    [variable[1..-1], instance_variable_get(variable)]
  end]
end

#to_spisu_recordsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bank_payments/beneficiary.rb', line 50

def to_spisu_records
  name      = BankPayments::SwedbankExport::NameRecord.new
  name.name = @name

  address              = BankPayments::SwedbankExport::AddressRecord.new
  address.address      = @address
  address.country_code = @country_code
  address. = @account_type
  address.cost_carrier = @cost_carrier
  address.priority     = @priority

  bank            = BankPayments::SwedbankExport::BankRecord.new
  bank.bank_id    = @bank_id
  bank.name       = @bank_name || ''
  bank.    = @account

  [name, address, bank]
end