Skip to content

Commit

Permalink
add header for uk traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimoiseanu committed Mar 5, 2024
1 parent 7adc800 commit 4a83993
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/mangopay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Configuration
:client_id, :client_apiKey,
:temp_dir, :log_file, :http_timeout,
:http_max_retries, :http_open_timeout,
:logger, :use_ssl
:logger, :use_ssl, :uk_header_flag

def apply_configuration
MangoPay.configure do |config|
Expand All @@ -70,6 +70,7 @@ def apply_configuration
config.http_open_timeout = @http_open_timeout
config.use_ssl = @use_ssl
config.logger = @logger
config.uk_header_flag = @uk_header_flag
end
end

Expand Down Expand Up @@ -100,6 +101,10 @@ def use_ssl?

true
end

def uk_header_flag
@uk_header_flag || false
end
end

class << self
Expand Down Expand Up @@ -193,6 +198,10 @@ def request(method, url, params={}, filters={}, headers_or_idempotency_key = nil
headers['Idempotency-Key'] = headers_or_idempotency_key if headers_or_idempotency_key != nil
end

if configuration.uk_header_flag
headers['x-tenant-id '] = 'uk'
end

res = Net::HTTP.start(uri.host, uri.port, :use_ssl => configuration.use_ssl?, :read_timeout => configuration.http_timeout,
:max_retries => configuration.http_max_retries,
:open_timeout => configuration.http_open_timeout, ssl_version: :TLSv1_2) do |http|
Expand Down
6 changes: 5 additions & 1 deletion lib/mangopay/authorization_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def get_token
token = storage.get
env_key = get_environment_key_for_token
if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now || token['environment_key'] != env_key
token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, {}, Proc.new do |req|
headers = {}
if MangoPay.configuration.uk_header_flag
headers['x-tenant-id '] = 'uk'
end
token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, headers, Proc.new do |req|
cfg = MangoPay.configuration
req.basic_auth cfg.client_id, cfg.client_apiKey
req.body = 'grant_type=client_credentials'
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def reset_mangopay_configuration
c.client_apiKey = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'

c.temp_dir = File.expand_path('../tmp', __FILE__)
c.logger = Logger.new(STDOUT)
c.uk_header_flag = true
require 'fileutils'
FileUtils.mkdir_p(c.temp_dir) unless File.directory?(c.temp_dir)
end
Expand Down

0 comments on commit 4a83993

Please sign in to comment.