Class: Epaybg::Response
- Inherits:
-
Object
- Object
- Epaybg::Response
- Defined in:
- lib/epaybg/response.rb
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#encoded ⇒ Object
Returns the value of attribute encoded.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #decoded ⇒ Object
-
#initialize(encoded, checksum) ⇒ Response
constructor
A new instance of Response.
- #invoice ⇒ Object
- #paid_on ⇒ Object
- #response_for(status) ⇒ Object
- #status ⇒ Object
- #to_hash ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(encoded, checksum) ⇒ Response
Returns a new instance of Response.
6 7 8 9 |
# File 'lib/epaybg/response.rb', line 6 def initialize(encoded, checksum) @encoded = encoded @checksum = checksum end |
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
4 5 6 |
# File 'lib/epaybg/response.rb', line 4 def checksum @checksum end |
#encoded ⇒ Object
Returns the value of attribute encoded.
4 5 6 |
# File 'lib/epaybg/response.rb', line 4 def encoded @encoded end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 |
# File 'lib/epaybg/response.rb', line 36 def [](key) to_hash[key] end |
#decoded ⇒ Object
11 12 13 |
# File 'lib/epaybg/response.rb', line 11 def decoded Base64.strict_decode64(@encoded) end |
#invoice ⇒ Object
28 29 30 |
# File 'lib/epaybg/response.rb', line 28 def invoice to_hash["INVOICE"] end |
#paid_on ⇒ Object
32 33 34 |
# File 'lib/epaybg/response.rb', line 32 def paid_on DateTime.parse(to_hash["PAY_TIME"]) if status == "PAID" end |
#response_for(status) ⇒ Object
40 41 42 43 44 |
# File 'lib/epaybg/response.rb', line 40 def response_for(status) response_statuses = [:ok, :err] raise "Status must be one of #{response_statuses}" unless response_statuses.include? status "INVOICE=#{self.to_hash["INVOICE"]}:STATUS=#{status.to_s.upcase}" end |
#status ⇒ Object
24 25 26 |
# File 'lib/epaybg/response.rb', line 24 def status to_hash["STATUS"] end |
#to_hash ⇒ Object
15 16 17 18 |
# File 'lib/epaybg/response.rb', line 15 def to_hash i = decoded.strip.split(":").flat_map{ |c| c.split("=")} Hash[*i] end |