Class: UnivapayClientSdk::Client

Inherits:
Object
  • Object
show all
Includes:
CoreLibrary
Defined in:
lib/univapay_client_sdk/client.rb,
lib/univapay_client_sdk/extensions.rb

Overview

Reopened onto the generated client class to expose the app token's context.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, adapter: :net_http_persistent, timeout: 30, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put get put],, http_callback: nil, proxy_settings: nil, logging_configuration: nil, environment: Environment::PRODUCTION, base_url: 'https://api.univapay.com', bearer_auth_credentials: nil, config: nil) ⇒ Client

Returns a new instance of Client.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/univapay_client_sdk/client.rb', line 70

def initialize(
  connection: nil, adapter: :net_http_persistent, timeout: 30,
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
  retry_methods: %i[get put get put], http_callback: nil,
  proxy_settings: nil, logging_configuration: nil,
  environment: Environment::PRODUCTION,
  base_url: 'https://api.univapay.com', bearer_auth_credentials: nil,
  config: nil
)
  wrapped_callback = IdempotencyCallback.new(http_callback)
  @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: wrapped_callback,
                proxy_settings: proxy_settings,
                logging_configuration: logging_configuration,
                environment: environment, base_url: base_url,
                bearer_auth_credentials: bearer_auth_credentials
              )
            else
            if config.http_callback.is_a?(IdempotencyCallback)
              config
            else
              config.clone_with(http_callback: IdempotencyCallback.new(config.http_callback))
            end
            end
  user_agent_params = BaseApi.user_agent_parameters

  @global_configuration = GlobalConfiguration.new(client_configuration: @config)
                                             .base_uri_executor(@config.method(:get_base_uri))
                                             .global_errors(BaseApi::GLOBAL_ERRORS)
                                             .user_agent(BaseApi.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.



16
17
18
# File 'lib/univapay_client_sdk/client.rb', line 16

def auth_managers
  @auth_managers
end

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/univapay_client_sdk/client.rb', line 16

def config
  @config
end

Class Method Details

.from_env(**overrides) ⇒ Object

Creates a client directly from environment variables.



122
123
124
125
126
# File 'lib/univapay_client_sdk/client.rb', line 122

def self.from_env(**overrides)
  default_config = Configuration.build_default_config_from_env
  new_config = default_config.clone_with(**overrides)
  new(config: new_config)
end

Instance Method Details

#cancelsCancelsApi

Access to cancels controller.

Returns:

  • (CancelsApi)

    Returns the controller instance.



48
49
50
# File 'lib/univapay_client_sdk/client.rb', line 48

def cancels
  @cancels ||= CancelsApi.new @global_configuration
end

#chargesChargesApi

Access to charges controller.

Returns:

  • (ChargesApi)

    Returns the controller instance.



24
25
26
# File 'lib/univapay_client_sdk/client.rb', line 24

def charges
  @charges ||= ChargesApi.new @global_configuration
end

#get_current_merchant_idString?

The merchant this client's app token was issued for, decoded from the configured JWT.

Both merchant-level and store-level app tokens carry a merchant, so this is set for either kind of token.

Returns:

  • (String, nil)

    The merchant id as a UUID string, or nil if no JWT is configured or its merchant_id claim is absent or not a UUID.



195
196
197
# File 'lib/univapay_client_sdk/extensions.rb', line 195

def get_current_merchant_id
  AppJwt.read_uuid_claim(jwt_token_or_nil, 'merchant_id')
end

#get_current_store_idString?

The store this client's app token was issued for, decoded from the configured JWT.

Only store-level app tokens are scoped to a store. A merchant-level token carries no store_id claim, so this returns nil for one -- use stores to list the merchant's stores instead.

Returns:

  • (String, nil)

    The store id as a UUID string, or nil if no JWT is configured or its store_id claim is absent or not a UUID.



208
209
210
# File 'lib/univapay_client_sdk/extensions.rb', line 208

def get_current_store_id
  AppJwt.read_uuid_claim(jwt_token_or_nil, 'store_id')
end

#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)



114
115
116
117
118
119
# File 'lib/univapay_client_sdk/client.rb', line 114

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

#merchantsMerchantsApi

Access to merchants controller.

Returns:



54
55
56
# File 'lib/univapay_client_sdk/client.rb', line 54

def merchants
  @merchants ||= MerchantsApi.new @global_configuration
end

#refundsRefundsApi

Access to refunds controller.

Returns:

  • (RefundsApi)

    Returns the controller instance.



36
37
38
# File 'lib/univapay_client_sdk/client.rb', line 36

def refunds
  @refunds ||= RefundsApi.new @global_configuration
end

#storesStoresApi

Access to stores controller.

Returns:

  • (StoresApi)

    Returns the controller instance.



60
61
62
# File 'lib/univapay_client_sdk/client.rb', line 60

def stores
  @stores ||= StoresApi.new @global_configuration
end

#subscriptionsSubscriptionsApi

Access to subscriptions controller.

Returns:



42
43
44
# File 'lib/univapay_client_sdk/client.rb', line 42

def subscriptions
  @subscriptions ||= SubscriptionsApi.new @global_configuration
end

#transaction_tokensTransactionTokensApi

Access to transaction_tokens controller.

Returns:



30
31
32
# File 'lib/univapay_client_sdk/client.rb', line 30

def transaction_tokens
  @transaction_tokens ||= TransactionTokensApi.new @global_configuration
end

#user_agent_detailObject



18
19
20
# File 'lib/univapay_client_sdk/client.rb', line 18

def user_agent_detail
  config.user_agent_detail
end

#webhooksWebhooksApi

Access to webhooks controller.

Returns:



66
67
68
# File 'lib/univapay_client_sdk/client.rb', line 66

def webhooks
  @webhooks ||= WebhooksApi.new @global_configuration
end