This repository contains working code samples which demonstrate Ruby integration with the CyberSource REST APIs through the CyberSource Ruby SDK.
The samples are all completely independent and self-contained. You can analyze them to get an understanding of how a particular method works, or you can use the snippets as a starting point for your own project. The samples are organized into categories and common usage examples, similar to the CyberSource API Reference.
You can run each sample directly from the command line.
git clone https://github.com/CyberSource/cybersource-rest-samples-ruby
gem install cybersource_rest_client
ruby [DirectoryPath]/[CodeSampleName]
e.g.
ruby Samples/Payments/Payments/simple-authorizationinternet.rb
Configure the following information in the data/Configuration.rb file:
merchantId = 'your_merchant_id'
authenticationType = 'http_signature'
# HTTP Parameters
merchantKeyId = 'your_key_serial_number'
merchantSecretKey = 'your_key_shared_secret'
merchantId = 'your_merchant_id'
authenticationType = 'jwt'
# JWT Parameters
keysDirectory = 'resource'
keyAlias = 'your_merchant_id'
keyPass = 'your_merchant_id'
keyFilename = 'your_merchant_id'
authenticationType = 'http_Signature'
merchantId = 'your_child_merchant_id'
merchantKeyId = 'your_metakey_serial_number'
merchantSecretKey = 'your_metakey_shared_secret'
portfolioId = 'your_portfolio_id'
useMetaKey = true
authenticationType = 'jwt'
merchantId = 'your_child_merchant_id'
keyAlias = 'your_child_merchant_id'
keyPass = 'your_portfolio_id'
keyFilename = 'your_portfolio_id'
keysDirectory = 'resource'
useMetaKey = true
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 sample code is configured to communicate with the sandbox environment. To switch to the production environment, set the appropriate environment constant in data/Configuration.rb file. For example:
# For TESTING use
runEnvironment='apitest.cybersource.com'
# For PRODUCTION use
# runEnvironment='api.cybersource.com'
The run environments that were supported in CyberSource Ruby SDK have been deprecated. Moving forward, the SDKs will only support the direct hostname as the run environment.
For the old run environments previously used, they should be replaced by the following hostnames:
Old Run Environment | New Hostname Value |
---|---|
cybersource.environment.sandbox |
apitest.cybersource.com |
cybersource.environment.production |
api.cybersource.com |
cybersource.in.environment.sandbox |
apitest.cybersource.com |
cybesource.in.environment.production |
api.in.cybersource.com |
For example, replace the following code in the Configuration file:
# For TESTING use
runEnvironment='cybersource.environment.sandbox'
# For PRODUCTION use
# runEnvironment='cybersource.environment.production'
with the following code:
# For TESTING use
runEnvironment='apitest.cybersource.com'
# For PRODUCTION use
# runEnvironment='api.cybersource.com'
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.
Since v0.0.38, a new logging framework has been introduced in the SDK. This new logging framework makes use of Ruby's logger package, and standardizes the logging so that it can be integrated with the logging in the client application.
More information about this new logging framework can be found in this file : Logging.md