Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Ruby Sample Code for the CyberSource SDK

Travis CI Status

This repository contains working code samples which demonstrate Ruby integration with the CyberSource REST APIs through the CyberSource Ruby SDK.

Using the Sample Code

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.


Running the Samples From the Command Line

  • Clone this repository:
    git clone
  • Install the cybersource-rest-client-ruby (from
    gem install cybersource_rest_client
  • Run the individual samples by name. For example:
    ruby [DirectoryPath]/[CodeSampleName]


    ruby Samples/Payments/Payments/simple-authorizationinternet.rb

Setting your own API credentials for an API request

Configure the following information in the data/Configuration.rb file:

  • Http Signature
    merchantId                  = 'your_merchant_id'
    authenticationType          = 'http_signature'
    # HTTP Parameters
    merchantKeyId               = 'your_key_serial_number'
    merchantSecretKey           = 'your_key_shared_secret'
  • Jwt
    merchantId                  = 'your_merchant_id'
    authenticationType          = 'jwt'
    # JWT Parameters
    keysDirectory               = 'resource'
    keyAlias                    = 'your_merchant_id'
    keyPass                     = 'your_merchant_id'
    keyFilename                 = 'your_merchant_id'
  • MetaKey Http
    authenticationType          = 'http_Signature'
    merchantId                  = 'your_child_merchant_id'
    merchantKeyId               = 'your_metakey_serial_number'
    merchantSecretKey           = 'your_metakey_shared_secret'
    portfolioId                 = 'your_portfolio_id'
    useMetaKey                  = true
  • MetaKey JWT
    authenticationType          = 'jwt'
    merchantId                  = 'your_child_merchant_id'
    keyAlias                    = 'your_child_merchant_id'
    keyPass                     = 'your_portfolio_id'
    keyFilename                 = 'your_portfolio_id'
    keysDirectory               = 'resource'
    useMetaKey                  = true

Switching between the sandbox environment and the production environment

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
   # For PRODUCTION use
   # runEnvironment=''

Run Environments

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

For example, replace the following code in the Configuration file:

   # For TESTING use
   # For PRODUCTION use
   # runEnvironment='cybersource.environment.production'

with the following code:

   # For TESTING use
   # For PRODUCTION use
   # runEnvironment=''

API Reference

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.


Ruby sample code for the CyberSource REST API






No releases published


No packages published