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
- ENVELOPE =
<<EOS <?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> EOS
- CACERT =
A CA file used to verify certificates when connecting to Adyen.
File.('../cacert.pem', __FILE__)
Class Attribute Summary (collapse)
-
+ (Response) stubbed_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)
-
- (Hash) params
readonly
A hash of key-value pairs required for the action that is to be called.
Class Method Summary (collapse)
-
+ (URI) endpoint
A URI based on the ENDPOINT_URI constant defined on subclasses, where the environment type has been interpolated.
Instance Method Summary (collapse)
-
- (Object) call_webservice_action(action, data, response_class)
This method wraps the given XML data in a SOAP envelope and posts it to action on the endpoint defined for the subclass.
-
- (SimpleSOAPClient) initialize(params = {})
constructor
A new instance of SimpleSOAPClient.
- - (Object) validate_parameter_value!(param, value)
- - (Object) validate_parameters!(*params)
Constructor Details
- (SimpleSOAPClient) initialize(params = {})
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
+ (Response) stubbed_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
- (Hash) params (readonly)
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
+ (URI) endpoint
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
- (Object) call_webservice_action(action, data, response_class)
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 |
- (Object) validate_parameter_value!(param, value)
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 |
- (Object) validate_parameters!(*params)
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 |