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

wk-nmi

v0.0.21

Published

This is a simple utility package

Downloads

11

Readme

NMI Gateway

This is the wklive implementation of nmi gateway, the original documentation of nmi is: https://secure.networkmerchants.com/gw/merchants/resources/integration/integration_portal.php#cv_variables

This package was build with the unique intention to make the integration with the gateway easy.

You can generate tokens using: https://nmi-dashboard.vercel.app/nmi?/generateToken

Getting started

First you need to configure GOOGLE_APPLICATION_CREDENTIALS env variable to point to your google key credentials.

GOOGLE_APPLICATION_CREDENTIALS = "path/to/you/service/account/credentials.json"

Also you need

WK_NMI_SERVER = "nmi server url"
NMI_ORGANIZATION = " nmi organization"

NextJS configuration example

You can get the project here: https://github.com/gtavo95/wk-nmi-front-example.git


// page.tsx

// import google authorization libraries
import { GoogleAuth } from "google-auth-library";

// import wk-nmi library to interact with nmi server
import { Plans } from "wk-nmi";

// server fetch function
async function getPlans() {
  // Init google auth libraries
  const auth = new GoogleAuth();

  // Workinglive nmi server url
  const url = process.env.WK_NMI_SERVER;

  // Nmi organization
  const organization = process.env.NMI_ORGANIZATION;

  if (url && organization) {
    console.info(
      `request ${url} with target audience ${url}`
    );

    // Get an auth client
    const client = await auth.getIdTokenClient(url);

    // Get the tokenID token
    const tokenId = await client.idTokenProvider.fetchIdToken(url);

    // Now use the wk-nmi library to get all plans as below
    const plan = new Plans(url, "testOrg4", tokenId);
    const plans = await plan.all();

    if (plans.status === 200) return plans.response;
    else return [];
  }
}

export default async function Page() {
  // Get plans
  const plans = await getPlans();

  // Render plans as you wish
  return (
    <div className="flex flex-col h-screen w-screen bg-white overflow-auto gap-3">
      {/* titulo */}
      <h1 className="text-black text-2xl">Plans</h1>
      {/* plans */}
      <div className="flex flex-row flex-wrap gap-1">
        {plans &&
          plans.map((plan: any) => (
            <div
              key={plan.plan_id}
              className="flex flex-col rounded-lg border border-gray-400 text-black p-3"
            >
              <h1>Name: {plan.plan_name}</h1>
              <p>payments: {plan.plan_payments}</p>
              <p>Amounts: {plan.plan_amount}</p>
            </div>
          ))}
      </div>
    </div>
  );
}

Doc

The library supports the next operations:

Billing

Add

The add method creates a new billing to the selected user_id

// Import library
import { Billing } from "wk-nmi";

// Init Billing
const billing = new Billing(
  "https://nmi-server-orkrbzqvda-uc.a.run.app",
  "testOrg4",
);

// use add method
const res = await billing.add({
  userId: "1",
  billingId: "16",
  token: "00000000-000000-000000-000000000000", //  collect-js-token
  billingInfo: {
    //  all fields are optional
    firstName: "test",
    lastName: "test",
    address1: "test",
    city: "test",
    state: "test",
    zip: "test",
    country: "test",
    phone: "test",
    email: "test",
    company: "test",
    address2: "test",
    fax: "test",
    shippingId: "test",
    shippingAddress1: "test",
    shippingAddress2: "test",
    shippingCity: "test",
    shippingCountry: "test",
    shippingZip: "test",
    shippingState: "test",
    shippingFirst_name: "test",
    shippingLast_name: "test",
    shippingPhone: "test",
    shippingEmail: "test",
  },
});

updateBillingInfo

The updateBillingInfo method only updates only billing information, it can't edit billing_id, user_id.

const res = await billing.updateBillingInfo({
  userId: "1",
  billingId: "16",
  token: "00000000-000000-000000-000000000000", //  collect-js-token
  billingInfo: {
    //  all fields are optional
    firstName: "test",
    lastName: "test",
    address1: "test",
    city: "test",
    state: "test",
    zip: "test",
    country: "test",
    phone: "test",
    email: "test",
    company: "test",
    address2: "test",
    fax: "test",
    shippingId: "test",
    shippingAddress1: "test",
    shippingAddress2: "test",
    shippingCity: "test",
    shippingCountry: "test",
    shippingZip: "test",
    shippingState: "test",
    shippingFirst_name: "test",
    shippingLast_name: "test",
    shippingPhone: "test",
    shippingEmail: "test",
  },
});

