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

opayo

v1.0.1

Published

A Node.JS module using the Sage Pay REST API that is based on REST principles.

Downloads

352

Readme

OPayo

A Node.js Client for interracting with the OPayo(SagePay) API

NPM version Build Status

Documentation

See SagePay API Reference

Installation

Install the package with

npm install @mhayk/sagepay --save

or

yarn add @mhayk/sagepay

Usage

Create a Client instance and provide the access_token and environment you want to use.

const sagepay = require("@mhayk/sagepay");
const Client = sagepay.Client;

// Gets Access Token stored in environment variable
const VENDOR_NAME = process.env.VENDOR_NAME
const SANDBOX_INTEGRATION_KEY = process.env.SANDBOX_INTEGRATION_KEY
const SANDBOX_INTEGRATION_PASSWORD = process.env.SANDBOX_INTEGRATION_PASSWORD

const client = new Client({
      vendor_name: VENDOR_NAME,
      integration_key: SANDBOX_INTEGRATION_KEY,
      integration_password: SANDBOX_INTEGRATION_PASSWORD,
      environment: "sandbox",
      card: "007",
    });

console.log(client)

const merchant = await client.merchant_session_keys.create(
  { vendorName: VENDOR_NAME }
  );
const { expiry, merchantSessionKey } = merchant
console.log(`Expiry: ${expiry}, Merchant Session Key: ${merchantSessionKey}`)

client.merchantSessionKey = merchantSessionKey;

const card = {
  cardDetails: {
  cardholderName: 'TEST',
  cardNumber: '4929000005559',
  expiryDate: '0821',
  securityCode: '123'
  }
}
const newCardIdentifier = await client.card_identifiers.create(card)
const { cardIdentifier } = newCardIdentifier
console.log(`Card Identifier: ${cardIdentifier}`)

const payment = {
  transactionType: 'Payment',
  paymentMethod: {
    card: {
      merchantSessionKey,
      cardIdentifier,
    }
  },
  vendorTxCode: '0102030405-faraan',
  amount: 100,
  currency: 'GBP',
  description: 'MHAYK TEST LIBRARY',
  customerFirstName: 'MHAYK WHANDSON',
  customerLastName: 'DA SILVA LIMA',
  billingAddress: {
    address1: "11, Worton Road",
    city: 'London',
    postalCode: "TW7 6HJ",
    country: "GB"
  }
}
const transaction = await client.transactions.create(payment)
console.log(transaction)

Usage with Typescript

import { Client } from "@mhayk/sagepay";

// Gets Access Token stored in environment variable
const VENDOR_NAME = process.env.VENDOR_NAME
const SANDBOX_INTEGRATION_KEY = process.env.SANDBOX_INTEGRATION_KEY
const SANDBOX_INTEGRATION_PASSWORD = process.env.SANDBOX_INTEGRATION_PASSWORD

const client = new Client({
      vendor_name: VENDOR_NAME,
      integration_key: SANDBOX_INTEGRATION_KEY,
      integration_password: SANDBOX_INTEGRATION_PASSWORD,
      environment: "sandbox",
      card: "007",
    });

console.log(client)

const merchant = await client.merchant_session_keys.create(
  { vendorName: VENDOR_NAME }
  );
const { expiry, merchantSessionKey } = merchant
console.log(`Expiry: ${expiry}, Merchant Session Key: ${merchantSessionKey}`)

client.merchantSessionKey = merchantSessionKey;

const card = {
  cardDetails: {
  cardholderName: 'TEST',
  cardNumber: '4929000005559',
  expiryDate: '0821',
  securityCode: '123'
  }
}
const newCardIdentifier = await client.card_identifiers.create(card)
const { cardIdentifier } = newCardIdentifier
console.log(`Card Identifier: ${cardIdentifier}`)

const payment = {
  transactionType: 'Payment',
  paymentMethod: {
    card: {
      merchantSessionKey,
      cardIdentifier,
    }
  },
  vendorTxCode: '0102030405-faraan',
  amount: 100,
  currency: 'GBP',
  description: 'MHAYK TEST LIBRARY',
  customerFirstName: 'MHAYK WHANDSON',
  customerLastName: 'DA SILVA LIMA',
  billingAddress: {
    address1: "11, Worton Road",
    city: 'London',
    postalCode: "TW7 6HJ",
    country: "GB"
  }
}
const transaction = await client.transactions.create(payment)
console.log(transaction)

Events

The SagePay Client instance emits request and response events

const sagepay = require("@mhayk/sagepay");
const Client = sagepay.Client;

const VENDOR_NAME = process.env.VENDOR_NAME
const SANDBOX_INTEGRATION_KEY = process.env.SANDBOX_INTEGRATION_KEY
const SANDBOX_INTEGRATION_PASSWORD = process.env.SANDBOX_INTEGRATION_PASSWORD

// Gets Access Token stored in environment variable
const access_token = process.env.ACCESS_TOKEN;
const environment = "sandbox";

const client = new Client({
    vendor_name: VENDOR_NAME,
    integration_key: SANDBOX_INTEGRATION_KEY,
    integration_password: SANDBOX_INTEGRATION_PASSWORD,
    environment: "sandbox",
    card: "007",
  });

// Add the request event handler function:
client.on("request", request => {
  // Carry out some actions
});

// Add the request event handler function:
client.on("response", response => {
  // Carry out some actions
});

Avaliable resources

  • Merchant Session Keys
  • Card Identifiers
  • Transactions

Development

Running tests

$ npm install
$ npm test

or

$ yarn
$ yarn test

To use your Sandbox Access Token to run the tests, you need to set the file .env with the following variables:

VENDOR_NAME=
SANDBOX_INTEGRATION_KEY=
SANDBOX_INTEGRATION_PASSWORD=