Node.js client library for the Scanpay API. You can always e-mail us at help@scanpay.dk or chat with us on irc.scanpay.dk:6697
or #scanpay
at Freenode (webchat)
This package works with Node.js >= 6.6. Install the package with npm:
npm install scanpay --save
and include it in your project.
const scanpay = require('scanpay')('API key');
Download the latest release and include in into your project:
const scanpay = require('lib/scanpay.js')('API key');
All methods, except handlePing
, will return a Promise
. Note that some methods accept an optional per-request options
object.
Create a payment link by passing the order details through newURL
. Strictly speaking, only the following data is required, but we strongly encourage you to use the entire spec (example).
const order = {
items: [{ total: '6000 DKK' }]
};
scanpay.newURL(order, options)
.then(url => console.log(url))
.catch(err => { /* handle errors */ });
Securely and efficiently validate pings. This method accepts two arguments from the received ping request, the HTTP message body and the X-Signature
HTTP header. The return value is a JSON object (example).
try {
const json = scanpay.handlePing(body, req.headers['x-signature']);
} catch (e) { /* handle errors */ }
Make a sequence request to get an object with a number of changes since the supplied sequence number (example).
const localSeq = 921;
scanpay.seq(localSeq, options)
.then(obj => console.log(obj.changes))
.catch(err => { /* handle errors */ });
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)
Nodejs compatibility table for this library.
Feature | Version |
---|---|
crypto.timingSafeEqual | 6.6 |
Arrow functions | 6.0 |
Default function parameters | 6.0 |
Array.isArray | 6.0 |
Buffer.from | 5.10 |
Everything in this repository is licensed under the MIT license.