module Adyen::Matchers::XPathPaymentFormCheck

Public Class Methods

build_xpath_query(checks) click to toggle source
   # File lib/adyen/matchers.rb
 8 def self.build_xpath_query(checks)
 9   # Start by finding the check for the Adyen form tag
10   xpath_query =  "//form[@id='adyen']"
11 
12   # Add recurring/single check if specified
13   recurring =  checks.delete(:recurring)
14   unless recurring.nil?
15     if recurring
16       xpath_query << "[descendant::input[@type='hidden'][@name='recurringContract']]"
17     else
18       xpath_query << "[not(descendant::input[@type='hidden'][@name='recurringContract'])]"
19     end
20   end
21 
22   # Add a check for all the other fields specified
23   checks.each do |key, value|
24     condition  = "\n  descendant::input[@type='hidden'][@name='#{Adyen::Util.camelize(key)}']"
25     condition << "[@value='#{value}']" unless value == :anything
26     xpath_query << "[#{condition}]"
27   end
28 
29   return xpath_query
30 end
check(subject, checks = {}) click to toggle source
   # File lib/adyen/matchers.rb
32 def self.check(subject, checks = {})
33   document = Adyen::API::XMLQuerier.html(subject)
34   result = document.xpath(build_xpath_query(checks))
35   !result.empty?
36 end