Class: Ingenico::Connect::SDK::Factory

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

Overview

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

Class Method Summary collapse

Class Method Details

.create_client_from_communicator(communicator) ⇒ Ingenico::Connect::SDK::Client

Creates and returns an Client that provides the a high-level interface with the Ingenico ePayments platform. 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:



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ingenico/connect/sdk/factory.rb', line 146

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) ⇒ Ingenico::Connect::SDK::Client

Creates and returns an Client that provides the a high-level interface with the Ingenico ePayments platform. 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:



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

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(configuration_file_name, api_key_id, secret_api_key) ⇒ Ingenico::Connect::SDK::Client

Creates and returns an Client that provides the a high-level interface with the Ingenico ePayments platform. 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(configuration_file_name, api_key_id, secret_api_key) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here

Parameters:

  • configuration_file_name (String)

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

  • api_key_id (String)

    Key id for the Ingenico ePayments platform.

  • secret_api_key (String)

    Secret key used for authentication to the Ingenico ePayments platform.

Returns:



197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/ingenico/connect/sdk/factory.rb', line 197

def self.create_client_from_file(configuration_file_name, api_key_id, secret_api_key)
  communicator = create_communicator_from_file(configuration_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_client_from_session(session) ⇒ Ingenico::Connect::SDK::Client

Creates and returns an Client that provides the a high-level interface with the Ingenico ePayments platform. 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_session(session) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here

Parameters:

Returns:



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/ingenico/connect/sdk/factory.rb', line 170

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

.create_communicator_from_configuration(configuration) ⇒ Ingenico::Connect::SDK::Communicator

Creates and returns an Communicator that can be used for communication with the Ingenico ePayments platform.

Parameters:

Returns:



93
94
95
96
# File 'lib/ingenico/connect/sdk/factory.rb', line 93

def self.create_communicator_from_configuration(configuration)
  session = create_session_from_configuration(configuration)
  Communicator.new(session, DefaultImpl::DefaultMarshaller.INSTANCE)
end

.create_communicator_from_file(configuration_file_name, api_key_id, secret_api_key) ⇒ Ingenico::Connect::SDK::Communicator

Creates and returns an Communicator that is used for communication with the Ingenico ePayments platform.

Parameters:

  • configuration_file_name (String)

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

  • api_key_id (String)

    Key id for the Ingenico ePayments platform.

  • secret_api_key (String)

    Secret key used for authentication to the Ingenico ePayments platform.

Returns:



104
105
106
107
108
# File 'lib/ingenico/connect/sdk/factory.rb', line 104

def self.create_communicator_from_file(configuration_file_name, api_key_id, secret_api_key)
  configuration = create_configuration(configuration_file_name, api_key_id, secret_api_key)
  session = create_session_from_configuration(configuration)
  Communicator.new(session, DefaultImpl::DefaultMarshaller.INSTANCE)
end

.create_communicator_from_session(session) ⇒ Ingenico::Connect::SDK::Communicator

Creates and returns an Communicator that is used for communication with the Ingenico ePayments platform.

Parameters:

Returns:



85
86
87
# File 'lib/ingenico/connect/sdk/factory.rb', line 85

def self.create_communicator_from_session(session)
  Communicator.new(session, DefaultImpl::DefaultMarshaller.INSTANCE)
end

.create_configuration(configuration_file_name, api_key_id, secret_api_key) ⇒ Ingenico::Connect::SDK::CommunicatorConfiguration

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

Parameters:

  • configuration_file_name (String)

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

  • api_key_id (String)

    Key id for the Ingenico ePayments platform.

  • secret_api_key (String)

    Secret key used for authentication to the Ingenico ePayments platform.

Returns:



26
27
28
29
30
31
# File 'lib/ingenico/connect/sdk/factory.rb', line 26

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

.create_session_from_configuration(configuration, meta_data_provider: nil, connection: nil, authenticator: nil) ⇒ Ingenico::Connect::SDK::Session

Creates and returns a Session from an CommunicatorConfiguration, an MetaDataProvider, an Connection and an Authenticator. If an authenticator is not given, a DefaultImpl::DefaultAuthenticator is created using the api_key_id and secret_api_key in the CommunicatorConfiguration.

Parameters:

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ingenico/connect/sdk/factory.rb', line 43

def self.create_session_from_configuration(configuration, meta_data_provider: nil,
                                           connection: nil, authenticator: nil)
  unless 
     = MetaDataProvider.new(configuration.integrator,
                                              shopping_cart_extension: configuration.shopping_cart_extension)
  end
  unless connection
    connection = DefaultImpl::DefaultConnection.new({ connect_timeout: configuration.connect_timeout,
                                                      socket_timeout: configuration.socket_timeout,
                                                      max_connections: configuration.max_connections,
                                                      proxy_configuration: configuration.proxy_configuration })
  end
  unless authenticator
    authenticator = DefaultImpl::DefaultAuthenticator.new(configuration.authorization_type,
                                                          configuration.api_key_id, configuration.secret_api_key)
  end
  Session.new(configuration.api_endpoint, connection, authenticator, )
end

.create_session_from_file(configuration_file_name, api_key_id, secret_api_key, meta_data_provider: nil, connection: nil, authenticator: nil) ⇒ Ingenico::Connect::SDK::Session

Creates and returns a Session from a file containing the communicator configuration, api_key_id, secret_api_key, an MetaDataProvider, an Connection and an Authenticator. If an authenticator is not given, a DefaultImpl::DefaultAuthenticator is created using the api_key_id and secret_api_key in the CommunicatorConfiguration.

Parameters:

  • configuration_file_name (String)

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

  • api_key_id (String)

    Key id for the Ingenico ePayments platform.

  • secret_api_key (String)

    Secret key used for authentication to the Ingenico ePayments platform.

  • meta_data_provider (Ingenico::Connect::SDK::MetaDataProvider) (defaults to: nil)

    stores the metadata for the communicating client.

  • connection (Ingenico::Connect::SDK::Connection) (defaults to: nil)

    connection that can be used to communicate with the Ingenico ePayments platform.

  • authenticator (Ingenico::Connect::SDK::Authenticator) (defaults to: nil)

    authenticator that can authenticate messages sent to the Ingenico ePayments platform.

Returns:



74
75
76
77
78
79
# File 'lib/ingenico/connect/sdk/factory.rb', line 74

def self.create_session_from_file(configuration_file_name, api_key_id, secret_api_key,
                                  meta_data_provider: nil, connection: nil, authenticator: nil)
  configuration = create_configuration(configuration_file_name, api_key_id, secret_api_key)
  create_session_from_configuration(configuration, meta_data_provider: , connection: connection,
                                    authenticator: authenticator)
end