Skip to content

Latest commit

History

47 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Scanpay node.js client

The official Node.js client library for the Scanpay API (docs). You can always e-mail us at help@scanpay.dk, or chat with us on IRC at libera.chat #scanpay

Installation

This package works with Node.js >= 6.6. You can install the package with npm:

npm install scanpay --save

You can then include it in your project with:

constscanpay=require('scanpay')('API key');

Manual installation

If you do not wish to use npm, you can download the latest release and include in into your project:

constscanpay=require('lib/scanpay.js')('API key');

Usage

The API documentation is available here. All methods, except handlePing, will return a Promise. Most methods accept an optional per-request object with options, here referred to as options.

newURL(Object, options) => String

Create a link to our hosted payment window (docs | example).

constorder={items: [{total: '6000 DKK'}]};scanpay.newURL(order,options).then(url=>console.log(url)).catch(err=>{/* handle errors */});

seq(Int, options) => Object

Make a sequence request to pull changes from the server (docs | example).

constlocalSeq=921;scanpay.seq(localSeq,options).then(obj=>console.log(obj.changes)).catch(err=>{/* handle errors */});

handlePing(String, String)

Handle and validate synchronization pings. The method accepts two arguments, the body of the received ping and the X-Signature HTTP header. The method returns an object (docs | example).

try{constjson=scanpay.handlePing(body,req.headers['x-signature']);}catch(e){/* handle errors */}

New subscriber - newURL(Object, options) => String

Create a link to our hosted payment window to create a new subscriber (docs | example).

constorder={subscriber: {ref: '5'}};scanpay.newURL(order,options).then(url=>console.log(url)).catch(err=>{/* handle errors */});

charge(Int, Object, Object) => String

Charge an amount from an existing subscriber (docs | example):

constsubscriberid=5;constorder={items: [{total: '6000 DKK'}]};scanpay.charge(subscriberid,order,options).then(res=>console.log(res)).catch(err=>{/* handle errors */});

renew(Int, Object, Object) => String

Renew the payment method for an existing subscriber (docs | example):

constsubscriberid=5;scanpay.renew(subscriberid,{},options).then(url=>console.log(url)).catch(err=>{/* handle errors */});

Options

All methods, except handlePing, accept an optional per-request options object. You can use it to:

  • Set the API key for this request (example)
  • Set HTTP headers, e.g. the highly recommended X-Cardholder-IP (example)
  • Change the hostname to use our test environment api.test.scanpay.dk (example)

Compatibility table

Nodejs compatibility table for this library.

FeatureVersion
crypto.timingSafeEqual6.6
Arrow functions6.0
Default function parameters6.0
Array.isArray6.0
Buffer.from5.10

License

Everything in this repository is licensed under the MIT license.

About

Scanpay node.js client library

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages