Class: OnlinePayments::SDK::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/onlinepayments/sdk/factory.rb

Overview

Convenience class that constructs instances of several other classes in the SDK. Provides methods to construct CommunicatorConfiguration, Communicator and Client instances.

Class Method Summary collapse

Class Method Details

.create_client_from_communicator(communicator) ⇒ OnlinePayments::SDK::Client

Creates and returns an Client that provides the a high-level interface with the OnlinePayments service. If a code block is given, the created client is returned to the code block and closed afterwards.

Examples:

Providing a code block

Factory.create_client_from_communicator(communicator) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here

Parameters:

Returns:



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/onlinepayments/sdk/factory.rb', line 96

def self.create_client_from_communicator(communicator)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_client_from_configuration(configuration) ⇒ OnlinePayments::SDK::Client

Creates and returns an Client that provides the a high-level interface with the OnlinePayments service. If a code block is given, the created client is returned to the code block and closed afterwards.

Examples:

Providing a code block

Factory.create_client_from_configuration(configuration) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here

Parameters:

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/onlinepayments/sdk/factory.rb', line 71

def self.create_client_from_configuration(configuration)
  communicator = create_communicator_from_configuration(configuration)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_client_from_file(config_file_name, api_key_id, secret_api_key) ⇒ OnlinePayments::SDK::Client

Creates and returns an Client that provides the a high-level interface with the OnlinePayments service. If a code block is given, the created client is returned to the code block and closed afterwards.

Examples:

Providing a code block

Factory.create_client_from_file(config_file_name, api_key_id, secret_api_key) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here

Parameters:

  • config_file_name (String)

    Path to the configuration file to use, should be in YAML format.

  • api_key_id (String)

    Key id for the OnlinePayments service.

  • secret_api_key (String)

    Secret key used for authentication to the OnlinePayments service.

Returns:



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/onlinepayments/sdk/factory.rb', line 122

def self.create_client_from_file(config_file_name, api_key_id, secret_api_key)
  communicator = create_communicator_from_file(config_file_name, api_key_id, secret_api_key)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_communicator_from_configuration(configuration, meta_data_provider: nil, connection: nil, authenticator: nil, marshaller: DefaultImpl::DefaultMarshaller.INSTANCE) ⇒ OnlinePayments::SDK::Communicator

Creates and returns an Communicator that can be used for communication with the OnlinePayments service.

Parameters:

Returns:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/onlinepayments/sdk/factory.rb', line 31

def self.create_communicator_from_configuration(configuration, meta_data_provider: nil, connection: nil, authenticator: nil, marshaller: DefaultImpl::DefaultMarshaller.INSTANCE)
   ||= MetaDataProvider.new(configuration.integrator, shopping_cart_extension: configuration.shopping_cart_extension)
  connection ||= DefaultImpl::DefaultConnection.new({ connect_timeout: configuration.connect_timeout,
                                                      socket_timeout: configuration.socket_timeout,
                                                      max_connections: configuration.max_connections,
                                                      proxy_configuration: configuration.proxy_configuration })
  authenticator ||= DefaultImpl::DefaultAuthenticator.new(configuration.api_key_id,
                                                          configuration.secret_api_key,
                                                          configuration.authorization_type)
  Communicator.new(configuration.api_endpoint, connection, authenticator, , marshaller)
end

.create_communicator_from_file(config_file_name, api_key_id, secret_api_key, meta_data_provider: nil, connection: nil, authenticator: nil, marshaller: DefaultImpl::DefaultMarshaller.INSTANCE) ⇒ OnlinePayments::SDK::Communicator

Creates and returns an Communicator that is used for communication with the OnlinePayments service.

Parameters:

  • config_file_name (String)

    Path to the configuration file to use, should be in YAML format.

  • api_key_id (String)

    Key id for the OnlinePayments service.

  • secret_api_key (String)

    Secret key used for authentication to the OnlinePayments service.

  • meta_data_provider (OnlinePayments::SDK::MetaDataProvider, nil) (defaults to: nil)

    stores the metadata for the communicating client.

  • connection (OnlinePayments::SDK::Connection, nil) (defaults to: nil)

    connection that can be used to communicate with the Online Payments platform.

  • authenticator (OnlinePayments::SDK::Authenticator, nil) (defaults to: nil)

    authenticator that can authenticate messages sent to the Online Payments platform.

Returns:



52
53
54
55
56
57
58
# File 'lib/onlinepayments/sdk/factory.rb', line 52

def self.create_communicator_from_file(config_file_name, api_key_id, secret_api_key,
                                       meta_data_provider: nil, connection: nil, authenticator: nil,
                                       marshaller: DefaultImpl::DefaultMarshaller.INSTANCE)
  configuration = create_configuration(config_file_name, api_key_id, secret_api_key)
  create_communicator_from_configuration(configuration, meta_data_provider: , connection: connection,
                                         authenticator: authenticator, marshaller: marshaller)
end

.create_configuration(config_file_name, api_key_id, secret_api_key) ⇒ OnlinePayments::SDK::CommunicatorConfiguration

Creates and returns a CommunicatorConfiguration based on the configuration in the file located at configuration_file_name.

Parameters:

  • config_file_name (String)

    Path to the configuration file to use, should be in YAML format.

  • api_key_id (String)

    Key id for the OnlinePayments service.

  • secret_api_key (String)

    Secret key used for authentication to the OnlinePayments service.

Returns:



16
17
18
19
20
21
# File 'lib/onlinepayments/sdk/factory.rb', line 16

def self.create_configuration(config_file_name, api_key_id, secret_api_key)
  properties = YAML::load_file(config_file_name)
  CommunicatorConfiguration.new(properties: properties,
                                api_key_id: api_key_id,
                                secret_api_key: secret_api_key)
end