Class: Adyen::API::SimpleSOAPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/adyen/api.rb

Overview

The actual classes

Direct Known Subclasses

PaymentService, RecurringService

Defined Under Namespace

Classes: ClientError

Constant Summary collapse

CACERT =
File.expand_path('../../../support/cacert.pem', __FILE__)

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ SimpleSOAPClient

Returns a new instance of SimpleSOAPClient.



70
71
72
# File 'lib/adyen/api.rb', line 70

def initialize(params = {})
  @params = API.default_params.merge(params)
end

Class Attribute Details

.stubbed_responseObject

Returns the value of attribute stubbed_response.



61
62
63
# File 'lib/adyen/api.rb', line 61

def stubbed_response
  @stubbed_response
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



68
69
70
# File 'lib/adyen/api.rb', line 68

def params
  @params
end

Class Method Details

.endpointObject



63
64
65
# File 'lib/adyen/api.rb', line 63

def endpoint
  @endpoint ||= URI.parse(const_get('ENDPOINT_URI') % Adyen.environment)
end

Instance Method Details

#call_webservice_action(action, data, response_class) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/adyen/api.rb', line 74

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(API.username, API.password)
    post.body = 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)
      raise ClientError.new(http_response, action, endpoint) if http_response.is_a?(Net::HTTPClientError)
      response_class.new(http_response)
    end
  end
end