The official Node.js client library for the Scanpay API (docs). You can always e-mail us at [email protected], or chat with us on IRC at libera.chat #scanpay
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:
const scanpay = require('scanpay')('API key');
If you do not wish to use npm, you can download the latest release and include in into your project:
const scanpay = require('lib/scanpay.js')('API key');
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
.
Create a link to our hosted payment window (docs | example).
const order = {
items: [{ total: '6000 DKK' }]
};
scanpay.newURL(order, options)
.then(url => console.log(url))
.catch(err => { /* handle errors */ });
Make a sequence request to pull changes from the server (docs | example).
const localSeq = 921;
scanpay.seq(localSeq, options)
.then(obj => console.log(obj.changes))
.catch(err => { /* handle errors */ });
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 {
const json = scanpay.handlePing(body, req.headers['x-signature']);
} catch (e) { /* handle errors */ }
Create a link to our hosted payment window to create a new subscriber (docs | example).
const order = {
subscriber: { ref: '5' }
};
scanpay.newURL(order, options)
.then(url => console.log(url))
.catch(err => { /* handle errors */ });
Charge an amount from an existing subscriber (docs | example):
const subscriberid = 5;
const order = {
items: [{ total: '6000 DKK' }]
};
scanpay.charge(subscriberid, order, options)
.then(res => console.log(res))
.catch(err => { /* handle errors */ });
Renew the payment method for an existing subscriber (docs | example):
const subscriberid = 5;
scanpay.renew(subscriberid, {}, options)
.then(url => console.log(url))
.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.