npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

creditguard

v1.1.0

Published

Simple wrapper for Creditguard API

Downloads

9

Readme

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.