This repository contains working code samples which demonstrate python integration with the CyberSource REST APIs through the CyberSource Python 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.
- Python 3.6 or later
- CyberSource Account
- CyberSource API Keys
- Clone this repository:
$ git clone https://github.com/CyberSource/cybersource-rest-samples-python.git
- Install the CyberSource Python SDK:
$ pip install cybersource-rest-client-python
- Install the Sample Codes (required for running Authentication samples only)
$ pip install -e .
- Run the individual samples by name. For example:
$ python [DirectoryPath]\[CodeSampleName]
e.g.
$ python samples\payments\coreservices\process_payment.py
Configure the following information in data/configuration.py file:
- Http Signature
self.authentication_type = "http_signature"
self.merchantid = "Your Merchant ID"
self.merchant_keyid = "your key id"
self.merchant_secretkey = "your secret key"
- Jwt
self.authentication_type = "jwt"
self.merchantid = "Your Merchant ID"
self.key_alias = "your key alias"
self.key_pass = "your key password"
self.key_file_name = "your key filename"
self.keys_directory = os.getcwd()+"\\resources\\"
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 appropriate environment constant in data/Configuration.py file. For example:
For TESTING use
self.run_environment = "CyberSource.Environment.SANDBOX"
#For PRODUCTION use
#self.run_environment = "CyberSource.Environment.PRODUCTION"
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.