Class: BuckarooClient::Gateway::NVP::Response

Inherits:
Object
  • Object
show all
Includes:
Signature
Defined in:
lib/buckaroo_client/gateway/nvp/response.rb

Direct Known Subclasses

InvoiceInfoResponse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Signature

#secret_key, #signature

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



27
28
29
30
31
32
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 27

def initialize(response)
  @body = response.body
  @response = Hash[Addressable::URI.form_unencode(body)]
  @status_code = @response['BRQ_STATUSCODE'].to_i
  @success = !error_occurred?
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



14
15
16
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 14

def body
  @body
end

#responseObject (readonly)

Returns the value of attribute response.



14
15
16
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 14

def response
  @response
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



14
15
16
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 14

def status_code
  @status_code
end

#successObject (readonly) Also known as: success?

Returns the value of attribute success.



14
15
16
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 14

def success
  @success
end

Class Method Details

.for_action(action, response) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 16

def self.for_action(action, response)
  klass = case action
  when 'invoiceinfo'
    require 'buckaroo_client/gateway/nvp/invoice_info_response'
    InvoiceInfoResponse
  else
    Response
  end
  klass.new(response)
end

Instance Method Details

#verified?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 40

def verified?
  input = response.dup
  given_hash = input['BRQ_SIGNATURE']
  input.delete('BRQ_SIGNATURE')
  signature(input) == given_hash
end

#verify!Object



36
37
38
# File 'lib/buckaroo_client/gateway/nvp/response.rb', line 36

def verify!
  verified? or raise "Response signature does not match expected value"
end