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
- #bcode ⇒ Object
- #decoded ⇒ Object
-
#initialize(encoded, checksum) ⇒ Response
constructor
A new instance of Response.
- #invoice ⇒ Object
- #paid_on ⇒ Object
- #response_for(status) ⇒ Object
- #stan ⇒ Object
- #status ⇒ Object
- #to_hash ⇒ Object
- #valid?(secret) ⇒ Boolean
Constructor Details
#initialize(encoded, checksum) ⇒ Response
Returns a new instance of Response.
5 6 7 8 |
# File 'lib/epaybg/response.rb', line 5 def initialize(encoded, checksum) @encoded = encoded @checksum = checksum end |
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
3 4 5 |
# File 'lib/epaybg/response.rb', line 3 def checksum @checksum end |
#encoded ⇒ Object
Returns the value of attribute encoded.
3 4 5 |
# File 'lib/epaybg/response.rb', line 3 def encoded @encoded end |
Instance Method Details
#[](key) ⇒ Object
43 44 45 |
# File 'lib/epaybg/response.rb', line 43 def [](key) to_hash[key] end |
#bcode ⇒ Object
35 36 37 |
# File 'lib/epaybg/response.rb', line 35 def bcode to_hash['BCODE'] if status == 'PAID' end |
#decoded ⇒ Object
10 11 12 |
# File 'lib/epaybg/response.rb', line 10 def decoded Base64.strict_decode64(@encoded) end |
#invoice ⇒ Object
27 28 29 |
# File 'lib/epaybg/response.rb', line 27 def invoice to_hash['INVOICE'] end |
#paid_on ⇒ Object
39 40 41 |
# File 'lib/epaybg/response.rb', line 39 def paid_on DateTime.parse(to_hash['PAY_TIME']) if status == 'PAID' end |
#response_for(status) ⇒ Object
47 48 49 50 51 |
# File 'lib/epaybg/response.rb', line 47 def response_for(status) response_statuses = [:ok, :err, :no] raise "Status must be one of #{response_statuses}" unless response_statuses.include? status "INVOICE=#{to_hash['INVOICE']}:STATUS=#{status.to_s.upcase}" end |
#stan ⇒ Object
31 32 33 |
# File 'lib/epaybg/response.rb', line 31 def stan to_hash['STAN'] if status == 'PAID' end |
#status ⇒ Object
23 24 25 |
# File 'lib/epaybg/response.rb', line 23 def status to_hash['STATUS'] end |
#to_hash ⇒ Object
14 15 16 17 |
# File 'lib/epaybg/response.rb', line 14 def to_hash i = decoded.strip.split(':').flat_map { |c| c.split('=') } Hash[*i] end |