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

visa-sdk

v0.0.4

Published

Visa API SDK

Downloads

11

Readme

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