Class: PaypalServerSdk::Client

Inherits:
Object
  • Object
show all
Includes:
CoreLibrary
Defined in:
lib/paypal_server_sdk/client.rb

Overview

paypal_server_sdk client class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, logging_configuration: nil, environment: Environment::SANDBOX, client_credentials_auth_credentials: nil, config: nil) ⇒ Client

Returns a new instance of Client.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/paypal_server_sdk/client.rb', line 41

def initialize(
  connection: nil, adapter: :net_http_persistent, timeout: 60,
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
  retry_methods: %i[get put], http_callback: nil,
  logging_configuration: nil, environment: Environment::SANDBOX,
  client_credentials_auth_credentials: nil, config: nil
)
  @config = if config.nil?
              Configuration.new(
                connection: connection, adapter: adapter, timeout: timeout,
                max_retries: max_retries, retry_interval: retry_interval,
                backoff_factor: backoff_factor,
                retry_statuses: retry_statuses,
                retry_methods: retry_methods, http_callback: http_callback,
                logging_configuration: logging_configuration,
                environment: environment,
                client_credentials_auth_credentials: client_credentials_auth_credentials
              )
            else
              config
            end
  user_agent_params = BaseController.user_agent_parameters

  @global_configuration = GlobalConfiguration.new(client_configuration: @config)
                                             .base_uri_executor(@config.method(:get_base_uri))
                                             .global_errors(BaseController::GLOBAL_ERRORS)
                                             .user_agent(BaseController.user_agent,
                                                         agent_parameters: user_agent_params)

  initialize_auth_managers(@global_configuration)
  @global_configuration = @global_configuration.auth_managers(@auth_managers)
end

Instance Attribute Details

#auth_managersObject (readonly)

Returns the value of attribute auth_managers.



10
11
12
# File 'lib/paypal_server_sdk/client.rb', line 10

def auth_managers
  @auth_managers
end

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/paypal_server_sdk/client.rb', line 10

def config
  @config
end

Instance Method Details

#initialize_auth_managers(global_config) ⇒ Object

Initializes the auth managers hash used for authenticating API calls.

Parameters:

  • global_config (GlobalConfiguration)

    The global configuration of the SDK)



77
78
79
80
81
82
83
# File 'lib/paypal_server_sdk/client.rb', line 77

def initialize_auth_managers(global_config)
  @auth_managers = {}
  http_client_config = global_config.client_configuration
  %w[Oauth2].each { |auth| @auth_managers[auth] = nil }
  @auth_managers['Oauth2'] = OAuth2.new(http_client_config.client_credentials_auth_credentials,
                                        global_config)
end

#o_auth_authorizationOAuthAuthorizationController

Access to o_auth_authorization controller.

Returns:



37
38
39
# File 'lib/paypal_server_sdk/client.rb', line 37

def o_auth_authorization
  @o_auth_authorization ||= OAuthAuthorizationController.new @global_configuration
end

#oauth2Object

Returns the configured authentication Oauth2 instance.



13
14
15
# File 'lib/paypal_server_sdk/client.rb', line 13

def oauth2
  @auth_managers['Oauth2']
end

#ordersOrdersController

Access to orders controller.

Returns:



19
20
21
# File 'lib/paypal_server_sdk/client.rb', line 19

def orders
  @orders ||= OrdersController.new @global_configuration
end

#paymentsPaymentsController

Access to payments controller.

Returns:



25
26
27
# File 'lib/paypal_server_sdk/client.rb', line 25

def payments
  @payments ||= PaymentsController.new @global_configuration
end

#vaultVaultController

Access to vault controller.

Returns:



31
32
33
# File 'lib/paypal_server_sdk/client.rb', line 31

def vault
  @vault ||= VaultController.new @global_configuration
end