GithubHelp home page GithubHelp logo

creditguard-node's Introduction

creditguard-node

A simple wrapper for creditguard api

styled with prettier

Usage

Installation

$ npm install creditguard

Setting up

var creditguard = require('creditguard');

var env = {
  user: 'username',
  password: 'password',
  server: 'https://cguat2.creditguard.co.il',
  terminal: '1234567',
  mid: '531', // required only for redirect
  // optional callback addresses when using cg redirect api
  // when left empty, cg will use the predefined terminal value
  success_url: 'localhost/payment/proceed?',
  error_url: 'localhost/payment/rejected?',
  cancel_url: 'localhost/payment/rejected?',
  // optional interface language of MPI hosted payment page
  language: 'heb', // default value is 'eng'
  version: '2000' // terminal version. At the moment CG works with EMV ('2000') and Credit96 ('1001') terminals. Default value is '1001'  
};

var options = {
  cleanup: true // remove empty fields from result, default to false
};

var cg = creditguard(env, options);

Charging

creditguard-node follows cg xml-api (see their docs) parameters names. For example, if their api expects the following xml :

<ashrait>
   <request>
      <command>doDeal</command>
      <requestId/>
      <version>1001</version>
      <language>Eng</language>
      <mayBeDuplicate>0</mayBeDuplicate>
      <doDeal>
         <terminalNumber>0962XXX</terminalNumber>
         <cardNo>458045XXXXXX4580</cardNo>
         <cardExpiration>1212</cardExpiration>
         <creditType>RegularCredit</creditType>
         <currency>USD</currency>
         <transactionCode>Phone</transactionCode>
         <transactionType>Debit</transactionType>
         <total>10010</total>
         <validation>AutoComm</validation>
         <user>567890</user>
      </doDeal>
   </request>
</ashrait>

Then the proper use would be :

// basically create an object with everything you want to put under 'doDeal' element
// (no need to inset terminal number or any other value from 'env')
let charge = {
  cardNo: '458045XXXXXX4580',
  cardExpiration: '1212',
  creditType: 'RegularCredit',
  currency: 'USD',
  transactionCode: 'Phone',
  transactionType: 'Debit',
  total: 10010,
  validation: 'AutoComm',
  user: '567890'
};

try {
  let res = await cg.call(charge);
  // ...
} catch (err) {
  // ...
}

Customer data

If you are using the xml api to get a redirect page and you want to use customerData fields to pass some data into that page, you can do it simply by attaching it to charge object:

charge.customerData = {
  userData1: 'userData1',
  userData3: 'userData3',
  ...
}

Invoices

If your terminal supports invoices you can easily attach invoice to the call, again, by attaching it to the charge object:

// check out cg invoice documentation for complete list of properties
charge.invoice = {
  invoiceCreationMethod: 'wait',
  invoiceSubject: 'Subject',
  invoiceItemQuantity: 1,
  invoiceItemPrice: 10010,
  companyInfo: 'Vandelay Industries',
  mailTo: '[email protected]',
  ...
}

Response

creditguard-node takes cg xml response and converts it to a javascript object so there's no need for you to parse any xml. It also verifies that the transaction result code is 000 (OK) and if not, throws an informative error that you can catch.

TODO

  • Add more tests.
  • Add more apis for common operations like charge, capture and redirect.

creditguard-node's People

Contributors

dearwish avatar dziamid avatar mderazon avatar yankee-by avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

creditguard-node's Issues

add support for angular

This is a great tool! thank you very much! any change we can add type definition for ts support? I can offer small payment via fiverr? I need this ASAP.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.