class ActiveMerchant::Billing::ResponseParser

Public Instance Methods

parse(body, required_items) click to toggle source
# 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

Private Instance Methods

account_name() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 90
def account_name
  uri_decode(@xml.xpath(ResponseXpath::ACCOUNT_NAME).to_s)
end
account_number() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 86
def account_number
  @xml.xpath(ResponseXpath::ACCOUNT_NUMBER).to_s
end
acs_url() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 54
def acs_url
  uri_decode(@xml.xpath(ResponseXpath::ACS_URL).to_s)
end
amount() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 126
def amount
  @xml.xpath(ResponseXpath::AMOUNT).to_s
end
bank_code() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 94
def bank_code
  @xml.xpath(ResponseXpath::BANK_CODE).to_s
end
bank_name() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 98
def bank_name
  uri_decode(@xml.xpath(ResponseXpath::BANK_NAME).to_s)
end
branch_code() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 102
def branch_code
  @xml.xpath(ResponseXpath::BRANCH_CODE).to_s
end
branch_name() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 106
def branch_name
  uri_decode(@xml.xpath(ResponseXpath::BRANCH_NAME).to_s)
end
captured() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 134
def captured
  @xml.xpath(ResponseXpath::CAPTURED).to_s != '1'
end
card_brand() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 42
def card_brand
  uri_decode(@xml.xpath(ResponseXpath::CARD_BRAND).to_s)
end
card_expire() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 46
def card_expire
  uri_decode(@xml.xpath(ResponseXpath::CARD_EXPIRE).to_s)
end
card_number_mask() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 38
def card_number_mask
  uri_decode(@xml.xpath(ResponseXpath::CARD_NUMBER_MASK).to_s)
end
company_code() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 82
def company_code
  @xml.xpath(ResponseXpath::COMPANY_CODE).to_s
end
convenience_store_limit_date() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 74
def convenience_store_limit_date
  uri_decode(@xml.xpath(ResponseXpath::CONVENIENCE_STORE_LIMIT_DATE).to_s)
end
convenience_store_payment_slip_url() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 78
def convenience_store_payment_slip_url
  uri_decode(@xml.xpath(ResponseXpath::CONVENIENCE_STORE_PAYMENT_SLIP_URL).to_s)
end
error_code() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 30
def error_code
  @xml.xpath(ResponseXpath::ERROR_CODE).to_s
end
error_detail() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 34
def error_detail
  uri_decode(@xml.xpath(ResponseXpath::ERROR_DETAIL).to_s)
end
item_price() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 122
def item_price
  @xml.xpath(ResponseXpath::ITEM_PRICE).to_s
end
last_update() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 114
def last_update
  @xml.xpath(ResponseXpath::LAST_UPDATE).to_s
end
pa_req() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 58
def pa_req
  uri_decode(@xml.xpath(ResponseXpath::PA_REQ).to_s)
end
payment_code() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 118
def payment_code
  @xml.xpath(ResponseXpath::PAYMENT_CODE).to_s
end
receipt_date() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 70
def receipt_date
  uri_decode(@xml.xpath(ResponseXpath::RECEIPT_DATE).to_s)
end
receipt_number() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 66
def receipt_number
  @xml.xpath(ResponseXpath::RECEIPT_NUMBER).to_s
end
redirect() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 130
def redirect
  uri_decode(@xml.xpath(ResponseXpath::REDIRECT).to_s)
end
state() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 110
def state
  @xml.xpath(ResponseXpath::STATE).to_s
end
tds2_url() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 62
def tds2_url
  uri_decode(@xml.xpath(ResponseXpath::TDS2_URL).to_s)
end
three_d_secure() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 50
def three_d_secure
  [ResultCode::THREE_D_SECURE_1, ResultCode::THREE_D_SECURE_2].include?(@result)
end
transaction_code() click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 26
def transaction_code
  @xml.xpath(ResponseXpath::TRANSACTION_CODE).to_s
end
uri_decode(string) click to toggle source
# File lib/active_merchant/billing/gateways/response_parser.rb, line 138
def uri_decode(string)
  CGI.unescape(string).encode(Encoding::UTF_8, Encoding::CP932)
end