Class: MPIClient::AccountManagement::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/mpi_client/account_management/response.rb

Constant Summary collapse

ATTRIBUTES =
[:merchant_id, :site_name, :site_url,
:certificate_subject, :acquirer_bin, :country_code,
:password, :certificate, :private_key,
:directory_server_url, :brand, :response_url,
:client_url, :term_url, :account_id]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_source) ⇒ Response

Returns a new instance of Response.



14
15
16
# File 'lib/mpi_client/account_management/response.rb', line 14

def initialize(response_source)
  @response_source = response_source
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



11
12
13
# File 'lib/mpi_client/account_management/response.rb', line 11

def error_code
  @error_code
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



11
12
13
# File 'lib/mpi_client/account_management/response.rb', line 11

def error_message
  @error_message
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/mpi_client/account_management/response.rb', line 11

def errors
  @errors
end

#response_sourceObject (readonly)

Returns the value of attribute response_source.



11
12
13
# File 'lib/mpi_client/account_management/response.rb', line 11

def response_source
  @response_source
end

Instance Method Details

#dataObject



37
38
39
40
41
42
43
# File 'lib/mpi_client/account_management/response.rb', line 37

def data
  {}.tap do |result|
    ATTRIBUTES.each do |attr|
      result[attr] = send(attr)
    end
  end
end

#parseObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mpi_client/account_management/response.rb', line 22

def parse
  doc = Nokogiri::XML.parse(response_source)
  case
  when error = doc.xpath("//Error").first
    @error_code    = error[:code]
    @error_message = error.text
    @errors        = errors_to_hash
  when (transaction = doc.xpath("//Transaction/*")) && transaction.any?
     transaction
  else
    @error_message = 'Unknown response was received from MPI'
    @errors = errors_to_hash
  end
end

#success?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/mpi_client/account_management/response.rb', line 18

def success?
  error_code.nil? && error_message.nil?
end