Giter VIP home page Giter VIP logo

node-visa-sdk's Introduction

Visa API SDK

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

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
  1. Crate 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

node-visa-sdk's People

Contributors

chriswoodle avatar

Stargazers

 avatar

Watchers

 avatar

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.