Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
env:
node: true
es6: true
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 2016
sourceType: module
rules:
indent:
- error
- tab
linebreak-style:
- error
- windows
quotes:
- error
- single
semi:
- error
- always
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
8 changes: 4 additions & 4 deletions Data/Configuration.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict'

var CybersourceRestApi = require('CyberSource');
var CybersourceRestApi = require('cybersource-rest-client');
/*
* If Cybs.json file is not provided Merchant configuration properties are taken from Configuration module
*/

//set the constant values
const MerchantId = "testrest";
const MerchantSecretKey = "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE=";
const MerchantKeyId = "08c94330-f618-42a3-b09d-e1e43be5efda";
const AuthenticationType = "http_signature";
const KeysDirectory = "SampleCodeCybsNode\\Resource";
const MerchantSecretKey = "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE=";
const AuthenticationType = "jwt";
const KeysDirectory = "Resource";
const KeyFileName = "testrest";
const RunEnvironment = "cybersource.environment.sandbox";
const KeyAlias = "testrest";
Expand Down
111 changes: 0 additions & 111 deletions Data/RequestData.js

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 CyberSource

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Node.js Sample Code for the Cybersource Rest client API
# Node.js Sample Code for the CyberSource SDK

This repository contains working code samples which demonstrate Node.js integration with the cybersourceRest-rest-client-nodejs and cybersource-rest-auth-nodejs
This repository contains working code samples which demonstrate Node.js integration with the CyberSource REST APIs through the [CyberSource Node.JS SDK](https://github.com/CyberSource/cybersource-rest-client-node).

The samples are organized into categories and common usage examples.

Expand All @@ -14,17 +14,58 @@ You can also run each sample directly from the command line.
## Running the Samples From the Command Line
* Clone this repository:
```
$ git clone https://github.com/khaaldrogo/cybersource-rest-samples-node
$ git clone https://github.com/CyberSource/cybersource-rest-samples-node
```
* Install the cybersource-rest-client-nodejs
* Install the cybersource-rest-client-node and other dependencies, for that go inside cybersource-rest-samples-node run below command
```
$ npm install
```
* Run the individual samples by name. For example:
```
$ node [DirectoryPath]\[CodeSampleName]
$ node [DirectoryPath]/[CodeSampleName]
```
e.g.
```
$ node Samples\Payments\AuthorizePayment\AmericanExpressSafeKey.js
$ node Samples/Payments/CoreServices/ProcessPayment.js
```

#### To set your own sandbox credentials for an API request, configure the following information in Data/Configuration.js file:

* Http

```
const MerchantId = "your_merchant_id";
const MerchantKeyId = "your_key_serial_number";
const MerchantSecretKey = "your_shared_secret";
const AuthenticationType = "http_signature";
const RunEnvironment = "cybersource.environment.sandbox";
```
* Jwt

```
const MerchantId = "your_merchant_id";
const AuthenticationType = "jwt";
const KeysDirectory = "Resource";
const KeyFileName = "your_merchant_id";
const RunEnvironment = "cybersource.environment.sandbox";
const KeyAlias = "your_merchant_id";
const KeyPass = "your_merchant_id";
```

### 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 SDK is
configured to communicate with the sandbox environment. To switch to the production environment, set the appropriate environment
constant. For example:

```javascript
// For TESTING use
const RunEnvironment = "cybersource.environment.sandbox";
// For PRODUCTION use
const RunEnvironment = "cybersource.environment.production";
```


The [API Reference Guide](https://developer.cybersource.com/api/reference/api-reference.html) 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.

6 changes: 3 additions & 3 deletions Resource/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"subMerchant": {
"cardAcceptorID": "1234567890",
"country": "US",
"phoneNumber": "650-432-0000",
"phoneNumber": "4158880000",
"address1": "900 Metro Center",
"postalCode": "94404-2775",
"locality": "Foster City",
"postalCode": "94105",
"locality": "San Francisco",
"name": "Visa Inc",
"administrativeArea": "CA",
"region": "PEN",
Expand Down
29 changes: 19 additions & 10 deletions Samples/Flex/CoreServices/GenerateKey.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
'use strict'

var CybersourceRestApi = require('CyberSource');
var path = require('path');
var filePath = path.resolve('Data/Configuration.js');
var Configuration = require(filePath);
var CybersourceRestApi = require('cybersource-rest-client');

function sampleCode() {
function generateKey(callback) {
try {
var apiClient = new CybersourceRestApi.ApiClient();
var instance = new CybersourceRestApi.KeyGenerationApi(apiClient);
var configObject = new Configuration();
var instance = new CybersourceRestApi.KeyGenerationApi(configObject);

var request = new CybersourceRestApi.GeneratePublicKeyRequest();
request.encryptionType = "RsaOaep256";

instance.generatePublicKey(request, function (error, data, response) {
var options = {
"generatePublicKeyRequest": request
};

console.log("\n*************** Generate Key ********************* ");

instance.generatePublicKey(options, function (error, data, response) {
if (error) {
console.log("Error : " + error);
console.log("Error status code : " + error.statusCode);
Expand All @@ -19,16 +28,16 @@ function sampleCode() {
console.log("Data : " + JSON.stringify(data));
}
console.log("Response : " + JSON.stringify(response));
console.log("Response id : " + response[text.id]);

console.log("Response Code Of GenerateKey : " + response['status']);
callback(error, data);
});
} catch (error) {
console.log(error);
}
};
if (require.main === module) {
sampleCode(function () {
console.log('Method call complete.');
generateKey(function () {
console.log('generateKey end.');
});
}
module.exports.sampleCode = sampleCode;
module.exports.generateKey = generateKey;
Loading