Class: Epaybg::Recurring::Debt::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/epaybg/recurring/debt/response.rb

Constant Summary collapse

XTYPE =
'RBN'
STATUSES =
%w(00 62 14 80 96)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ Response

00 върнато е задължение / debt returned 62 няма задължение. / no debts for this isd 14 невалиден номер(idn) / invalid idn 80 заявката временно не може да бъде изпълнена / timeout, server buisy 96 обща грешка / other errors

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
25
26
27
# File 'lib/epaybg/recurring/debt/response.rb', line 18

def initialize(params = {})
  @errors = []

  params.each do |k, v|
    instance_variable_set("@#{k}", v)
  end

  yield self if block_given?
  validate!
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



5
6
7
# File 'lib/epaybg/recurring/debt/response.rb', line 5

def amount
  @amount
end

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/epaybg/recurring/debt/response.rb', line 5

def errors
  @errors
end

#longdescObject

Returns the value of attribute longdesc.



5
6
7
# File 'lib/epaybg/recurring/debt/response.rb', line 5

def longdesc
  @longdesc
end

#secondidObject

Returns the value of attribute secondid.



5
6
7
# File 'lib/epaybg/recurring/debt/response.rb', line 5

def secondid
  @secondid
end

#shortdescObject

Returns the value of attribute shortdesc.



5
6
7
# File 'lib/epaybg/recurring/debt/response.rb', line 5

def shortdesc
  @shortdesc
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/epaybg/recurring/debt/response.rb', line 5

def status
  @status
end

#xvalidtoObject

Returns the value of attribute xvalidto.



5
6
7
# File 'lib/epaybg/recurring/debt/response.rb', line 5

def xvalidto
  @xvalidto
end

Instance Method Details

#bodyObject



67
68
69
# File 'lib/epaybg/recurring/debt/response.rb', line 67

def body
  body_array.join("\n") + "\n"
end

#body_arrayObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/epaybg/recurring/debt/response.rb', line 53

def body_array
  @body_array = [
                  "XTYPE=#{XTYPE}",
                  "XVALIDTO=#{xvalidto.strftime('%Y%m%d000000')}",
                  "AMOUNT=#{amount}",
                  "STATUS=#{status}",
                  "SHORTDESC=#{shortdesc}"
                ]

  @body_array << "SECONDID=#{secondid}" if secondid
  @body_array << "LONGDESC=#{longdesc}" if longdesc
  @body_array
end

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/epaybg/recurring/debt/response.rb', line 43

def valid?
  @errors.empty?
end

#validate!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/epaybg/recurring/debt/response.rb', line 29

def validate!
  [:xvalidto, :amount, :status, :shortdesc].each do |element|
    @errors << "Attribute #{element} is required!" if send(element).blank?
  end

  @errors << "'xvalidto' should be a time type field!" unless xvalidto.kind_of?(Time)

  {secondid: 15, shortdesc: 40, longdesc: 1800}.each do |k, v|
    @errors << "Attribute #{k} is too long. Maximum length should be #{v}." if send(k).to_s.length > v
  end

  @errors << "Invalid value #{status} for status" unless STATUSES.include?(status)
end