Module: Adyen::Matchers::XPathPaymentFormCheck

Defined in:
lib/adyen/matchers.rb

Class Method Summary collapse

Class Method Details

.build_xpath_query(checks) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/adyen/matchers.rb', line 8

def self.build_xpath_query(checks)
  # Start by finding the check for the Adyen form tag
  xpath_query =  "//form[@action='#{Adyen::Form.url}']"

  # Add recurring/single check if specified
  recurring =  checks.delete(:recurring)
  unless recurring.nil?
    if recurring
      xpath_query << "[descendant::input[@type='hidden'][@name='recurringContract']]"
    else
      xpath_query << "[not(descendant::input[@type='hidden'][@name='recurringContract'])]"
    end
  end

  # Add a check for all the other fields specified
  checks.each do |key, value|
    condition  = "descendant::input[@type='hidden'][@name='#{key.to_s.camelize(:lower)}']"
    condition << "[@value='#{value}']" unless value == :anything
    xpath_query << "[#{condition}]"
  end

  return xpath_query
end

.check(subject, checks = {}) ⇒ Object



46
47
48
# File 'lib/adyen/matchers.rb', line 46

def self.check(subject, checks = {})
  document(subject).find_first(build_xpath_query(checks))
end

.document(subject) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/adyen/matchers.rb', line 32

def self.document(subject)
  if String === subject
    XML::HTMLParser.string(subject).parse
  elsif subject.respond_to?(:body)
    XML::HTMLParser.string(subject.body).parse
  elsif XML::Node === subject
    subject
  elsif XML::Document === subject
    subject
  else
    raise "Cannot handle this XML input type"
  end
end