visa-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Visa API SDK

This is an unnofficial Typescript NodeJS sdk for VISA API's. Initially created at SmallBusinessWeek Hackathon 2019.

NPM

Note: This SDK is only implemented for a subset of all the Visa REST API's. PR's welcome!

Currently this SDK contains type definitons for the following API's:

Complete:

  • Data and Analytics
    • Merchant Search

Partial:

  • Commercial
    • Visa B2B Connect
    • Visa B2B Virtual Account Payment Method
  • Visa DPS
    • Visa DPS Card and Account Services

Other API's may be typed as any;

Setup

yarn add visa-sdk
# or 
npm install visa-sdk

Authentication

Visa API's use Two way SSL and credentials to authenticate to their api.

To authenticate NodeJS to the Visa, you will need the following information:

  • VISA_USER_ID - a project User ID
  • VISA_PASSWORD - a project Password
  • CERTIFICATE_PASSPHRASE - your passphrase set when creating the .p12 bundle
  • CERTIFICATE_FILE - the path to the .p12 bundle file

Visa has documentation on how to generate your .p12 bundle from a CSR file (Visa can generate a CSR if you do not have one).

  1. Create a Project. While creating the project you will generate or upload a CSR file.
  2. Download the Certificate private key (cert.pem) from the the project Credentials page.
  3. Use the OpenSSL cli to bundle both the CSR and private key. You will encrypt the bundle by entering a passphrase. This passphrase is CERTIFICATE_PASSPHRASE.
openssl pkcs12 -export -in cert.pem -inkey "privateKey.pem" -certfile cert.pem -out myProject_keyAndCertBundle.p12

In the above example, the path to myProject_keyAndCertBundle.p12 is CERTIFICATE_FILE

  1. After creating the project, the web interface will present you with both the generated User ID and password.

Usage

Hello World

import { Visa } from 'visa-sdk';
 
const credentials = {
    userId: process.env.VISA_USER_ID,
    password: process.env.VISA_PASSWORD,
    certificate_passphrase: process.env.CERTIFICATE_PASSPHRASE,
    certificate_file_path: process.env.CERTIFICATE_FILE
};
 
const visa = new Visa(credentials);
visa.helloWorld().then(({ body, response }) => {
    console.log(response.statusCode);
    console.log(body);
});

Merchant Search

import { MerchantSearch } from 'visa-sdk';
 
const credentials = {
    userId: process.env.VISA_USER_ID,
    password: process.env.VISA_PASSWORD,
    certificate_passphrase: process.env.CERTIFICATE_PASSPHRASE,
    certificate_file_path: process.env.CERTIFICATE_FILE
};
 
const query: MerchantSearch.Query = {
    searchAttrList: {
        merchantName: "STARBUCKS",
        merchantCity: "SAN FRANCISCO",
        merchantState: "CA",
        merchantPostalCode: 94127,
        merchantCountryCode: 840
    },
    responseAttrList: [
        "GNSTANDARD"
    ],
    searchOptions: {
        wildCard: [
            "merchantName"
        ],
        maxRecords: 5,
        matchIndicators: true,
        matchScore: true,
        proximity: [
            "merchantName"
        ]
    },
    header: {
        requestMessageId: "Request_001",
        startIndex: 0,
        messageDateTime: "2019-05-04T20:17:52.903"
    }
};
merchantSearch.search(query).then(({ body, response }) => {
    console.log(response.statusCode)
    console.log(body.merchantSearchServiceResponse.response)
});

Development

Setup:

yarn
# --or-- 
npm install

Build:

# Transpile typescript 
yarn build
# Transpile on file changes 
yarn watch
 
# --or-- 
 
# Transpile typescript 
npm run build
# Transpile on file changes 
npm run watch

Package Sidebar

Install

npm i visa-sdk

Weekly Downloads

2

Version

0.0.4

License

MIT

Unpacked Size

81.4 kB

Total Files

29

Last publish

Collaborators

  • chriswoodle