class Adyen::API::SimpleSOAPClient
The base class of the API
classes that map to Adyen
SOAP services.
Constants
- CACERT
A CA file used to verify certificates when connecting to
Adyen
.- ENVELOPE
@private
Attributes
When a response instance has been assigned, the subsequent call to {SimpleSOAPClient#call_webservice_action} will not make a remote call, but simply return the stubbed response instance. This is obviously meant for making payments from tests.
@see PaymentService::TestHelpers
@see RecurringService::TestHelpers
@return [Response] The stubbed Response
subclass instance.
@return [Hash] A hash of key-value pairs required for the action that is to be called.
Public Class Methods
@return [URI] A URI based on the ENDPOINT_URI constant defined on subclasses, where
the environment type has been interpolated. E.g. Test environment.
# File lib/adyen/api/simple_soap_client.rb 62 def endpoint 63 @endpoint ||= URI.parse(const_get('ENDPOINT_URI') % Adyen.configuration.environment) 64 end
@param [Hash] params A hash of key-value pairs required for the action that is to be called.
These are merged with the Adyen::API.default_params.
# File lib/adyen/api/simple_soap_client.rb 72 def initialize(params = {}) 73 @params = Adyen.configuration.default_api_params.merge(params) 74 end
Public Instance Methods
This method wraps the given XML data
in a SOAP envelope and posts it to action
on the endpoint
defined for the subclass.
The result is a response object, with XMLQuerier
, ready to be queried.
If a {stubbed_response} has been set, then said response is returned and no actual remote calls are made.
@param [String] action The remote action to call. @param [String] data The XML data to post to the remote action. @param [Response] response_class The Response
subclass used to wrap the response from Adyen
.
# File lib/adyen/api/simple_soap_client.rb 107 def call_webservice_action(action, data, response_class) 108 if response = self.class.stubbed_response 109 self.class.stubbed_response = nil 110 response 111 else 112 endpoint = self.class.endpoint 113 114 post = Net::HTTP::Post.new(endpoint.path, 'Accept' => 'text/xml', 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => action) 115 post.basic_auth(Adyen.configuration.api_username, Adyen.configuration.api_password) 116 post.body = ENVELOPE % data 117 118 request = Net::HTTP.new(endpoint.host, endpoint.port) 119 request.use_ssl = true 120 request.ca_file = CACERT 121 request.verify_mode = OpenSSL::SSL::VERIFY_PEER 122 123 request.start do |http| 124 http_response = http.request(post) 125 response = response_class.new(http_response) 126 raise ClientError.new(response, action, endpoint) if http_response.is_a?(Net::HTTPClientError) 127 raise ServerError.new(response, action, endpoint) if response.server_error? 128 response 129 end 130 end 131 end
# File lib/adyen/api/simple_soap_client.rb 76 def validate_parameter_value!(param, value) 77 if value.nil? || value =~ /^\s*$/ 78 raise ArgumentError, "The required parameter `:#{param}' is missing." 79 end 80 end
# File lib/adyen/api/simple_soap_client.rb 82 def validate_parameters!(*params) 83 params.each do |param| 84 case param 85 when Symbol 86 validate_parameter_value!(param, @params[param]) 87 when Hash 88 param.each do |name, attrs| 89 validate_parameter_value!(name, @params[name]) 90 attrs.each { |attr| validate_parameter_value!("#{name} => :#{attr}", @params[name][attr]) } 91 end 92 end 93 end 94 end