delete

Deletes selected billing_id

const userId = "";
const billingId = "";
const res = await billing.delete(userId, billingId);

priority

Changes the billing priority of a billing id.

const res = await billing.changePriority({
  userId: "1",
  billingId: "16",
  priority: 1,
});

info

get billing information of userId

const userId = "";
const res = await billing.info(userId);

Customer Vault

Handle customer vault operations

add

Create a new customer vault with the provided id (this id is then used by other methods of this library as user_id)

// import library
import { CustomerVault } from "wk-nmi";

const host = "";
const org = "";
// init CustomerVault
customerVault = new CustomerVault(host, org);
// add user
const res = await customerVault.add({
  id: "testId113233",
  token: "00000000-000000-000000-000000000000",
  billingId: "",
  billingInfo: {
    firstName: "",
    lastName: "",
    address1: "",
    city: "",
    state: "",
    zip: "",
    country: "",
    phone: "",
    email: "",
  },
});

Plans

Handles plan operations with the nmi api

all

Get all plans created plans in the organization

// import
import { Plans } from "wk-nmi";

const host = "https://nmi-server-orkrbzqvda-uc.a.run.app";
const org = "testOrg4";
// init CustomerVault
plan = new Plans(host, org);

// get plans
const res = await plan.all();

id

Get plan id information

// Get swzshoppingonly plan information
const planId = "";
const res = await plan.id(planId);

addMonthConfiguration

Create a new plan using month setup

# create plan
const res = await plan.withMonthConfig({
    customPlan: {
        planAmount: "10.00",
        planName: "test",
        planId: "testtset",
        monthFrequency: "1",
        dayOfMonth: "1",
        planPayments: "0"
    }
})

edit_month_configuation

Edit plan using month configuration

// edit month configuration plan
const res = await plan.editMonthConfig({
  customPlan: {
    planAmount: "10.00",
    planName: "test",
    planId: "testtset",
    monthFrequency: "1",
    dayOfMonth: "1",
    planPayments: "0",
  },
});

addDayConfiguration

Create a new plan using day setup

// create a plan using day configuration
plan.withDayConfig({
  customPlan: {
    planAmount: "10.00",
    planName: "test",
    planId: "testtsetts",
    dayFrequency: "1",
    planPayments: "0",
  },
});

editDayConfiguration

Edit a plan using day setup

// edit a plan using day configuration
plan.editDayConfig({
  customPlan: {
    planAmount: "10.00",
    planName: "test",
    planId: "testtsetts",
    dayFrequency: "1",
    planPayments: "0",
  },
});

Subscription

Handles subscriptions using the nmi api

withMonthConfig

Assign a subscriptions to the user_id (customer vault). if total_amount is set to 0, the method will behave as a normal subscription and the user will be charged according to the custom_subscription info object. But if total_amount is set to a value greater that 0 the user will be charged by that amount

// import library
import { Subs } from "wk-nmi";

// init
const subsObj = new Subs(
  "https://nmi-server-orkrbzqvda-uc.a.run.app",
  "testOrg4",
);

// assign subscription to custumer vault
const res = await subsObj.withMonthConfig({
  userId: "1",
  orderId: "test",
  totalAmount: "0", // 0 for subscription without an addition sale amount
  customSubscriptionInfo: {
    planId: "test",
    planAmount: "10.00",
    planName: "test",
    monthFrequency: "1",
    dayOfMonth: "1",
    planPayments: "0",
  },
});

// The output can be of type BadResponse | ErrorDetail | SubscriptionResult

if (
  "successfull" in subResponse &&
  subResponse.successfull &&
  "nm_response" in subResponse
) {
  let nmiRespones = subResponse.nm_response.
} else {
  // error handling
}

withDayConfig

Assign a subscriptions to the user_id (customer vault). if total_amount is set to 0, the method will behave as a normal subscription and the user will be charged according to the custom_subscription info object. But if total_amount is set to a value greater that 0 the user will be charged by that amount

