cybersource_rest_client 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/AuthenticationSDK/authentication/http/GetSignatureParameter.rb +64 -0
- data/lib/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb +52 -0
- data/lib/AuthenticationSDK/authentication/jwt/JwtToken.rb +62 -0
- data/lib/AuthenticationSDK/authentication/payloadDigest/digest.rb +10 -0
- data/lib/AuthenticationSDK/core/Authorization.rb +24 -0
- data/lib/AuthenticationSDK/core/ITokenGeneration.rb +4 -0
- data/lib/AuthenticationSDK/core/Logger.rb +26 -0
- data/lib/AuthenticationSDK/core/MerchantConfig.rb +181 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/resource/TRRReports.json +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/resource/cybs.yml +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/resource/request.json +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/resource/request_capture.json +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/resource/testrest.p12 +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/spec/Authorization_spec.rb +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/spec/MerchantConfigData.rb +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/spec/MerchantConfig_spec.rb +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/spec/PostRequestData.json +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/spec/PutRequestData.json +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/spec/ResponseCodeMessage_spec.rb +0 -0
- data/{AuthenticationSDK → lib/AuthenticationSDK}/spec/spec_helper.rb +0 -0
- data/lib/AuthenticationSDK/util/ApiException.rb +19 -0
- data/lib/AuthenticationSDK/util/Cache.rb +36 -0
- data/lib/AuthenticationSDK/util/Constants.rb +138 -0
- data/lib/AuthenticationSDK/util/PropertiesUtil.rb +19 -0
- data/lib/AuthenticationSDK/util/Utility.rb +32 -0
- data/lib/cybersource_rest_client/api_client.rb +11 -11
- data/lib/cybersource_rest_client.rb +13 -0
- metadata +27 -29
- data/AuthenticationSDK/AuthenticationSDK-0.0.1.gem +0 -0
- data/AuthenticationSDK/Cybersource.gemspec +0 -25
- data/AuthenticationSDK/authentication/http/GetSignatureParameter.rb +0 -64
- data/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb +0 -52
- data/AuthenticationSDK/authentication/jwt/JwtToken.rb +0 -62
- data/AuthenticationSDK/authentication/payloadDigest/digest.rb +0 -10
- data/AuthenticationSDK/core/Authorization.rb +0 -24
- data/AuthenticationSDK/core/ITokenGeneration.rb +0 -4
- data/AuthenticationSDK/core/Logger.rb +0 -26
- data/AuthenticationSDK/core/MerchantConfig.rb +0 -181
- data/AuthenticationSDK/util/ApiException.rb +0 -19
- data/AuthenticationSDK/util/Cache.rb +0 -36
- data/AuthenticationSDK/util/Constants.rb +0 -138
- data/AuthenticationSDK/util/PropertiesUtil.rb +0 -20
- data/AuthenticationSDK/util/Utility.rb +0 -31
@@ -0,0 +1,138 @@
|
|
1
|
+
class Constants
|
2
|
+
|
3
|
+
GET_REQUEST_TYPE_LOWER = 'get' unless const_defined?(:GET_REQUEST_TYPE_LOWER)
|
4
|
+
|
5
|
+
POST_REQUEST_TYPE_LOWER = 'post' unless const_defined?(:POST_REQUEST_TYPE_LOWER)
|
6
|
+
|
7
|
+
PUT_REQUEST_TYPE_LOWER = 'put' unless const_defined?(:PUT_REQUEST_TYPE_LOWER)
|
8
|
+
|
9
|
+
PATCH_REQUEST_TYPE_LOWER = 'patch' unless const_defined?(:PATCH_REQUEST_TYPE_LOWER)
|
10
|
+
|
11
|
+
DELETE_REQUEST_TYPE_LOWER = 'delete' unless const_defined?(:DELETE_REQUEST_TYPE_LOWER)
|
12
|
+
|
13
|
+
GET_REQUEST_TYPE = 'GET' unless const_defined?(:GET_REQUEST_TYPE)
|
14
|
+
|
15
|
+
POST_REQUEST_TYPE = 'POST' unless const_defined?(:POST_REQUEST_TYPE)
|
16
|
+
|
17
|
+
PUT_REQUEST_TYPE = 'PUT' unless const_defined?(:PUT_REQUEST_TYPE)
|
18
|
+
|
19
|
+
PATCH_REQUEST_TYPE = 'PATCH' unless const_defined?(:PATCH_REQUEST_TYPE)
|
20
|
+
|
21
|
+
DELETE_REQUEST_TYPE = 'DELETE' unless const_defined?(:DELETE_REQUEST_TYPE)
|
22
|
+
|
23
|
+
V_C_MERCHANT_ID = 'v-c-merchant-id' unless const_defined?(:V_C_MERCHANT_ID)
|
24
|
+
|
25
|
+
HOST = 'host' unless const_defined?(:HOST)
|
26
|
+
|
27
|
+
DATE = 'date' unless const_defined?(:DATE)
|
28
|
+
|
29
|
+
REQUEST_TARGET = '(request-target)' unless const_defined?(:REQUEST_TARGET)
|
30
|
+
|
31
|
+
DIGEST = 'digest' unless const_defined?(:DIGEST)
|
32
|
+
|
33
|
+
SIGNATURE = 'Signature' unless const_defined?(:SIGNATURE)
|
34
|
+
|
35
|
+
HTTPS_URI_PREFIX = 'https://' unless const_defined?(:HTTPS_URI_PREFIX)
|
36
|
+
|
37
|
+
BEARER = 'Bearer' unless const_defined?(:BEARER)
|
38
|
+
|
39
|
+
MEDIA_TYPE_JSON = 'application/json' unless const_defined?(:MEDIA_TYPE_JSON)
|
40
|
+
|
41
|
+
SIGNATURE_ALGORITHM = 'HmacSHA256' unless const_defined?(:SIGNATURE_ALGORITHM)
|
42
|
+
|
43
|
+
ALGORITHM = "algorithm=\"" unless const_defined?(:ALGORITHM)
|
44
|
+
|
45
|
+
SHA256 = 'SHA-256=' unless const_defined?(:SHA256)
|
46
|
+
|
47
|
+
CONTENT_TYPE = 'Content-Type' unless const_defined?(:CONTENT_TYPE)
|
48
|
+
|
49
|
+
USER_AGENT = 'User-Agent' unless const_defined?(:USER_AGENT)
|
50
|
+
|
51
|
+
USER_AGENT_VALUE = 'Mozilla/5.0' unless const_defined?(:USER_AGENT_VALUE)
|
52
|
+
|
53
|
+
KEY_ID = "keyid=\"" unless const_defined?(:KEY_ID)
|
54
|
+
|
55
|
+
HEADERS_PARAM = "headers=\"" unless const_defined?(:HEADERS_PARAM)
|
56
|
+
|
57
|
+
SIGNATURE_PARAM = "signature=\"" unless const_defined?(:SIGNATURE_PARAM)
|
58
|
+
|
59
|
+
AUTH_TYPE_HTTP = 'HTTP_SIGNATURE' unless const_defined?(:AUTH_TYPE_HTTP)
|
60
|
+
|
61
|
+
AUTH_TYPE_JWT = 'JWT' unless const_defined?(:AUTH_TYPE_JWT)
|
62
|
+
|
63
|
+
RUN_ENV_SANDBOX = 'CYBERSOURCE.ENVIRONMENT.SANDBOX' unless const_defined?(:RUN_ENV_SANDBOX)
|
64
|
+
|
65
|
+
RUN_ENV_PROD = 'CYBERSOURCE.ENVIRONMENT.PRODUCTION'unless const_defined?(:RUN_ENV_PROD)
|
66
|
+
|
67
|
+
SANDBOX_URL = 'apitest.cybersource.com' unless const_defined?(:SANDBOX_URL)
|
68
|
+
|
69
|
+
PRODUCTION_URL = 'api.cybersource.com' unless const_defined?(:PRODUCTION_URL)
|
70
|
+
|
71
|
+
# constants for fall back logic
|
72
|
+
|
73
|
+
DEFAULT_LOG_SIZE = '10485760' unless const_defined?(:DEFAULT_LOG_SIZE)
|
74
|
+
|
75
|
+
DEFAULT_PROXY_ADDRESS = 'userproxy.visa.com' unless const_defined?(:DEFAULT_PROXY_ADDRESS)
|
76
|
+
|
77
|
+
DEFAULT_PROXY_PORT = '443' unless const_defined?(:DEFAULT_PROXY_PORT)
|
78
|
+
|
79
|
+
DEFAULT_TIMEOUT = '1000' unless const_defined?(:DEFAULT_TIMEOUT)
|
80
|
+
|
81
|
+
DEFAULT_LOG_DIRECTORY = '../log' unless const_defined?(:DEFAULT_LOG_DIRECTORY)
|
82
|
+
|
83
|
+
DEFAULT_KEY_DIRECTORY = 'resource' unless const_defined?(:DEFAULT_KEY_DIRECTORY)
|
84
|
+
|
85
|
+
DEFAULT_LOGFILE_NAME = 'cybs' unless const_defined?(:DEFAULT_LOGFILE_NAME)
|
86
|
+
|
87
|
+
# Constant for Fall back logic and Exception Handling
|
88
|
+
|
89
|
+
REQUEST_JSON_ERROR = 'Request Json File missing. File Path :: ' unless const_defined?(:REQUEST_JSON_ERROR)
|
90
|
+
|
91
|
+
INVALID_ENABLE_LOG = 'EnableLog should be (True/False) in cybs.yml' unless const_defined?(:INVALID_ENABLE_LOG)
|
92
|
+
|
93
|
+
REFER_LOG = 'Please refer Log for details' unless const_defined?(:REFER_LOG)
|
94
|
+
|
95
|
+
MERCHANT_ID_NULL = 'MerchantID is mandatory' unless const_defined?(:MERCHANT_ID_NULL)
|
96
|
+
|
97
|
+
INCORRECT_KEY_PASS = 'The keyPass Entered is Incorrect' unless const_defined?(:INCORRECT_KEY_PASS)
|
98
|
+
|
99
|
+
AUTH_TYPE_MANDATORY= 'AuthenticationType is Mandatory' unless const_defined?(:AUTH_TYPE_MANDATORY)
|
100
|
+
|
101
|
+
MERCHANT_KEY_ID_MANDATORY = 'MerchantKeyId is Mandatory' unless const_defined?(:MERCHANT_KEY_ID_MANDATORY)
|
102
|
+
|
103
|
+
MERCHANT_SECRET_KEY_MANDATORY = 'MerchantSecretKey is Mandatory' unless const_defined?(:MERCHANT_SECRET_KEY_MANDATORY)
|
104
|
+
|
105
|
+
KEY_PASS_NULL = 'keyPass is empty, Assigining merchantID value' unless const_defined?(:KEY_PASS_NULL)
|
106
|
+
|
107
|
+
REQUEST_JSON_PATH_EMPTY = 'RequestJsonPath not provided. Using Default Value:'unless const_defined?(:REQUEST_JSON_PATH_EMPTY)
|
108
|
+
|
109
|
+
REQUEST_TYPE_EMPTY = 'RequestType Property of Merchant Config Not Set' unless const_defined?(:REQUEST_TYPE_EMPTY)
|
110
|
+
|
111
|
+
INVALID_REQUEST_TYPE_METHOD = 'Entered Request Type should be (GET/POST/PUT)' unless const_defined?(:INVALID_REQUEST_TYPE_METHOD)
|
112
|
+
|
113
|
+
INVALID_LOG_DIRECTORY = 'Entered LogDirectory is Incorrect. Using Default Path: ' unless const_defined?(:INVALID_LOG_DIRECTORY)
|
114
|
+
|
115
|
+
RUN_ENVIRONMENT_ERROR = 'Entered RunEnvironment is Incorrect.' unless const_defined?(:RUN_ENVIRONMENT_ERROR)
|
116
|
+
|
117
|
+
PROPERTY_FILE_NOT_FOUND = 'Cybs.yml file not found' unless const_defined?(:PROPERTY_FILE_NOT_FOUND)
|
118
|
+
|
119
|
+
ERROR_PREFIX = 'Error: ' unless const_defined?(:ERROR_PREFIX)
|
120
|
+
|
121
|
+
WARNING_PREFIX = 'Warning: ' unless const_defined?(:WARNING_PREFIX)
|
122
|
+
|
123
|
+
HIDDEN_MERCHANT_PROPERTIES = 'merchantID,merchantKeyId,merchantsecretKey,keyAlias,keyPass' unless const_defined?(:HIDDEN_MERCHANT_PROPERTIES)
|
124
|
+
|
125
|
+
RUN_ENVIRONMENT = 'RunEnvironment is Mandatory' unless const_defined?(:RUN_ENVIRONMENT)
|
126
|
+
|
127
|
+
KEY_DIRECTORY_EMPTY = 'KeysDirectory not provided. Using Default Path:' unless const_defined?(:KEY_DIRECTORY_EMPTY)
|
128
|
+
|
129
|
+
FILE_NOT_FOUND = 'File not found, Re-Enter path/file name, Entered path/file name :: ' unless const_defined?(:FILE_NOT_FOUND)
|
130
|
+
|
131
|
+
AUTH_ERROR = 'Check Authentication Type (HTTP_Signature/JWT) in cybs.yml.' unless const_defined?(:AUTH_ERROR)
|
132
|
+
|
133
|
+
KEY_FILE_NAME_NULL_EMPTY = 'KeyFilename Empty/Null. Assigining merchantID value' unless const_defined?(:KEY_FILE_NAME_NULL_EMPTY)
|
134
|
+
|
135
|
+
KEY_ALIAS_NULL_EMPTY = 'KeyAlias Empty/Null. Assigining merchantID value' unless const_defined?(:KEY_ALIAS_NULL_EMPTY)
|
136
|
+
|
137
|
+
INCORRECT_KEY_ALIAS = 'The Entered KeyAlias is Incorrect. Assigining merchantID value' unless const_defined?(:INCORRECT_KEY_ALIAS)
|
138
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require_relative './Constants.rb'
|
3
|
+
public
|
4
|
+
# Method for reading Cybs.yml file
|
5
|
+
class PropertiesUtil
|
6
|
+
def getCybsProp(cybs_path)
|
7
|
+
# Give the path of cybs properties file which needs to be read.
|
8
|
+
if File.exist?(cybs_path)
|
9
|
+
# Reading Merchant Config from Cybs.yml File"
|
10
|
+
cybsproperty_obj = YAML.load(File.read(cybs_path))
|
11
|
+
return cybsproperty_obj
|
12
|
+
elsif !File.exist?(cybs_path)
|
13
|
+
raise Constants::ERROR_PREFIX + Constants::PROPERTY_FILE_NOT_FOUND
|
14
|
+
end
|
15
|
+
rescue StandardError => err
|
16
|
+
puts err.message
|
17
|
+
exit!
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
public
|
2
|
+
|
3
|
+
class Utility
|
4
|
+
def getResponseCodeMessage(responseCode)
|
5
|
+
responseCode = responseCode.to_s
|
6
|
+
case responseCode
|
7
|
+
when "200"
|
8
|
+
tempResponseCodeMessage = "Transcation Successful"
|
9
|
+
when "201"
|
10
|
+
tempResponseCodeMessage = "Transcation Successful"
|
11
|
+
when "400"
|
12
|
+
tempResponseCodeMessage = "Bad Request"
|
13
|
+
when "401"
|
14
|
+
tempResponseCodeMessage = "Authentication Failed"
|
15
|
+
when "404"
|
16
|
+
tempResponseCodeMessage = "Not Found"
|
17
|
+
when "403"
|
18
|
+
tempResponseCodeMessage = "Forbidden"
|
19
|
+
when "500"
|
20
|
+
tempResponseCodeMessage = "Internal Server Error"
|
21
|
+
when "502"
|
22
|
+
tempResponseCodeMessage = "Bad Gateway"
|
23
|
+
when "503"
|
24
|
+
tempResponseCodeMessage = "Service Unavailable"
|
25
|
+
when "504"
|
26
|
+
tempResponseCodeMessage = "Gateway Timeout"
|
27
|
+
else
|
28
|
+
tempResponseCodeMessage= ''
|
29
|
+
end
|
30
|
+
return tempResponseCodeMessage
|
31
|
+
end
|
32
|
+
end
|
@@ -140,16 +140,16 @@ module CyberSource
|
|
140
140
|
download_file(request) if opts[:return_type] == 'File'
|
141
141
|
request
|
142
142
|
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
143
|
+
# set merchantConfig
|
144
|
+
def set_configuration(config)
|
145
|
+
require_relative '../AuthenticationSDK/core/MerchantConfig.rb'
|
146
|
+
$merchantconfig_obj = Merchantconfig.new(config)
|
147
|
+
@config.host = $merchantconfig_obj.requestHost
|
148
|
+
end
|
149
|
+
# Calling Authentication
|
150
150
|
def CallAuthenticationHeader(http_method, path, body_params, header_params, query_params)
|
151
|
-
require_relative '
|
152
|
-
require_relative '
|
151
|
+
require_relative '../AuthenticationSDK/core/Authorization.rb'
|
152
|
+
require_relative '../AuthenticationSDK/authentication/payloadDigest/digest.rb'
|
153
153
|
request_target = get_query_param(path, query_params)
|
154
154
|
# Request Type. [Non-Editable]
|
155
155
|
request_type = http_method.to_s
|
@@ -198,7 +198,7 @@ module CyberSource
|
|
198
198
|
end
|
199
199
|
request_target
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
# Check if the given MIME is a JSON MIME.
|
203
203
|
# JSON MIME examples:
|
204
204
|
# application/json
|
@@ -457,4 +457,4 @@ module CyberSource
|
|
457
457
|
end
|
458
458
|
end
|
459
459
|
end
|
460
|
-
end
|
460
|
+
end
|
@@ -10,6 +10,19 @@ Swagger Codegen version: 2.2.3
|
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
13
|
+
require 'AuthenticationSDK/util/Utility'
|
14
|
+
require 'AuthenticationSDK/util/PropertiesUtil'
|
15
|
+
require 'AuthenticationSDK/util/Constants'
|
16
|
+
require 'AuthenticationSDK/util/Cache'
|
17
|
+
require 'AuthenticationSDK/util/ApiException'
|
18
|
+
require 'AuthenticationSDK/core/MerchantConfig'
|
19
|
+
require 'AuthenticationSDK/core/Logger'
|
20
|
+
require 'AuthenticationSDK/core/ITokenGeneration'
|
21
|
+
require 'AuthenticationSDK/core/Authorization'
|
22
|
+
require 'AuthenticationSDK/authentication/payloadDigest/digest'
|
23
|
+
require 'AuthenticationSDK/authentication/jwt/JwtToken'
|
24
|
+
require 'AuthenticationSDK/authentication/http/HttpSignatureHeader'
|
25
|
+
require 'AuthenticationSDK/authentication/http/GetSignatureParameter'
|
13
26
|
# Common files
|
14
27
|
require 'cybersource_rest_client/api_client'
|
15
28
|
require 'cybersource_rest_client/api_error'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cybersource_rest_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CyberSource
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -279,33 +279,31 @@ executables: []
|
|
279
279
|
extensions: []
|
280
280
|
extra_rdoc_files: []
|
281
281
|
files:
|
282
|
-
- AuthenticationSDK/
|
283
|
-
- AuthenticationSDK/
|
284
|
-
- AuthenticationSDK/authentication/
|
285
|
-
- AuthenticationSDK/authentication/
|
286
|
-
- AuthenticationSDK/
|
287
|
-
- AuthenticationSDK/
|
288
|
-
- AuthenticationSDK/core/
|
289
|
-
- AuthenticationSDK/core/
|
290
|
-
- AuthenticationSDK/
|
291
|
-
- AuthenticationSDK/
|
292
|
-
- AuthenticationSDK/resource/
|
293
|
-
- AuthenticationSDK/resource/
|
294
|
-
- AuthenticationSDK/resource/
|
295
|
-
- AuthenticationSDK/
|
296
|
-
- AuthenticationSDK/
|
297
|
-
- AuthenticationSDK/spec/
|
298
|
-
- AuthenticationSDK/spec/
|
299
|
-
- AuthenticationSDK/spec/
|
300
|
-
- AuthenticationSDK/spec/
|
301
|
-
- AuthenticationSDK/spec/
|
302
|
-
- AuthenticationSDK/
|
303
|
-
- AuthenticationSDK/
|
304
|
-
- AuthenticationSDK/util/
|
305
|
-
- AuthenticationSDK/util/
|
306
|
-
- AuthenticationSDK/util/
|
307
|
-
- AuthenticationSDK/util/PropertiesUtil.rb
|
308
|
-
- AuthenticationSDK/util/Utility.rb
|
282
|
+
- lib/AuthenticationSDK/authentication/http/GetSignatureParameter.rb
|
283
|
+
- lib/AuthenticationSDK/authentication/http/HttpSignatureHeader.rb
|
284
|
+
- lib/AuthenticationSDK/authentication/jwt/JwtToken.rb
|
285
|
+
- lib/AuthenticationSDK/authentication/payloadDigest/digest.rb
|
286
|
+
- lib/AuthenticationSDK/core/Authorization.rb
|
287
|
+
- lib/AuthenticationSDK/core/ITokenGeneration.rb
|
288
|
+
- lib/AuthenticationSDK/core/Logger.rb
|
289
|
+
- lib/AuthenticationSDK/core/MerchantConfig.rb
|
290
|
+
- lib/AuthenticationSDK/resource/TRRReports.json
|
291
|
+
- lib/AuthenticationSDK/resource/cybs.yml
|
292
|
+
- lib/AuthenticationSDK/resource/request.json
|
293
|
+
- lib/AuthenticationSDK/resource/request_capture.json
|
294
|
+
- lib/AuthenticationSDK/resource/testrest.p12
|
295
|
+
- lib/AuthenticationSDK/spec/Authorization_spec.rb
|
296
|
+
- lib/AuthenticationSDK/spec/MerchantConfigData.rb
|
297
|
+
- lib/AuthenticationSDK/spec/MerchantConfig_spec.rb
|
298
|
+
- lib/AuthenticationSDK/spec/PostRequestData.json
|
299
|
+
- lib/AuthenticationSDK/spec/PutRequestData.json
|
300
|
+
- lib/AuthenticationSDK/spec/ResponseCodeMessage_spec.rb
|
301
|
+
- lib/AuthenticationSDK/spec/spec_helper.rb
|
302
|
+
- lib/AuthenticationSDK/util/ApiException.rb
|
303
|
+
- lib/AuthenticationSDK/util/Cache.rb
|
304
|
+
- lib/AuthenticationSDK/util/Constants.rb
|
305
|
+
- lib/AuthenticationSDK/util/PropertiesUtil.rb
|
306
|
+
- lib/AuthenticationSDK/util/Utility.rb
|
309
307
|
- lib/cybersource_rest_client.rb
|
310
308
|
- lib/cybersource_rest_client/api/capture_api.rb
|
311
309
|
- lib/cybersource_rest_client/api/conversion_details_api.rb
|
Binary file
|
@@ -1,25 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "authenticationSDK"
|
3
|
-
s.version = "0.0.1"
|
4
|
-
s.platform = Gem::Platform::RUBY
|
5
|
-
s.date = "2018-07-17"
|
6
|
-
s.summary = "Cybersource Payments REST API Ruby Gem"
|
7
|
-
s.description = "Move your business forward with the Cybersource Payments REST API"
|
8
|
-
s.authors = ["cybersource"]
|
9
|
-
s.email = ""
|
10
|
-
s.files = Dir.glob("{lib}/**/*")
|
11
|
-
|
12
|
-
s.required_ruby_version = '>= 2.2.2'
|
13
|
-
s.required_rubygems_version = '>= 1.3.6'
|
14
|
-
|
15
|
-
s.add_runtime_dependency 'activesupport', '~> 5.2', '>= 5.2.0'
|
16
|
-
s.add_runtime_dependency 'json', '~> 2.1.0', '>= 1.8.1'
|
17
|
-
s.add_runtime_dependency 'interface','~> 1.0', '>= 1.0.4'
|
18
|
-
s.add_runtime_dependency 'jwt', '~> 2.1.0'
|
19
|
-
|
20
|
-
s.add_runtime_dependency 'rspec', '~> 2.1'
|
21
|
-
s.add_runtime_dependency 'simplecov'
|
22
|
-
s.add_runtime_dependency 'simplecov-json'
|
23
|
-
s.add_development_dependency 'rubocop', '~> 0.57.2'
|
24
|
-
end
|
25
|
-
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require_relative '../../util/Constants.rb'
|
2
|
-
require_relative '.././payloadDigest/digest.rb'
|
3
|
-
require 'openssl'
|
4
|
-
# This function returns value for paramter Signature which is then passed to Signature header
|
5
|
-
# paramter 'Signature' is calucated based on below key values and then signed with SECRET KEY -
|
6
|
-
# host: Sandbox (apitest.cybersource.com) or Production (api.cybersource.com) hostname
|
7
|
-
# date: "HTTP-date" format as defined by RFC7231.
|
8
|
-
# (request-target): Should be in format of httpMethod: path
|
9
|
-
# Example: "post /pts/v2/payments"
|
10
|
-
# Digest: Only needed for POST calls.
|
11
|
-
# digestString = BASE64( HMAC-SHA256 ( Payload ));
|
12
|
-
# Digest: “SHA-256=“ + digestString;
|
13
|
-
# v-c-merchant-id: set value to Cybersource Merchant ID
|
14
|
-
# This ID can be found on EBC portal*/
|
15
|
-
class SignatureParameter
|
16
|
-
def generateSignatureParameter(merchantconfig_obj, gmtdatetime, log_obj)
|
17
|
-
request_type = merchantconfig_obj.requestType.upcase
|
18
|
-
merchantSecretKey = merchantconfig_obj.merchantSecretKey
|
19
|
-
signatureString = Constants::HOST + ': ' + merchantconfig_obj.requestHost
|
20
|
-
signatureString << "\n"+ Constants::DATE + ': ' + gmtdatetime
|
21
|
-
signatureString << "\n(request-target): "
|
22
|
-
if request_type == Constants::GET_REQUEST_TYPE || request_type == Constants::DELETE_REQUEST_TYPE
|
23
|
-
targetUrl=gettargetUrlForGetDelete(request_type,merchantconfig_obj)
|
24
|
-
signatureString << targetUrl + "\n"
|
25
|
-
elsif request_type == Constants::POST_REQUEST_TYPE || request_type == Constants::PUT_REQUEST_TYPE || request_type == Constants::PATCH_REQUEST_TYPE
|
26
|
-
targetUrl=gettargetUrlForPutPost(request_type,merchantconfig_obj)
|
27
|
-
signatureString << targetUrl + "\n"
|
28
|
-
payload = merchantconfig_obj.requestJsonData
|
29
|
-
digest = DigestGeneration.new.generateDigest(payload, log_obj)
|
30
|
-
digest_payload = Constants::SHA256 + digest
|
31
|
-
signatureString << Constants::DIGEST + ': ' + digest_payload + "\n"
|
32
|
-
end
|
33
|
-
signatureString << Constants::V_C_MERCHANT_ID + ': ' + merchantconfig_obj.merchantId
|
34
|
-
encodedSignatureString = signatureString.force_encoding(Encoding::UTF_8)
|
35
|
-
decodedKey = Base64.decode64(merchantSecretKey)
|
36
|
-
base64EncodedSignature = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', decodedKey, encodedSignatureString))
|
37
|
-
return base64EncodedSignature
|
38
|
-
rescue StandardError => err
|
39
|
-
log_obj.logger.error(err.message)
|
40
|
-
log_obj.logger.error(err.backtrace)
|
41
|
-
puts 'Check log for more details.'
|
42
|
-
exit!
|
43
|
-
end
|
44
|
-
def gettargetUrlForGetDelete(request_type, merchantconfig_obj)
|
45
|
-
targetUrlForGetDelete = ''
|
46
|
-
if request_type == Constants::DELETE_REQUEST_TYPE
|
47
|
-
targetUrlForGetDelete = Constants::DELETE_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
|
48
|
-
elsif request_type == Constants::GET_REQUEST_TYPE
|
49
|
-
targetUrlForGetDelete = Constants::GET_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
|
50
|
-
end
|
51
|
-
return targetUrlForGetDelete
|
52
|
-
end
|
53
|
-
def gettargetUrlForPutPost(request_type, merchantconfig_obj)
|
54
|
-
targetUrlForPutPost = ''
|
55
|
-
if request_type == Constants::POST_REQUEST_TYPE
|
56
|
-
targetUrlForPutPost = Constants::POST_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
|
57
|
-
elsif request_type == Constants::PUT_REQUEST_TYPE
|
58
|
-
targetUrlForPutPost = Constants::PUT_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
|
59
|
-
elsif request_type == Constants::PATCH_REQUEST_TYPE
|
60
|
-
targetUrlForPutPost = Constants::PATCH_REQUEST_TYPE_LOWER + ' ' + merchantconfig_obj.requestTarget
|
61
|
-
end
|
62
|
-
return targetUrlForPutPost
|
63
|
-
end
|
64
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require_relative '../../core/ITokenGeneration.rb'
|
3
|
-
require_relative '../../util/Constants.rb'
|
4
|
-
require_relative '../../util/ApiException.rb'
|
5
|
-
require_relative '.././payloadDigest/digest.rb'
|
6
|
-
require_relative '.././http/GetSignatureParameter.rb'
|
7
|
-
public
|
8
|
-
# SignatureHeader return SignatureHeader Value that contains following paramters
|
9
|
-
# * keyid -- Merchant ID obtained from EBC portal
|
10
|
-
# * algorithm -- Should have value as "HmacSHA256"
|
11
|
-
# * headers -- List of all header name passed in the Signature paramter below
|
12
|
-
# String getHeaders = "host date (request-target)" + " " + "v-c-merchant-id";
|
13
|
-
# String postHeaders = "host date (request-target) digest v-c-merchant-id";
|
14
|
-
# Note: Digest is not passed for GET calls
|
15
|
-
# * signature -- Signature header has paramter called signature
|
16
|
-
# Paramter 'Signature' must contain all the paramters mentioned in header above in given order
|
17
|
-
class GenerateHttpSignature
|
18
|
-
# Generates Signature based on the requestType
|
19
|
-
def getToken(merchantconfig_obj, gmtdatetime, log_obj)
|
20
|
-
request_type = merchantconfig_obj.requestType.upcase
|
21
|
-
signatureHeaderValue =''
|
22
|
-
signatureHeaderValue << Constants::KEY_ID + merchantconfig_obj.merchantKeyId + "\""
|
23
|
-
# Algorithm should be always HmacSHA256 for http signature
|
24
|
-
signatureHeaderValue << ', ' + Constants::ALGORITHM + Constants::SIGNATURE_ALGORITHM + "\""
|
25
|
-
# Headers - list is choosen based on HTTP method
|
26
|
-
signatureheader=getsignatureHeader(request_type)
|
27
|
-
signatureHeaderValue << ', ' + Constants::HEADERS_PARAM + signatureheader + "\""
|
28
|
-
# Get Value for parameter 'Signature' to be passed to Signature Header
|
29
|
-
signature_value = SignatureParameter.new.generateSignatureParameter(merchantconfig_obj, gmtdatetime, log_obj)
|
30
|
-
signatureHeaderValue << ', ' + Constants::SIGNATURE_PARAM + signature_value + "\""
|
31
|
-
return signatureHeaderValue
|
32
|
-
rescue StandardError => err
|
33
|
-
ApiException.new.apiexception(err,log_obj)
|
34
|
-
exit!
|
35
|
-
end
|
36
|
-
def getsignatureHeader(request_type)
|
37
|
-
headers = ''
|
38
|
-
if request_type == Constants::POST_REQUEST_TYPE
|
39
|
-
headers = 'host date (request-target) digest ' + Constants::V_C_MERCHANT_ID
|
40
|
-
elsif request_type == Constants::GET_REQUEST_TYPE || request_type == Constants::DELETE_REQUEST_TYPE
|
41
|
-
headers = 'host date (request-target)' + ' ' + Constants::V_C_MERCHANT_ID
|
42
|
-
elsif request_type == Constants::PUT_REQUEST_TYPE
|
43
|
-
headers = 'host date (request-target) digest ' + Constants::V_C_MERCHANT_ID
|
44
|
-
elsif request_type == Constants::PATCH_REQUEST_TYPE
|
45
|
-
headers = 'host date (request-target) digest ' + Constants::V_C_MERCHANT_ID
|
46
|
-
else
|
47
|
-
raise StandardError.new(Constants::ERROR_PREFIX + Constants::INVALID_REQUEST_TYPE_METHOD)
|
48
|
-
end
|
49
|
-
return headers
|
50
|
-
end
|
51
|
-
implements TokenInterface
|
52
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'openssl'
|
3
|
-
require 'jwt'
|
4
|
-
require 'json'
|
5
|
-
require 'active_support'
|
6
|
-
require_relative '../../core/ITokenGeneration.rb'
|
7
|
-
require_relative '../../util/Constants.rb'
|
8
|
-
require_relative '../../util/ApiException.rb'
|
9
|
-
require_relative '../../util/Cache.rb'
|
10
|
-
require_relative '../../authentication/payloadDigest/digest.rb'
|
11
|
-
public
|
12
|
-
#JWT Token-generated based on the Request type
|
13
|
-
class GenerateJwtToken
|
14
|
-
def getToken(merchantconfig_obj,gmtDatetime,log_obj)
|
15
|
-
jwtBody = ''
|
16
|
-
request_type = merchantconfig_obj.requestType.upcase
|
17
|
-
filePath = merchantconfig_obj.keysDirectory + '/' + merchantconfig_obj.keyFilename + '.p12'
|
18
|
-
if (!File.exist?(filePath))
|
19
|
-
raise Constants::ERROR_PREFIX + Constants::FILE_NOT_FOUND + File.expand_path(filePath)
|
20
|
-
end
|
21
|
-
p12File = File.binread(filePath)
|
22
|
-
jwtBody=getJwtBody(request_type, gmtDatetime, merchantconfig_obj, log_obj)
|
23
|
-
claimSet = JSON.parse(jwtBody)
|
24
|
-
p12FilePath = OpenSSL::PKCS12.new(p12File, merchantconfig_obj.keyPass)
|
25
|
-
# Generating certificate.
|
26
|
-
cacheObj = ActiveSupport::Cache::MemoryStore.new
|
27
|
-
x5Cert = Cache.new.fetchCachedCertificate(filePath, p12File, merchantconfig_obj.keyPass, cacheObj)
|
28
|
-
# Generating Public key.
|
29
|
-
publicKey = OpenSSL::PKey::RSA.new(p12FilePath.key.public_key)
|
30
|
-
#Generating Private Key
|
31
|
-
privateKey = OpenSSL::PKey::RSA.new(p12FilePath.key)
|
32
|
-
# JWT token-Generates using RS256 algorithm only
|
33
|
-
x5clist = [x5Cert]
|
34
|
-
customHeaders = {}
|
35
|
-
customHeaders['v-c-merchant-id'] = merchantconfig_obj.keyAlias
|
36
|
-
customHeaders['x5c'] = x5clist
|
37
|
-
# Generating JWT token
|
38
|
-
token = JWT.encode(claimSet, privateKey, 'RS256', customHeaders)
|
39
|
-
return token
|
40
|
-
rescue StandardError => err
|
41
|
-
if err.message.include? 'PKCS12_parse: mac verify failure'
|
42
|
-
ApiException.new.customerror(Constants::ERROR_PREFIX + Constants::INCORRECT_KEY_PASS,log_obj)
|
43
|
-
exit!
|
44
|
-
else
|
45
|
-
ApiException.new.apiexception(err,log_obj)
|
46
|
-
exit!
|
47
|
-
end
|
48
|
-
end
|
49
|
-
def getJwtBody(request_type, gmtDatetime, merchantconfig_obj,log_obj)
|
50
|
-
if request_type == Constants::POST_REQUEST_TYPE || request_type == Constants::PUT_REQUEST_TYPE || request_type == Constants::PATCH_REQUEST_TYPE
|
51
|
-
payload = merchantconfig_obj.requestJsonData
|
52
|
-
# Note: Digest is not passed for GET calls
|
53
|
-
digest = DigestGeneration.new.generateDigest(payload, log_obj)
|
54
|
-
jwtBody = "{\n \"digest\":\"" + digest + "\", \"digestAlgorithm\":\"SHA-256\", \"iat\":\"" + gmtDatetime + "\"}"
|
55
|
-
elsif request_type == Constants::GET_REQUEST_TYPE || request_type == Constants::DELETE_REQUEST_TYPE
|
56
|
-
jwtBody = "{\n \"iat\":\"" + gmtDatetime + "\"\n} \n\n"
|
57
|
-
else
|
58
|
-
raise StandardError.new(Constants::ERROR_PREFIX + Constants::INVALID_REQUEST_TYPE_METHOD)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
implements TokenInterface
|
62
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'digest'
|
2
|
-
public
|
3
|
-
# This method return Digest value which is SHA-256
|
4
|
-
# hash of payload that is BASE64 encoded
|
5
|
-
class DigestGeneration
|
6
|
-
def generateDigest(payload, log_obj)
|
7
|
-
digest = Digest::SHA256.base64digest(payload)
|
8
|
-
return digest
|
9
|
-
end
|
10
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative '../authentication/http/HttpSignatureHeader.rb'
|
2
|
-
require_relative '../authentication/jwt/JwtToken.rb'
|
3
|
-
require_relative '../util/Constants.rb'
|
4
|
-
require_relative '../util/ApiException.rb'
|
5
|
-
public
|
6
|
-
# This function calls for the generation of Signature message depending on the authentication type.
|
7
|
-
class Authorization
|
8
|
-
def getToken(merchantconfig_obj, gmtdatetime, log_obj)
|
9
|
-
authenticationType = merchantconfig_obj.authenticationType.upcase
|
10
|
-
if merchantconfig_obj.requestType.to_s.empty?
|
11
|
-
raise StandardError.new(Constants::ERROR_PREFIX + Constants::REQUEST_TYPE_EMPTY)
|
12
|
-
end
|
13
|
-
if authenticationType == Constants::AUTH_TYPE_HTTP
|
14
|
-
token = GenerateHttpSignature.new.getToken(merchantconfig_obj, gmtdatetime, log_obj)
|
15
|
-
elsif authenticationType == Constants::AUTH_TYPE_JWT
|
16
|
-
token = GenerateJwtToken.new.getToken(merchantconfig_obj, gmtdatetime, log_obj)
|
17
|
-
elsif authenticationType != Constants::AUTH_TYPE_HTTP || authenticationType != Constants::AUTH_TYPE_JWT
|
18
|
-
raise StandardError.ner(Constants::ERROR_PREFIX + Constants::AUTH_ERROR)
|
19
|
-
end
|
20
|
-
rescue StandardError => err
|
21
|
-
ApiException.new.apiexception(err,log_obj)
|
22
|
-
exit!
|
23
|
-
end
|
24
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require_relative '../util/ApiException.rb'
|
2
|
-
require 'logger'
|
3
|
-
public
|
4
|
-
# Logger Class
|
5
|
-
class Log
|
6
|
-
def initialize(logDirectory, logFilename, logSize, enableLog)
|
7
|
-
#log
|
8
|
-
if enableLog == true
|
9
|
-
filename = logDirectory + '/' + logFilename + '.log'
|
10
|
-
datetime = DateTime.now
|
11
|
-
if File.exist?(filename) && File.size(filename) >= logSize
|
12
|
-
updatedFileName = logDirectory + '/' + logFilename + '_' + datetime.strftime('%Y%m%d%H%M%S') + '.log'
|
13
|
-
File.rename(filename, updatedFileName)
|
14
|
-
end
|
15
|
-
@logger = Logger.new(STDOUT)
|
16
|
-
@logger = Logger.new(filename, logSize)
|
17
|
-
@logger.datetime_format = datetime.strftime('%Y-%m-%d %H:%M:%S')
|
18
|
-
else
|
19
|
-
@logger = Logger.new(false)
|
20
|
-
end
|
21
|
-
rescue StandardError => err
|
22
|
-
puts err
|
23
|
-
exit!
|
24
|
-
end
|
25
|
-
attr_accessor :logger
|
26
|
-
end
|