Skip to content

Commit 473138e

Browse files
committed
Removed hardcoded values for hostnames with check for backward compatibility
1 parent 62bb238 commit 473138e

File tree

4 files changed

+80
-100
lines changed

4 files changed

+80
-100
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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,11 @@ def validateMerchantDetails()
8080
if !@runEnvironment.to_s.empty?
8181
if !@runEnvironment.instance_of? String
8282
@requestHost = @runEnvironment.to_s
83-
elsif @runEnvironment.upcase == Constants::RUN_ENV_PROD
84-
@requestHost = Constants::PRODUCTION_URL
85-
elsif @runEnvironment.upcase == Constants::RUN_ENV_SANDBOX
86-
@requestHost = Constants::SANDBOX_URL
87-
elsif @runEnvironment.upcase == Constants::BOA_RUN_ENV_PROD
88-
@requestHost = Constants::BOA_PRODUCTION_URL
89-
elsif @runEnvironment.upcase == Constants.BOA_RUN_ENV_SANDBOX
90-
@requestHost = Constants::BOA_SANDBOX_URL
91-
elsif @runEnvironment.upcase == Constants::IDC_RUN_ENV_PROD
92-
@requestHost = Constants::IDC_PRODUCTION_URL
93-
elsif @runEnvironment.upcase == Constants.IDC_RUN_ENV_SANDBOX
94-
@requestHost = Constants::IDC_SANDBOX_URL
83+
end
84+
85+
if Constants::OLD_RUN_ENVIRONMENT_CONSTANTS.include?(@runEnvironment.upcase)
86+
err = raise StandardError.new(Constants::ERROR_PREFIX + Constants::DERPECATED_ENVIRONMENT)
87+
ApiException.new.apiexception(err, log_obj)
9588
else
9689
@requestHost = @runEnvironment
9790
end
Lines changed: 56 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,136 @@
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

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-
BOA_RUN_ENV_SANDBOX = 'BANKOFAMERICA.ENVIRONMENT.SANDBOX' unless const_defined?(:RUN_ENV_SANDBOX)
72-
73-
BOA_RUN_ENV_PROD = 'BANKOFAMERICA.ENVIRONMENT.PRODUCTION'unless const_defined?(:RUN_ENV_PROD)
74-
75-
BOA_SANDBOX_URL = 'apitest.merchant-services.bankofamerica.com' unless const_defined?(:SANDBOX_URL)
76-
77-
BOA_PRODUCTION_URL = 'api.merchant-services.bankofamerica.com' unless const_defined?(:PRODUCTION_URL)
78-
79-
IDC_RUN_ENV_SANDBOX = 'CYBERSOURCE.IN.ENVIRONMENT.SANDBOX' unless const_defined?(:RUN_ENV_SANDBOX)
80-
81-
IDC_RUN_ENV_PROD = 'CYEBRSOURCE.IN.ENVIRONMENT.PRODUCTION'unless const_defined?(:RUN_ENV_PROD)
82-
83-
IDC_SANDBOX_URL = 'apitest.cybersource.com' unless const_defined?(:SANDBOX_URL)
61+
AUTH_TYPE_JWT = 'JWT' unless const_defined?(:AUTH_TYPE_JWT)
8462

85-
IDC_PRODUCTION_URL = 'api.in.cybersource.com' unless const_defined?(:PRODUCTION_URL)
63+
OLD_RUN_ENVIRONMENT_CONSTANTS = ['CYBERSOURCE.ENVIRONMENT.SANDBOX', 'CYBERSOURCE.ENVIRONMENT.PRODUCTION', 'CYBERSOURCE.IN.ENVIRONMENT.SANDBOX', 'CYBERSOURCE.IN.ENVIRONMENT.PRODUCTION']
8664

8765
# constants for fall back logic
8866

8967
DEFAULT_LOG_SIZE = 10485760 unless const_defined?(:DEFAULT_LOG_SIZE)
90-
68+
9169
DEFAULT_PROXY_ADDRESS = 'userproxy.visa.com' unless const_defined?(:DEFAULT_PROXY_ADDRESS)
92-
70+
9371
DEFAULT_PROXY_PORT = '443' unless const_defined?(:DEFAULT_PROXY_PORT)
94-
72+
9573
DEFAULT_TIMEOUT = '1000' unless const_defined?(:DEFAULT_TIMEOUT)
96-
74+
9775
DEFAULT_LOG_DIRECTORY = '../log' unless const_defined?(:DEFAULT_LOG_DIRECTORY)
98-
76+
9977
DEFAULT_KEY_DIRECTORY = 'resource' unless const_defined?(:DEFAULT_KEY_DIRECTORY)
100-
78+
10179
DEFAULT_LOGFILE_NAME = 'cybs' unless const_defined?(:DEFAULT_LOGFILE_NAME)
10280

