Class: Adyen::API::SimpleSOAPClient
- Inherits:
-
Object
- Object
- Adyen::API::SimpleSOAPClient
- Defined in:
- lib/adyen/api/simple_soap_client.rb
Overview
The base class of the API classes that map to Adyen SOAP services.
Direct Known Subclasses
Defined Under Namespace
Classes: ClientError, ServerError, StandardError
Constant Summary collapse
- ENVELOPE =
<<-EOXML.strip.freeze <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> %s </soap:Body> </soap:Envelope> EOXML
- CACERT =
A CA file used to verify certificates when connecting to Adyen.
File.('../cacert.pem', __FILE__)
Class Attribute Summary collapse
-
.stubbed_response ⇒ Response
When a response instance has been assigned, the subsequent call to #call_webservice_action will not make a remote call, but simply return the stubbed response instance.
Instance Attribute Summary collapse
-
#params ⇒ Hash
readonly
A hash of key-value pairs required for the action that is to be called.
Class Method Summary collapse
-
.endpoint ⇒ URI
A URI based on the ENDPOINT_URI constant defined on subclasses, where the environment type has been interpolated.
Instance Method Summary collapse
-
#call_webservice_action(action, data, response_class) ⇒ Object
This method wraps the given XML
data
in a SOAP envelope and posts it toaction
on theendpoint
defined for the subclass. -
#initialize(params = {}) ⇒ SimpleSOAPClient
constructor
A new instance of SimpleSOAPClient.
- #validate_parameter_value!(param, value) ⇒ Object
- #validate_parameters!(*params) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ SimpleSOAPClient
Returns a new instance of SimpleSOAPClient.
72 73 74 |
# File 'lib/adyen/api/simple_soap_client.rb', line 72 def initialize(params = {}) @params = Adyen.configuration.default_api_params.merge(params) end |
Class Attribute Details
.stubbed_response ⇒ Response
When a response instance has been assigned, the subsequent call to #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.
58 59 60 |
# File 'lib/adyen/api/simple_soap_client.rb', line 58 def stubbed_response @stubbed_response end |
Instance Attribute Details
#params ⇒ Hash (readonly)
Returns A hash of key-value pairs required for the action that is to be called.
68 69 70 |
# File 'lib/adyen/api/simple_soap_client.rb', line 68 def params @params end |
Class Method Details
.endpoint ⇒ URI
Returns A URI based on the ENDPOINT_URI constant defined on subclasses, where the environment type has been interpolated. E.g. Test environment.
62 63 64 |
# File 'lib/adyen/api/simple_soap_client.rb', line 62 def endpoint @endpoint ||= URI.parse(const_get('ENDPOINT_URI') % Adyen.configuration.environment) end |
Instance Method Details
#call_webservice_action(action, data, response_class) ⇒ Object
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.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/adyen/api/simple_soap_client.rb', line 107 def call_webservice_action(action, data, response_class) if response = self.class.stubbed_response self.class.stubbed_response = nil response else endpoint = self.class.endpoint post = Net::HTTP::Post.new(endpoint.path, 'Accept' => 'text/xml', 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => action) post.basic_auth(Adyen.configuration.api_username, Adyen.configuration.api_password) post.body = ENVELOPE % data request = Net::HTTP.new(endpoint.host, endpoint.port) request.use_ssl = true request.ca_file = CACERT request.verify_mode = OpenSSL::SSL::VERIFY_PEER request.start do |http| http_response = http.request(post) response = response_class.new(http_response) raise ClientError.new(response, action, endpoint) if http_response.is_a?(Net::HTTPClientError) raise ServerError.new(response, action, endpoint) if response.server_error? response end end end |
#validate_parameter_value!(param, value) ⇒ Object
76 77 78 79 80 |
# File 'lib/adyen/api/simple_soap_client.rb', line 76 def validate_parameter_value!(param, value) if value.nil? || value =~ /^\s*$/ raise ArgumentError, "The required parameter `:#{param}' is missing." end end |
#validate_parameters!(*params) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/adyen/api/simple_soap_client.rb', line 82 def validate_parameters!(*params) params.each do |param| case param when Symbol validate_parameter_value!(param, @params[param]) when Hash param.each do |name, attrs| validate_parameter_value!(name, @params[name]) attrs.each { |attr| validate_parameter_value!("#{name} => :#{attr}", @params[name][attr]) } end end end end |