class QiwiObserver::WebhookResponse
Attributes
error[R]
value[R]
Public Class Methods
new(success:, body:)
click to toggle source
# File lib/qiwi_observer/webhook/webhook_response.rb, line 6 def initialize(success:, body:) @success = success if @success @value = parse_body(body) else @error = error_description(body) end end
Public Instance Methods
success?()
click to toggle source
# File lib/qiwi_observer/webhook/webhook_response.rb, line 15 def success? @success end
Private Instance Methods
error_description(body)
click to toggle source
# File lib/qiwi_observer/webhook/webhook_response.rb, line 26 def error_description(body) return "This ##{body} transaction is not authenticated" if body.is_a?(String) return "Error #{body.first} #{body.last}" if body.is_a?(Array) end
parse_body(body)
click to toggle source
# File lib/qiwi_observer/webhook/webhook_response.rb, line 21 def parse_body(body) return parse_hash(body) if body.is_a?(Hash) return parse_json(body) if body.is_a?(String) end
parse_hash(body)
click to toggle source
# File lib/qiwi_observer/webhook/webhook_response.rb, line 31 def parse_hash(body) if body[:test] != true output = body[:payment] output.reject { |key, _val| key == :signFields }.to_h else body end end
parse_json(body)
click to toggle source
# File lib/qiwi_observer/webhook/webhook_response.rb, line 40 def parse_json(body) output = JSON.parse(body).reduce({}) {|result, (key, value)| result.merge({key.to_sym => value})} end