Wondering what’s next for npm?Check out our public roadmap! »

    cybersource-api
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.8 • Public • Published

    Cybersource API :)

    NodeJs module for connect to cybersource using soap, with predefined functions.

    Features

    • Very simple API
    • Using asyncronous functions for requesting
    • WS-Security inserted in soap

    Install

    Install with npm:

      npm install cybersource-api
    

    How it works

    Instantiate CybersourceApi

    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/.

    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);

    Type of transactions

    Authorize and Capture Transaction

    For authorize charge use next example, this will return an authorization that will be used later to capture

    // 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

    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>
        }
        */
      });

    Charge card

    // 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>
      }
      */
    });

    Install

    npm i cybersource-api

    DownloadsWeekly Downloads

    12

    Version

    1.0.8

    License

    ISC

    Unpacked Size

    28.7 kB

    Total Files

    31

    Last publish

    Collaborators

    • avatar
    • avatar