// Assign subscription to custumer vault
const res = await subsObj.withDayConfig({
  userId: "1",
  orderId: "testRef",
  totalAmount: "0", //0 for subscription without an addition sale amount
  customSubscriptionInfo: {
    planPayments: "15",
    planAmount: "6",
    dayFrequency: "1",
  },
});

// The output can be of type BadResponse | ErrorDetail | SubscriptionResult

if (
  "successfull" in subResponse &&
  subResponse.successfull &&
  "nm_response" in subResponse
) {
  let nmiRespones = subResponse.nm_response.
} else {
  // error handling
}

Pause/Resume

Pause subscription

// pause subscription
const subscriptionId = "your subscription id";
const pause = true; // true to pause/false to resume
const res = await subsObj.pause(subscriptionId, pause);

Cancel

Cancel a subscripion

const subscriptionId = "your subscription id";
const result = await subsObj.cancel(subscriptionId);

by_user_id

Get all subscriptions of user_id

// Get subscriptions of user id
const userId = "your user id";
const result = await subsObj.all(userId);

update

Update payment method, using a new customer vault id,

// Update subscriptions 
const subId = ""
const customerId = ""
const org = ""
const url = ""
const apikey = ""
const subs = new Subs(url, org, apikey);
const res = await subs.update_month_subscription(subId, customerId, {
    planPayments: "1",
    planAmount: "14",
    monthFrequency: "1",
    dayOfMonth: "1",
    startDate: ""
});

Config

Handles creations of the merchants

get

Get merchant information

// import library
import { Config } from "wk-nmi

// init
const configObj = new Config("http://127.0.0.1:8000","testOrg4")

// get merchant configuration
const res = await configObj.get()

update

Update merchant information

// edit merchant information
const res = await configObj.update({
  storeId: 2342311,
  environmentActive: "sandbox",
  productionEnv: {
    token: "",
  },
  sandboxEnv: {
    token: "",
  },
  secretToken: "",
  merchantOrchestrator_url: "http://",
  merchantId: "123",
  merchantSignature: "123",
});

add

Create a new merchant

//  add a new merchant
const res = await configObj.add({
  storeId: 2342311,
  environmentActive: "sandbox",
  productionEnv: {
    token: "",
  },
  sandboxEnv: {
    token: "",
  },
  secretToken: "",
  merchantOrchestrator_url: "http://",
  merchantId: "123",
  merchantSignature: "123",
});

delete

Delete a current merchant,

// warning
const res = await configObj.delete();

Payment

Handles payments

withCustomerVault

Handles customer vaults requests

import { Pay } from "../lib/payments";

const pay = new Pay("http://127.0.0.1:8000", "testOrg4", "secretToken");

const paymentResult = await pay.withCustomerVault({
  total: "6",
  customerVault: "2",
  billingInfo: {
    firstName: "testFirstName",
    lastName: "testLastName",
    address1: "testAddress1",
    city: "testCity",
    state: "testState",
    zip: "testZip",
    country: "testCountry",
    phone: "testPhone",
    email: "testEmail",
  },
});

// The output can be of type BadResponse | ErrorDetail | NMIResponse

if (
  "successfull" in subResponse &&
  subResponse.successfull &&
  "nm_response" in subResponse
) {
  // successfull
  let nmiRespones = subResponse.nm_response.
} else {
  // error handling
}

withToken

Handles simple payment requests

const pay = new Pay("http://127.0.0.1:8000", "testOrg4", "secretToken");

const paymentResult = await pay.withToken({
  total: "6",
  customerVault: "2",
  billingInfo: {
    firstName: "testFirstName",
    lastName: "testLastName",
    address1: "testAddress1",
    city: "testCity",
    state: "testState",
    zip: "testZip",
    country: "testCountry",
    phone: "testPhone",
    email: "testEmail",
  },
});

// The output can be of type BadResponse | ErrorDetail | NMIResponse

if (
  "successfull" in subResponse &&
  subResponse.successfull &&
  "nm_response" in subResponse
) {
  // successfull
  let nmiRespones = subResponse.nm_response.
} else {
  // error handling
}