Skip to content

Commit a6224d4

Browse files
committed
# Conflicts: # lib/AuthenticationSDK/core/MerchantConfig.rb # lib/AuthenticationSDK/util/Constants.rb
2 parents 8b3070b + 473138e commit a6224d4

File tree

4 files changed

+83
-125
lines changed

4 files changed

+83
-125
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,49 @@ The CyberSource Ruby client provides convenient access to the [CyberSource REST
88
[rubygems]: https://rubygems.org/gems/cybersource_rest_client
99

1010
## Requirements
11+
1112
* Ruby 2.5.0 or higher
1213
* [CyberSource Account](https://developer.cybersource.com/api/developer-guides/dita-gettingstarted/registration.html)
1314
* [CyberSource API Keys](https://prod.developer.cybersource.com/api/developer-guides/dita-gettingstarted/registration/createCertSharedKey.html)
1415

1516
## Dependencies
17+
1618
* activesupport 6.0.3.2
1719
* interface 1.0.4
1820
* json 2.1.0
1921
* jwt 2.1.0
2022
* typhoeus 1.3.1
2123

2224
## Installation
25+
2326
### Bundler
24-
Be sure to always use HTTPS rubygems source in your gemfile and include the cybersource_rest_client.
2527

26-
```
27-
source 'https://rubygems.org' do
28-
gem 'cybersource_rest_client'
29-
end
28+
Be sure to always use HTTPS rubygems source in your gemfile and include the cybersource_rest_client.
3029

30+
```ruby
31+
source 'https://rubygems.org' do
32+
gem 'cybersource_rest_client'
33+
end
3134
```
3235

3336
## Registration & Configuration
37+
3438
Use of this SDK and the CyberSource APIs requires having an account on our system. You can find details of getting a test account and creating your keys [here](https://developer.cybersource.com/api/developer-guides/dita-gettingstarted/registration.html)
3539

3640
Once you have your keys, simply load them into the appropriate variables in your code, as per the below sample code dealing with the authentication part of the API request.
3741

3842
Remember this SDK is for use in server-side Ruby applications that access the CyberSource REST API and credentials should always be securely stored and accessed appropriately.
3943

4044
## SDK Usage Examples and Sample Code
45+
4146
To get started using this SDK, it's highly recommended to download our sample code repository:
42-
* [Cybersource Ruby Sample Code Repository (on GitHub)](https://github.com/CyberSource/cybersource-rest-samples-ruby)
47+
48+
* [CyberSource Ruby Sample Code Repository (on GitHub)](https://github.com/CyberSource/cybersource-rest-samples-ruby)
4349

4450
In that respository, we have comprehensive sample code for all common uses of our API:
4551

4652
Additionally, you can find details and examples of how our API is structured in our API Reference Guide:
53+
4754
* [Developer Center API Reference](https://developer.cybersource.com/api/reference/api-reference.html)
4855

4956
The API Reference Guide provides examples of what information is needed for a particular request and how that information would be formatted. Using those examples, you can easily determine what methods would be necessary to include that information in a request using this SDK.
@@ -59,18 +66,18 @@ MIDs continue to be able to create keys for themselves, even if a Meta Key is ge
5966
Further information on MetaKey can be found in [New Business Center User Guide](https://developer.cybersource.com/library/documentation/dev_guides/Business_Center/New_Business_Center_User_Guide.pdf).
6067

6168
### Switching between the sandbox environment and the production environment
62-
Cybersource maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this SDK is configured to communicate with the sandbox environment. To switch to the production environment, set the `runEnvironment` property in the SDK Configuration. See our sample at https://github.com/CyberSource/cybersource-rest-samples-ruby/blob/master/data/Configuration.rb
69+
70+
CyberSource maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this SDK is configured to communicate with the sandbox environment. To switch to the production environment, set the `runEnvironment` property in the SDK Configuration. See our sample at <https://github.com/CyberSource/cybersource-rest-samples-ruby/blob/master/data/Configuration.rb>
6371

6472
```Ruby
6573
# For TESTING use
66-
runEnvironment='cybersource.environment.sandbox'
74+
runEnvironment='apitest.cybersource.com'
6775
# For PRODUCTION use
68-
# runEnvironment='cybersource.environment.production'
76+
# runEnvironment='api.cybersource.com'
6977
```
7078

7179
API credentials are different for each environment, so be sure to switch to the appropriate credentials when switching environments.
7280

73-
74-
7581
## License
82+
7683
This repository is distributed under a proprietary license. See the provided [`LICENSE.txt`](/LICENSE.txt) file.

cybersource_rest_client.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
2525
s.summary = "CyberSource Ruby SDK Gem"
2626
s.description = "Simple REST API for the CyberSource Global Payments Platform"
2727
s.license = "CyberSource"
28-
s.files = Dir.glob("{lib}/**/*")
28+
s.files = Dir.glob("{lib}/{cybersource_rest_client}/**/*") + Dir.glob("{lib}/{AuthenticationSDK}/authentication/**/*") + Dir.glob("{lib}/{AuthenticationSDK}/core/**/*") + Dir.glob("{lib}/{AuthenticationSDK}/util/**/*") + Dir.glob("{lib}/cybersource_rest_client.rb")
2929
s.required_ruby_version = ">= 1.9"
3030

3131
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'

lib/AuthenticationSDK/core/MerchantConfig.rb

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,11 @@ def validateMerchantDetails()
8484
if !@runEnvironment.to_s.empty?
8585
if !@runEnvironment.instance_of? String
8686
@requestHost = @runEnvironment.to_s
87-
elsif @runEnvironment.upcase == Constants::RUN_ENV_PROD
88-
@requestHost = Constants::PRODUCTION_URL
89-
elsif @runEnvironment.upcase == Constants::RUN_ENV_SANDBOX
90-
@requestHost = Constants::SANDBOX_URL
91-
elsif @runEnvironment.upcase == Constants::BOA_RUN_ENV_PROD
92-
@requestHost = Constants::BOA_PRODUCTION_URL
93-
elsif @runEnvironment.upcase == Constants::BOA_RUN_ENV_SANDBOX
94-
@requestHost = Constants::BOA_SANDBOX_URL
95-
elsif @runEnvironment.upcase == Constants::IDC_RUN_ENV_PROD
96-
@requestHost = Constants::IDC_PRODUCTION_URL
97-
elsif @runEnvironment.upcase == Constants::IDC_RUN_ENV_SANDBOX
98-
@requestHost = Constants::IDC_SANDBOX_URL
99-
elsif @runEnvironment.upcase == Constants::RUN_ENV_MUTUAL_AUTH_SANDBOX
100-
@requestHost = Constants::MA_SANDBOX_URL
101-
elsif @runEnvironment.upcase == Constants::RUN_ENV_MUTUAL_AUTH_PROD
102-
@requestHost = Constants::MA_PRODUCTION_URL
103-
elsif @runEnvironment.upcase == Constants::RUN_ENV_SIT
104-
@requestHost = Constants::SIT_URL
105-
elsif @runEnvironment.upcase == Constants::RUN_ENV_MUTUAL_AUTH_SIT
106-
@requestHost = Constants::MA_SIT_URL
87+
end
88+
89+
if Constants::OLD_RUN_ENVIRONMENT_CONSTANTS.include?(@runEnvironment.upcase)
90+
err = raise StandardError.new(Constants::ERROR_PREFIX + Constants::DERPECATED_ENVIRONMENT)
91+
ApiException.new.apiexception(err, log_obj)
10792
else
10893
@requestHost = @runEnvironment
10994
end
Lines changed: 59 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,141 @@
11
class Constants
22

33
GET_REQUEST_TYPE_LOWER = 'get' unless const_defined?(:GET_REQUEST_TYPE_LOWER)
4-
4+
55
POST_REQUEST_TYPE_LOWER = 'post' unless const_defined?(:POST_REQUEST_TYPE_LOWER)
6-
6+
77
PUT_REQUEST_TYPE_LOWER = 'put' unless const_defined?(:PUT_REQUEST_TYPE_LOWER)
88

99
PATCH_REQUEST_TYPE_LOWER = 'patch' unless const_defined?(:PATCH_REQUEST_TYPE_LOWER)
10-
10+
1111
DELETE_REQUEST_TYPE_LOWER = 'delete' unless const_defined?(:DELETE_REQUEST_TYPE_LOWER)
1212

1313
GET_REQUEST_TYPE = 'GET' unless const_defined?(:GET_REQUEST_TYPE)
14-
14+
1515
POST_REQUEST_TYPE = 'POST' unless const_defined?(:POST_REQUEST_TYPE)
16-
16+
1717
PUT_REQUEST_TYPE = 'PUT' unless const_defined?(:PUT_REQUEST_TYPE)
1818

1919
PATCH_REQUEST_TYPE = 'PATCH' unless const_defined?(:PATCH_REQUEST_TYPE)
20-
20+
2121
DELETE_REQUEST_TYPE = 'DELETE' unless const_defined?(:DELETE_REQUEST_TYPE)
2222

2323
V_C_MERCHANT_ID = 'v-c-merchant-id' unless const_defined?(:V_C_MERCHANT_ID)
24-
24+
2525
HOST = 'host' unless const_defined?(:HOST)
26-
26+
2727
DATE = 'date' unless const_defined?(:DATE)
28-
28+
2929
REQUEST_TARGET = '(request-target)' unless const_defined?(:REQUEST_TARGET)
30-
30+
3131
DIGEST = 'digest' unless const_defined?(:DIGEST)
32-
32+
3333
SIGNATURE = 'Signature' unless const_defined?(:SIGNATURE)
34-
34+
3535
HTTPS_URI_PREFIX = 'https://' unless const_defined?(:HTTPS_URI_PREFIX)
36-
36+
3737
BEARER = 'Bearer' unless const_defined?(:BEARER)
38-
38+
3939
MEDIA_TYPE_JSON = 'application/json' unless const_defined?(:MEDIA_TYPE_JSON)
40-
40+
4141
SIGNATURE_ALGORITHM = 'HmacSHA256' unless const_defined?(:SIGNATURE_ALGORITHM)
42-
42+
4343
ALGORITHM = "algorithm=\"" unless const_defined?(:ALGORITHM)
44-
44+
4545
SHA256 = 'SHA-256=' unless const_defined?(:SHA256)
46-
46+
4747
CONTENT_TYPE = 'Content-Type' unless const_defined?(:CONTENT_TYPE)
48-
48+
4949
USER_AGENT = 'User-Agent' unless const_defined?(:USER_AGENT)
50-
50+
5151
USER_AGENT_VALUE = 'Mozilla/5.0' unless const_defined?(:USER_AGENT_VALUE)
52-
52+
5353
KEY_ID = "keyid=\"" unless const_defined?(:KEY_ID)
54-
54+
5555
HEADERS_PARAM = "headers=\"" unless const_defined?(:HEADERS_PARAM)
56-
56+
5757
SIGNATURE_PARAM = "signature=\"" unless const_defined?(:SIGNATURE_PARAM)
5858

5959
AUTH_TYPE_HTTP = 'HTTP_SIGNATURE' unless const_defined?(:AUTH_TYPE_HTTP)
60-
61-
AUTH_TYPE_JWT = 'JWT' unless const_defined?(:AUTH_TYPE_JWT)
6260

6361
AUTH_TYPE_OAUTH = 'OAUTH' unless const_defined?(:AUTH_TYPE_OAUTH)
6462

6563
AUTH_TYPE_MUTUAL_AUTH = 'MUTUAL_AUTH' unless const_defined?(:AUTH_TYPE_MUTUAL_AUTH)
64+
65+
AUTH_TYPE_JWT = 'JWT' unless const_defined?(:AUTH_TYPE_JWT)
6666

67-
RUN_ENV_SANDBOX = 'CYBERSOURCE.ENVIRONMENT.SANDBOX' unless const_defined?(:RUN_ENV_SANDBOX)
68-
69-
RUN_ENV_MUTUAL_AUTH_SANDBOX = 'CYBERSOURCE.ENVIRONMENT.MUTUALAUTH.SANDBOX' unless const_defined?(:RUN_ENV_MUTUAL_AUTH_SANDBOX)
70-
71-
RUN_ENV_PROD = 'CYBERSOURCE.ENVIRONMENT.PRODUCTION'unless const_defined?(:RUN_ENV_PROD)
72-
73-
RUN_ENV_MUTUAL_AUTH_PROD = 'CYBERSOURCE.ENVIRONMENT.MUTUALAUTH.PRODUCTION' unless const_defined?(:RUN_ENV_MUTUAL_AUTH_PROD)
74-
75-
RUN_ENV_SIT = 'CYBERSOURCE.ENVIRONMENT.SIT' unless const_defined?(:RUN_ENV_SIT)
76-
77-
RUN_ENV_MUTUAL_AUTH_SIT = 'CYBERSOURCE.ENVIRONMENT.MUTUALAUTH.SIT' unless const_defined?(:RUN_ENV_MUTUAL_AUTH_SIT)
78-
79-
SANDBOX_URL = 'apitest.cybersource.com' unless const_defined?(:SANDBOX_URL)
80-
81-
SIT_URL = 'pnrstage.ic3.com:7448' unless const_defined?(:SIT_URL)
82-
83-
MA_SIT_URL = 'pnrstage.ic3.com:8451' unless const_defined?(:MA_SIT_URL)
84-
85-
MA_SANDBOX_URL = 'api-matest.cybersource.com' unless const_defined?(:MA_SANDBOX_URL)
86-
87-
PRODUCTION_URL = 'api.cybersource.com' unless const_defined?(:PRODUCTION_URL)
88-
89-
MA_PRODUCTION_URL = 'api-ma.cybersource.com' unless const_defined?(:MA_PRODUCTION_URL)
90-
91-
BOA_RUN_ENV_SANDBOX = 'BANKOFAMERICA.ENVIRONMENT.SANDBOX' unless const_defined?(:BOA_RUN_ENV_SANDBOX)
92-
93-
BOA_RUN_ENV_PROD = 'BANKOFAMERICA.ENVIRONMENT.PRODUCTION' unless const_defined?(:BOA_RUN_ENV_PROD)
94-
95-
BOA_SANDBOX_URL = 'apitest.merchant-services.bankofamerica.com' unless const_defined?(:BOA_SANDBOX_URL)
96-
97-
BOA_PRODUCTION_URL = 'api.merchant-services.bankofamerica.com' unless const_defined?(:BOA_PRODUCTION_URL)
98-
99-
IDC_RUN_ENV_SANDBOX = 'CYBERSOURCE.IN.ENVIRONMENT.SANDBOX' unless const_defined?(:IDC_RUN_ENV_SANDBOX)
100-
101-
IDC_RUN_ENV_PROD = 'CYEBRSOURCE.IN.ENVIRONMENT.PRODUCTION' unless const_defined?(:IDC_RUN_ENV_PROD)
102-
103-
IDC_SANDBOX_URL = 'apitest.cybersource.com' unless const_defined?(:IDC_SANDBOX_URL)
104-
105-
IDC_PRODUCTION_URL = 'api.in.cybersource.com' unless const_defined?(:IDC_PRODUCTION_URL)
67+
OLD_RUN_ENVIRONMENT_CONSTANTS = ['CYBERSOURCE.ENVIRONMENT.SANDBOX', 'CYBERSOURCE.ENVIRONMENT.MUTUALAUTH.SANDBOX', 'CYBERSOURCE.ENVIRONMENT.PRODUCTION',
68+
'CYBERSOURCE.ENVIRONMENT.MUTUALAUTH.PRODUCTION', 'CYBERSOURCE.IN.ENVIRONMENT.SANDBOX', 'CYBERSOURCE.IN.ENVIRONMENT.PRODUCTION', 'CYBERSOURCE.ENVIRONMENT.SIT',
69+
'CYBERSOURCE.ENVIRONMENT.MUTUALAUTH.SIT', 'BANKOFAMERICA.ENVIRONMENT.SANDBOX', 'BANKOFAMERICA.ENVIRONMENT.PRODUCTION']
10670

10771
# constants for fall back logic
10872

10973
DEFAULT_LOG_SIZE = 10485760 unless const_defined?(:DEFAULT_LOG_SIZE)
110-
74+
11175
DEFAULT_PROXY_ADDRESS = 'userproxy.visa.com' unless const_defined?(:DEFAULT_PROXY_ADDRESS)
112-
76+
11377
DEFAULT_PROXY_PORT = '443' unless const_defined?(:DEFAULT_PROXY_PORT)
114-
78+
11579
DEFAULT_TIMEOUT = '1000' unless const_defined?(:DEFAULT_TIMEOUT)
116-
80+
11781
DEFAULT_LOG_DIRECTORY = '../log' unless const_defined?(:DEFAULT_LOG_DIRECTORY)
118-
82+
11983
DEFAULT_KEY_DIRECTORY = 'resource' unless const_defined?(:DEFAULT_KEY_DIRECTORY)
120-
84+
12185
DEFAULT_LOGFILE_NAME = 'cybs' unless const_defined?(:DEFAULT_LOGFILE_NAME)
12286

12387
# Constant for Fall back logic and Exception Handling
12488

12589
REQUEST_JSON_ERROR = 'Request Json File missing. File Path :: ' unless const_defined?(:REQUEST_JSON_ERROR)
126-
90+
12791
INVALID_ENABLE_LOG = 'EnableLog should be (True/False) in cybs.yml' unless const_defined?(:INVALID_ENABLE_LOG)
128-
92+
12993
REFER_LOG = 'Please refer Log for details' unless const_defined?(:REFER_LOG)
130-
94+
13195
MERCHANT_ID_NULL = 'MerchantID is mandatory' unless const_defined?(:MERCHANT_ID_NULL)
132-
96+
13397
INCORRECT_KEY_PASS = 'The keyPass Entered is Incorrect' unless const_defined?(:INCORRECT_KEY_PASS)
134-
98+
13599
AUTH_TYPE_MANDATORY= 'AuthenticationType is Mandatory' unless const_defined?(:AUTH_TYPE_MANDATORY)
136-
100+
137101
MERCHANT_KEY_ID_MANDATORY = 'MerchantKeyId is Mandatory' unless const_defined?(:MERCHANT_KEY_ID_MANDATORY)
138-
102+
139103
MERCHANT_SECRET_KEY_MANDATORY = 'MerchantSecretKey is Mandatory' unless const_defined?(:MERCHANT_SECRET_KEY_MANDATORY)
140104

141105
PORTFOLIO_ID_MANDATORY = 'PortfolioID is Mandatory' unless const_defined?(:PORTFOLIO_ID_MANDATORY)
142-
106+
143107
KEY_PASS_NULL = 'keyPass is empty, Assigining merchantID value' unless const_defined?(:KEY_PASS_NULL)
144-
108+
145109
REQUEST_JSON_PATH_EMPTY = 'RequestJsonPath not provided. Using Default Value:'unless const_defined?(:REQUEST_JSON_PATH_EMPTY)
146-
110+
147111
REQUEST_TYPE_EMPTY = 'RequestType Property of Merchant Config Not Set' unless const_defined?(:REQUEST_TYPE_EMPTY)
148-
112+
149113
INVALID_REQUEST_TYPE_METHOD = 'Entered Request Type should be (GET/POST/PUT)' unless const_defined?(:INVALID_REQUEST_TYPE_METHOD)
150-
114+
151115
INVALID_LOG_DIRECTORY = 'Entered LogDirectory is Incorrect. Using Default Path: ' unless const_defined?(:INVALID_LOG_DIRECTORY)
152-
116+
153117
RUN_ENVIRONMENT_ERROR = 'Entered RunEnvironment is Incorrect.' unless const_defined?(:RUN_ENVIRONMENT_ERROR)
154-
118+
155119
PROPERTY_FILE_NOT_FOUND = 'Cybs.yml file not found' unless const_defined?(:PROPERTY_FILE_NOT_FOUND)
156120

157121
ERROR_PREFIX = 'Error: ' unless const_defined?(:ERROR_PREFIX)
158-
122+
159123
WARNING_PREFIX = 'Warning: ' unless const_defined?(:WARNING_PREFIX)
160-
124+
161125
HIDDEN_MERCHANT_PROPERTIES = 'merchantID,merchantKeyId,merchantsecretKey,keyAlias,keyPass' unless const_defined?(:HIDDEN_MERCHANT_PROPERTIES)
162-
126+
163127
RUN_ENVIRONMENT = 'RunEnvironment is Mandatory' unless const_defined?(:RUN_ENVIRONMENT)
164-
128+
165129
KEY_DIRECTORY_EMPTY = 'KeysDirectory not provided. Using Default Path:' unless const_defined?(:KEY_DIRECTORY_EMPTY)
166-
130+
167131
FILE_NOT_FOUND = 'File not found, Re-Enter path/file name, Entered path/file name :: ' unless const_defined?(:FILE_NOT_FOUND)
168-
132+
169133
AUTH_ERROR = 'Check Authentication Type (HTTP_Signature/JWT) in cybs.yml.' unless const_defined?(:AUTH_ERROR)
170-
134+
171135
KEY_FILE_NAME_NULL_EMPTY = 'KeyFilename Empty/Null. Assigining merchantID value' unless const_defined?(:KEY_FILE_NAME_NULL_EMPTY)
172-
136+
173137
KEY_ALIAS_NULL_EMPTY = 'KeyAlias Empty/Null. Assigining merchantID value' unless const_defined?(:KEY_ALIAS_NULL_EMPTY)
174-
138+
175139
INCORRECT_KEY_ALIAS = 'The Entered KeyAlias is Incorrect. Assigining merchantID value' unless const_defined?(:INCORRECT_KEY_ALIAS)
176140

177141
ENABLE_CLIENT_CERT_EMPTY = 'Enable Clientcert is Empty/Null.' unless const_defined?(:ENABLE_CLIENT_CERT_EMPTY)
@@ -191,4 +155,6 @@ class Constants
191155
ACCESS_TOKEN_EMPTY = 'AccessToken is Empty/Null' unless const_defined?(:ACCESS_TOKEN_REQ)
192156

193157
REFRESH_TOKEN_EMPTY = 'RefreshToken is Empty/Null' unless const_defined?(:REFRESH_TOKEN_REQ)
158+
159+
DERPECATED_ENVIRONMENT = 'The value provided for this field `RunEnvironment` has been deprecated and will not be used anymore.\n\nPlease refer to the README file [ https://github.com/CyberSource/cybersource-rest-samples-node/blob/master/README.md ] for information about the new values that are accepted.'
194160
end

0 commit comments

Comments
 (0)