mastercard_api_core 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mastercard/core/config.rb +35 -16
- data/lib/mastercard/core/constants.rb +25 -0
- data/lib/mastercard/core/controller.rb +21 -20
- data/lib/mastercard/core/model.rb +6 -1
- data/lib/mastercard/core/util.rb +11 -2
- data/lib/mastercard/security/oauth.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 935f938b44f37f40d32dc83246584931f8859a9f
|
4
|
+
data.tar.gz: d4b93fb4e1c91b374113ac6008f4b9c78edd9713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19f4e5015aa084f5090fa4d5d245080d03228b48d9ed5d0d424734e8df7e8c3f95f35eb0035efb3a4d55a3f0787a696524ef9d1901b9dca4e8ce40aa8ec2a445
|
7
|
+
data.tar.gz: 920550390ae05f073b126b369832ec7cb66f002c1d6ba3106879afa4ed13ab18b8249e9c0bcf8e3dea3ab2891f8d3b1a49187aaf377abcd0079da0ed0da6cf59
|
@@ -31,10 +31,10 @@ module MasterCard
|
|
31
31
|
class Config
|
32
32
|
|
33
33
|
private
|
34
|
-
@@sandbox = true
|
35
34
|
@@debug = false
|
36
|
-
@@
|
37
|
-
@@
|
35
|
+
@@environment = Environment::SANDBOX
|
36
|
+
@@authentication = nil;
|
37
|
+
@@registeredInstances = {}
|
38
38
|
|
39
39
|
public
|
40
40
|
def self.setDebug(debug)
|
@@ -46,21 +46,33 @@ module MasterCard
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.setSandbox(sandbox)
|
49
|
-
|
49
|
+
if sandbox
|
50
|
+
@@environment = Environment::SANDBOX
|
51
|
+
else
|
52
|
+
@@environment = Environment::PRODUCTION
|
53
|
+
end
|
50
54
|
end
|
51
|
-
|
52
|
-
def self.isSandbox
|
53
|
-
return @@
|
55
|
+
|
56
|
+
def self.isSandbox
|
57
|
+
return @@environment == Environment::SANDBOX
|
54
58
|
end
|
55
59
|
|
56
|
-
|
57
|
-
|
60
|
+
|
61
|
+
def self.getEnvironment
|
62
|
+
return @@environment
|
58
63
|
end
|
64
|
+
|
65
|
+
def self.setEnvironment(environment)
|
59
66
|
|
60
|
-
|
61
|
-
|
67
|
+
if !environment.nil? && !environment.empty?
|
68
|
+
if Environment::MAPPING.key?(environment)
|
69
|
+
@@registeredInstances.values().each { |instance| instance.setEnvironment(environment) }
|
70
|
+
@@environment = environment
|
71
|
+
end
|
72
|
+
end
|
62
73
|
end
|
63
74
|
|
75
|
+
|
64
76
|
def self.setAuthentication(auth)
|
65
77
|
@@authentication = auth
|
66
78
|
end
|
@@ -69,13 +81,20 @@ module MasterCard
|
|
69
81
|
return @@authentication
|
70
82
|
end
|
71
83
|
|
72
|
-
def self.
|
73
|
-
if
|
74
|
-
|
75
|
-
else
|
76
|
-
return Constants::API_BASE_LIVE_URL
|
84
|
+
def self.registerResourceConfig(instance)
|
85
|
+
if !@@registeredInstances.key?(instance.class.name)
|
86
|
+
@@registeredInstances[instance.class.name] = instance
|
77
87
|
end
|
78
88
|
end
|
89
|
+
|
90
|
+
def self.clearResourceConfig
|
91
|
+
@@registeredInstances = {}
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.sizeResourceConfig
|
95
|
+
return @@registeredInstances.length
|
96
|
+
end
|
97
|
+
|
79
98
|
end
|
80
99
|
end
|
81
100
|
end
|
@@ -30,5 +30,30 @@ module MasterCard
|
|
30
30
|
API_BASE_LIVE_URL = "https://api.mastercard.com"
|
31
31
|
API_BASE_SANDBOX_URL = "https://sandbox.api.mastercard.com"
|
32
32
|
end
|
33
|
+
|
34
|
+
module Environment
|
35
|
+
PRODUCTION = "production"
|
36
|
+
SANDBOX = "sandbox"
|
37
|
+
STAGE = "stage"
|
38
|
+
DEV = "dev"
|
39
|
+
MTF = "mtf"
|
40
|
+
ITF = "itf"
|
41
|
+
LOCALHOST = "localhost"
|
42
|
+
DEVCLOUD = "devcloud"
|
43
|
+
LABSCLOUD = "labscloud"
|
44
|
+
OTHER1 = "other1"
|
45
|
+
OTHER2 = "other2"
|
46
|
+
OTHER3 = "other3"
|
47
|
+
MAPPING = {
|
48
|
+
"production" => ["https://api.mastercard.com", nil],
|
49
|
+
"sandbox" => ["https://sandbox.api.mastercard.com", nil],
|
50
|
+
"stage" => ["https://stage.api.mastercard.com", nil],
|
51
|
+
"dev" => ["https://dev.api.mastercard.com", nil],
|
52
|
+
"mtf" => ["https://sandbox.api.mastercard.com", "mtf"],
|
53
|
+
"itf" => ["https://sandbox.api.mastercard.com", "itf"],
|
54
|
+
"localhost" => ["http://localhost:8081", nil]
|
55
|
+
}
|
56
|
+
|
57
|
+
end
|
33
58
|
end
|
34
59
|
end
|
@@ -56,28 +56,20 @@ module MasterCard
|
|
56
56
|
JSON_STR = "JSON"
|
57
57
|
|
58
58
|
|
59
|
-
def initialize()
|
60
|
-
#Set the parameters
|
61
|
-
@baseURL = Config.getAPIBaseURL()
|
62
|
-
|
63
|
-
@baseURL = removeForwardSlashFromTail(@baseURL)
|
64
|
-
|
65
|
-
#Verify if the URL is correct
|
66
|
-
unless Util.validateURL(@baseURL)
|
67
|
-
raise APIException.new "URL: '" + @baseURL + "' is not a valid url"
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
59
|
def execute(config,metadata,input)
|
73
60
|
|
74
61
|
#Check preconditions for execute
|
75
62
|
preCheck()
|
76
63
|
|
77
|
-
resolvedHost =
|
78
|
-
|
79
|
-
|
64
|
+
resolvedHost = metadata.getHost()
|
65
|
+
if resolvedHost != nil && resolvedHost != 0
|
66
|
+
unless Util.validateURL(resolvedHost)
|
67
|
+
raise APIException.new "URL: '" + resolvedHost + "' is not a valid url"
|
68
|
+
end
|
69
|
+
else
|
70
|
+
raise APIException.new "URL: '' is not a valid url"
|
80
71
|
end
|
72
|
+
|
81
73
|
|
82
74
|
uri = URI.parse(resolvedHost)
|
83
75
|
#Get the http object
|
@@ -221,12 +213,21 @@ module MasterCard
|
|
221
213
|
queryParams = Util.subMap(input,config.getQueryParams())
|
222
214
|
|
223
215
|
#We need to resolve the host
|
224
|
-
resolvedHost =
|
225
|
-
|
226
|
-
|
216
|
+
resolvedHost = metadata.getHost()
|
217
|
+
|
218
|
+
resourcePath = config.getResoucePath().dup
|
219
|
+
if (resourcePath.index("{:env}"))
|
220
|
+
contenxt = ""
|
221
|
+
|
222
|
+
if !metadata.getContext().nil? && !metadata.getContext().empty?
|
223
|
+
contenxt = metadata.getContext()
|
224
|
+
end
|
225
|
+
|
226
|
+
resourcePath.sub!("{:env}", contenxt)
|
227
|
+
resourcePath.sub!("//", "/")
|
227
228
|
end
|
228
229
|
|
229
|
-
fullUrl = resolvedHost +
|
230
|
+
fullUrl = resolvedHost + resourcePath
|
230
231
|
|
231
232
|
#Get the resourcePath containing values from input
|
232
233
|
fullUrl = getFullResourcePath(config.getAction(),fullUrl,input)
|
@@ -347,9 +347,10 @@ module MasterCard
|
|
347
347
|
|
348
348
|
class OperationMetadata
|
349
349
|
|
350
|
-
def initialize(version, host)
|
350
|
+
def initialize(version, host, context = nil)
|
351
351
|
@version = version
|
352
352
|
@host = host
|
353
|
+
@context = context
|
353
354
|
end
|
354
355
|
|
355
356
|
def getVersion()
|
@@ -359,6 +360,10 @@ module MasterCard
|
|
359
360
|
def getHost()
|
360
361
|
return @host
|
361
362
|
end
|
363
|
+
|
364
|
+
def getContext()
|
365
|
+
return @context
|
366
|
+
end
|
362
367
|
|
363
368
|
end
|
364
369
|
|
data/lib/mastercard/core/util.rb
CHANGED
@@ -36,8 +36,11 @@ module MasterCard
|
|
36
36
|
def validateURL(url)
|
37
37
|
#
|
38
38
|
# Validates that the given string is a valid URL
|
39
|
-
|
40
|
-
|
39
|
+
if url =~ URI::DEFAULT_PARSER.make_regexp
|
40
|
+
return true
|
41
|
+
else
|
42
|
+
return false
|
43
|
+
end
|
41
44
|
end
|
42
45
|
|
43
46
|
def normalizeParams(url,params)
|
@@ -131,6 +134,12 @@ module MasterCard
|
|
131
134
|
return base64Encode(Digest::SHA1.digest text)
|
132
135
|
end
|
133
136
|
|
137
|
+
def sha256Base64Encode(text)
|
138
|
+
#
|
139
|
+
#Base 64 encodes the SHA1 digest of text
|
140
|
+
return base64Encode(Digest::SHA256.digest text)
|
141
|
+
end
|
142
|
+
|
134
143
|
def uriRfc3986Encode(value)
|
135
144
|
#
|
136
145
|
#RFC 3986 encodes the value
|
@@ -59,7 +59,7 @@ module MasterCard
|
|
59
59
|
oAuthParameters.setOAuthConsumerKey(@clientId)
|
60
60
|
oAuthParameters.setOAuthNonce(Util.getNonce())
|
61
61
|
oAuthParameters.setOAuthTimestamp(Util.getTimestamp())
|
62
|
-
oAuthParameters.setOAuthSignatureMethod("RSA-
|
62
|
+
oAuthParameters.setOAuthSignatureMethod("RSA-SHA256")
|
63
63
|
oAuthParameters.setOAuthVersion("1.0")
|
64
64
|
|
65
65
|
if body.nil?
|
@@ -72,7 +72,7 @@ module MasterCard
|
|
72
72
|
#Do nothing and hope for the best
|
73
73
|
end
|
74
74
|
|
75
|
-
encodedHash =
|
75
|
+
encodedHash = sha256Base64Encode(body)
|
76
76
|
oAuthParameters.setOAuthBodyHash(encodedHash)
|
77
77
|
|
78
78
|
return oAuthParameters
|
@@ -133,7 +133,7 @@ module MasterCard
|
|
133
133
|
privateKeyFile = File.read(@privateKey)
|
134
134
|
|
135
135
|
p12 = OpenSSL::PKCS12.new(privateKeyFile, @password)
|
136
|
-
sign = p12.key.sign OpenSSL::Digest::
|
136
|
+
sign = p12.key.sign OpenSSL::Digest::SHA256.new, message
|
137
137
|
|
138
138
|
return base64Encode(sign)
|
139
139
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mastercard_api_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MasterCard Worldwide
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|