Class: MPIClient::AccountManagement::Response
- Inherits:
-
Object
- Object
- MPIClient::AccountManagement::Response
- 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
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#response_source ⇒ Object
readonly
Returns the value of attribute response_source.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(response_source) ⇒ Response
constructor
A new instance of Response.
- #parse ⇒ Object
- #success? ⇒ Boolean
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_code ⇒ Object (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_message ⇒ Object (readonly)
Returns the value of attribute error_message.
11 12 13 |
# File 'lib/mpi_client/account_management/response.rb', line 11 def @error_message end |
#errors ⇒ Object (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_source ⇒ Object (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
#data ⇒ Object
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 |
#parse ⇒ Object
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? set_account_attributes transaction else @error_message = 'Unknown response was received from MPI' @errors = errors_to_hash end end |
#success? ⇒ Boolean
18 19 20 |
# File 'lib/mpi_client/account_management/response.rb', line 18 def success? error_code.nil? && .nil? end |