cybersource-api
Version:
Module for connect with CyberSource by soap methods.
127 lines (113 loc) • 4.31 kB
Markdown
NodeJs module for connect to cybersource using soap, with predefined functions.
- [Features](
- [Install](
- [How it works](
- [Instantiate CybersourceApi](
- [Type of transactions](
- [Authorize and Capture Transaction](
- [Charge card](
* Very simple API
* Using asyncronous functions for requesting
* WS-Security inserted in soap
Install with [npm](http://github.com/isaacs/npm):
```
npm install cybersource-api
```
To start using this module it is only necessary to import and instantiate a CybersourceApi object, for versions check https://ics2wstesta.ic3.com/commerce/1.x/transactionProcessor/.
```javascript
const CybersourceApi = require('cybersource-api');
let password = "<password provided by cybersource>";
let merchantID = "<merchandID provided by cybersource>";
let enviroment = "<enviroment for test or production>"; //use "production" or "development"
let language = "<language for message from api>"; // use "es" or "en"
let version = "<soap url version of cybersource>"; // ej: "1.151". check https://ics2wstesta.ic3.com/commerce/1.x/transactionProcessor/ for versions
let currency = "<currency definition for transactions>";
let cybersourceApi = new CybersourceApi(password,merchantID,enviroment,language,version,currency);
```
For authorize charge use next example, this will return an authorization that will be used later to capture
```javascript
// Create object of type BillTo with required data
let billTo = new cybersourceApi.Models.BillTo("firstName","lastName","address","city","state","postalCode","country","email");
//Create object of type Card with required data
let card = new cybersourceApi.Models.Card("4111111111111111","02","2020","001");
//Create object of type AuthorizationRequest with previus objects created
let authorizationRequest = new cybersourceApi.Models.AuthorizationRequest("referenceCode",billTo,card);
//Call method authorizeCharge parsing the authorizationRequest object and amount to authorize
cybersourceApi.authorizeCharge(authorizationRequest,200).then(res=>{
console.log("Authorization Response: ",res);
/*
res = {
message: 'Success',
code: 100,
authorization: '5543146435356332104008' // <== save this for capture amount after
}
*/
}).catch(e=>{
console.log("Authorization Reqest: ",e);
/*
e = {
message: <message error>,
code: <code error>,
data: <object with more error info>
}
*/
});
```
For capture charge use next example, use authorization obtained in the previous step
```javascript
let authorization = "1232313123123123";// authorization obtained in authorizationRequest
let captureRequest = new cybersourceApi.Models.CaptureRequest("referenceCode",authorization);
cybersourceApi.captureCharge(captureRequest,200).then(resCapture=>
console.log("Capture Request: ",resCapture)
/*
resCapture = {
message: 'Success',
code: 100
}
*/
).catch(e=>{
console.log("Capture Request: ",e);
/*
e = {
message: <message error>,
code: <code error>,
data: <object with more error info>
}
*/
});
```
```javascript
// Create object of type BillTo with required data
let billTo = new cybersourceApi.Models.BillTo("firstName","lastName","address","city","state","postalCode","country","email");
//Create object of type Card with required data
let card = new cybersourceApi.Models.Card("4111111111111111","02","2020","001");
//Create object of type ChargeRequest with previus objects created
let chargeRequest = new cybersourceApi.Models.ChargeRequest("referenceCode",billTo,card);
//Call method chargeCard parsing the chargeRequest object and amount to charge
cybersourceApi.chargeCard(chargeRequest,200).then(res=>{
console.log("Charge Card Response: ",res);
/*
res = {
message: 'Success',
code: 100
}
*/
}).catch(e=>{
console.log("Authorization Reqest: ",e);
/*
e = {
message: <message error>,
code: <code error>,
data: <object with more error info>
}
*/
});
```