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[@id='adyen']"

  # 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  = "\n  descendant::input[@type='hidden'][@name='#{Adyen::Util.camelize(key)}']"
    condition << "[@value='#{value}']" unless value == :anything
    xpath_query << "[#{condition}]"
  end

  return xpath_query
end

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



32
33
34
35
36
# File 'lib/adyen/matchers.rb', line 32

def self.check(subject, checks = {})
  document = Adyen::API::XMLQuerier.html(subject)
  result = document.xpath(build_xpath_query(checks))
  !result.empty?
end