Class: Tray::Checkout::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tray/checkout/response_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ ResponseParser

Returns a new instance of ResponseParser.



16
17
18
# File 'lib/tray/checkout/response_parser.rb', line 16

def initialize(xml)
  @xml = xml
end

Class Method Details

.get_parser(xml) ⇒ Object



9
10
11
12
13
14
# File 'lib/tray/checkout/response_parser.rb', line 9

def self.get_parser(xml)
  #TODO: Remove this POG, please!
  Tray::Checkout::ResponseParser.transaction?(xml) ?
    Tray::Checkout::TransactionResponseParser.new(xml) :
    Tray::Checkout::AccountResponseParser.new(xml)
end

.transaction?(xml) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/tray/checkout/response_parser.rb', line 5

def self.transaction?(xml)
  xml.include?('<transaction>') || xml.include?('<tmp_transaction>')
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/tray/checkout/response_parser.rb', line 20

def parse
  response = Tray::Checkout::Response.new
  response.success = success?

  unless response.success?
    response.errors = errors
  end

  response
end