Class: Epaybg::Recurring::Debt::Response
- Inherits:
-
Object
- Object
- Epaybg::Recurring::Debt::Response
- Defined in:
- lib/epaybg/recurring/debt/response.rb
Constant Summary collapse
- XTYPE =
'RBN'
- STATUSES =
%w(00 62 14 80 96)
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#longdesc ⇒ Object
Returns the value of attribute longdesc.
-
#secondid ⇒ Object
Returns the value of attribute secondid.
-
#shortdesc ⇒ Object
Returns the value of attribute shortdesc.
-
#status ⇒ Object
Returns the value of attribute status.
-
#xvalidto ⇒ Object
Returns the value of attribute xvalidto.
Instance Method Summary collapse
- #body ⇒ Object
- #body_array ⇒ Object
-
#initialize(params = {}) {|_self| ... } ⇒ Response
constructor
00 върнато е задължение / debt returned 62 няма задължение.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
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
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
#amount ⇒ Object
Returns the value of attribute amount.
5 6 7 |
# File 'lib/epaybg/recurring/debt/response.rb', line 5 def amount @amount end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/epaybg/recurring/debt/response.rb', line 5 def errors @errors end |
#longdesc ⇒ Object
Returns the value of attribute longdesc.
5 6 7 |
# File 'lib/epaybg/recurring/debt/response.rb', line 5 def longdesc @longdesc end |
#secondid ⇒ Object
Returns the value of attribute secondid.
5 6 7 |
# File 'lib/epaybg/recurring/debt/response.rb', line 5 def secondid @secondid end |
#shortdesc ⇒ Object
Returns the value of attribute shortdesc.
5 6 7 |
# File 'lib/epaybg/recurring/debt/response.rb', line 5 def shortdesc @shortdesc end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/epaybg/recurring/debt/response.rb', line 5 def status @status end |
#xvalidto ⇒ Object
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
#body ⇒ Object
67 68 69 |
# File 'lib/epaybg/recurring/debt/response.rb', line 67 def body body_array.join("\n") + "\n" end |
#body_array ⇒ Object
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
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 |