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

swish-payment

v0.0.6

Published

Node.js library for the Swish Handel API (Swedish mobile payment solution)

Downloads

10

Readme

Library for Swish Handel API

Uses promises for async operations

Install

npm install swish-payment

Use

swish = require('swish-payment')

Methods

Library contains only three methods:

  • init
  • add
  • get

See reference below.

init(options)

Initialize Swish module.

Takes options object (see below) as argument. Resolves with options object if successful.

Must be called before adding and getting payments.

Convert provided .p12 to .pem before use (with OPENSSL or equivalent).

# OPTION OBJECT
{
  cert: {
    key: <STRING>         # Path to .pem file containing private key
    cert: <STRING>        # Path to .pem file containing SSL certificate
    ca: <STRING>          # Path to .pem file containing root certificate
    passphrase: <STRING>  # Passphrase for private key
  },
  data: {
    payeeAlias <STRING>   # Merchant Swish number
    currency: <STRING>    # Currency code (default: "SEK")
    callbackUrl: <STRING> # Callback URL for payment request status notification
  }
}

Example

swish.init({
  cert: {
    key: 'res/certs/swish.key',
    cert: 'res/certs/swish.crt',
    ca: 'res/certs/swish.ca',
    passphrase: 'swish'
  },
  data: {
    payeeAlias: '1231181189',
    currency: 'SEK',
    callbackUrl: 'https://www.minsida.se/callback'
  }
});

add(data)

Send payment request to Swish.

Takes data object (see below) as argument. Resolves with Swish payment ID if successful.

# DATA OBJECT
{
  payeePaymentReference: <STRING>   # Merchant payment reference (e.g. order id)
  payerAlias: <STRING>              # Telephone number of customer
  amount: <STRING>                  # Amount in SEK (e.g. "100" or "49.50")
  message: <STRING>                 # Merchant supplied message to customer
}

Example

  swish.add({
    payeePaymentReference: "snus123",
    payerAlias: '0706123456',
    amount: "100",
    message: "Prima snus"
  })
  .then(function(id) {
    console.log(id);      # e.g. "DE6F11C3A0AF4AFC9399C0F0ECC50C5E"
  });

get(id)

Get payment data by ID.

Takes Swish payment ID as argument and resolves with payment data if successful.

Example

swish.get('DE6F11C3A0AF4AFC9399C0F0ECC50C5E')
.then(function(data) {
  console.log(data);
});

# Example response
{ errorCode: null,
  errorMessage: null,
  id: 'DE6F11C3A0AF4AFC9399C0F0ECC50C5E',
  payeePaymentReference: 'snus123',
  paymentReference: '5504E033FA7E4C85B7B2C9C7947D9C5D',
  callbackUrl: 'https://www.test.se/callback',
  payerAlias: '0706123456',
  payeeAlias: '1231181189',
  amount: 100,
  currency: 'SEK',
  message: 'Prima snus',
  status: 'PAID',
  dateCreated: '2016-06-03T13:20:26.093Z',
  datePaid: '2016-06-03T13:20:26.094Z' }