Class: MultibancoIfthenpay::Multibanco

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

Overview

Multibanco reference generator using Ifthenpay gateway

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity, sub_entity, order_id, order_value) ⇒ Multibanco

Returns a new instance of Multibanco.

Parameters:

  • entity (String)
  • sub_entity (String)
  • order_id (String)
  • order_value (Float)


13
14
15
16
17
18
19
20
# File 'lib/multibanco_ifthenpay.rb', line 13

def initialize(entity, sub_entity, order_id, order_value)
  validate!(entity, sub_entity, order_value)

  @entity = entity
  @sub_entity = sub_entity
  @order_id = order_id
  @order_value = order_value
end

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.



7
8
9
# File 'lib/multibanco_ifthenpay.rb', line 7

def entity
  @entity
end

#order_valueObject (readonly)

Returns the value of attribute order_value.



7
8
9
# File 'lib/multibanco_ifthenpay.rb', line 7

def order_value
  @order_value
end

Instance Method Details

Parameters:

  • prettify (BooleanMatcher) (defaults to: false)

Returns:

  • (String)


31
32
33
34
35
36
37
# File 'lib/multibanco_ifthenpay.rb', line 31

def print_multibanco_reference(prettify = false)
  reference = MultibancoIfthenpay::Calculator
              .get_multibanco_reference(@entity, @sub_entity,
                                        @order_id, @order_value)

  prettify ? reference.scan(/.{3}/).join(' ') : reference
end

#validate!(entity, sub_entity, order_value) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/multibanco_ifthenpay.rb', line 22

def validate!(entity, sub_entity, order_value)
  raise ArgumentError, 'Not a valid entity' unless entity.length == 5
  raise ArgumentError, 'Not a valid sub-entity' unless
      !sub_entity.empty? && sub_entity.length < 4
  raise ArgumentError, 'Not a valid order value' unless order_value >= 1
end