Class: ActiveMerchant::Billing::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/response_parser.rb

Defined Under Namespace

Modules: ResponseXpath, ResultCode

Instance Method Summary collapse

Instance Method Details

#parse(body, required_items) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_merchant/billing/gateways/response_parser.rb', line 6

def parse(body, required_items)
  # because of following error
  #   Nokogiri::XML::SyntaxError: Unsupported encoding x-sjis-cp932
  @xml = Nokogiri::XML(body.sub('x-sjis-cp932', 'UTF-8'))
  @result = @xml.xpath(ResponseXpath::RESULT).to_s

  response = {
    success: [ResultCode::SUCCESS, ResultCode::THREE_D_SECURE_1, ResultCode::THREE_D_SECURE_2].include?(@result) || !state.empty?,
    message: "#{error_code}: #{error_detail}"
  }

  required_items.each do |item_name|
    response[item_name] = self.send(item_name)
  end

  response
end