10381
# Constant for Fall back logic and Exception Handling
10482

10583
REQUEST_JSON_ERROR = 'Request Json File missing. File Path :: ' unless const_defined?(:REQUEST_JSON_ERROR)
106-
84+
10785
INVALID_ENABLE_LOG = 'EnableLog should be (True/False) in cybs.yml' unless const_defined?(:INVALID_ENABLE_LOG)
108-
86+
10987
REFER_LOG = 'Please refer Log for details' unless const_defined?(:REFER_LOG)
110-
88+
11189
MERCHANT_ID_NULL = 'MerchantID is mandatory' unless const_defined?(:MERCHANT_ID_NULL)
112-
90+
11391
INCORRECT_KEY_PASS = 'The keyPass Entered is Incorrect' unless const_defined?(:INCORRECT_KEY_PASS)
114-
92+
11593
AUTH_TYPE_MANDATORY= 'AuthenticationType is Mandatory' unless const_defined?(:AUTH_TYPE_MANDATORY)
116-
94+
11795
MERCHANT_KEY_ID_MANDATORY = 'MerchantKeyId is Mandatory' unless const_defined?(:MERCHANT_KEY_ID_MANDATORY)
118-
96+
11997
MERCHANT_SECRET_KEY_MANDATORY = 'MerchantSecretKey is Mandatory' unless const_defined?(:MERCHANT_SECRET_KEY_MANDATORY)
12098

12199
PORTFOLIO_ID_MANDATORY = 'PortfolioID is Mandatory' unless const_defined?(:PORTFOLIO_ID_MANDATORY)
122-
100+
123101
KEY_PASS_NULL = 'keyPass is empty, Assigining merchantID value' unless const_defined?(:KEY_PASS_NULL)
124-
102+
125103
REQUEST_JSON_PATH_EMPTY = 'RequestJsonPath not provided. Using Default Value:'unless const_defined?(:REQUEST_JSON_PATH_EMPTY)
126-
104+
127105
REQUEST_TYPE_EMPTY = 'RequestType Property of Merchant Config Not Set' unless const_defined?(:REQUEST_TYPE_EMPTY)
128-
106+
129107
INVALID_REQUEST_TYPE_METHOD = 'Entered Request Type should be (GET/POST/PUT)' unless const_defined?(:INVALID_REQUEST_TYPE_METHOD)
130-
108+
131109
INVALID_LOG_DIRECTORY = 'Entered LogDirectory is Incorrect. Using Default Path: ' unless const_defined?(:INVALID_LOG_DIRECTORY)
132-
110+
133111
RUN_ENVIRONMENT_ERROR = 'Entered RunEnvironment is Incorrect.' unless const_defined?(:RUN_ENVIRONMENT_ERROR)
134-
112+
135113
PROPERTY_FILE_NOT_FOUND = 'Cybs.yml file not found' unless const_defined?(:PROPERTY_FILE_NOT_FOUND)
136114

137115
ERROR_PREFIX = 'Error: ' unless const_defined?(:ERROR_PREFIX)
138-
116+
139117
WARNING_PREFIX = 'Warning: ' unless const_defined?(:WARNING_PREFIX)
140-
118+
141119
HIDDEN_MERCHANT_PROPERTIES = 'merchantID,merchantKeyId,merchantsecretKey,keyAlias,keyPass' unless const_defined?(:HIDDEN_MERCHANT_PROPERTIES)
142-
120+
143121
RUN_ENVIRONMENT = 'RunEnvironment is Mandatory' unless const_defined?(:RUN_ENVIRONMENT)
144-
122+
145123
KEY_DIRECTORY_EMPTY = 'KeysDirectory not provided. Using Default Path:' unless const_defined?(:KEY_DIRECTORY_EMPTY)
146-
124+
147125
FILE_NOT_FOUND = 'File not found, Re-Enter path/file name, Entered path/file name :: ' unless const_defined?(:FILE_NOT_FOUND)
148-
126+
149127
AUTH_ERROR = 'Check Authentication Type (HTTP_Signature/JWT) in cybs.yml.' unless const_defined?(:AUTH_ERROR)
150-
128+
151129
KEY_FILE_NAME_NULL_EMPTY = 'KeyFilename Empty/Null. Assigining merchantID value' unless const_defined?(:KEY_FILE_NAME_NULL_EMPTY)
152-
130+
153131
KEY_ALIAS_NULL_EMPTY = 'KeyAlias Empty/Null. Assigining merchantID value' unless const_defined?(:KEY_ALIAS_NULL_EMPTY)
154-
132+
155133
INCORRECT_KEY_ALIAS = 'The Entered KeyAlias is Incorrect. Assigining merchantID value' unless const_defined?(:INCORRECT_KEY_ALIAS)
134+
135+
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.'
156136
end

0 commit comments

Comments
 (0)