Node.js library for the Swish Handel API (Swedish mobile payment solution)
npm install swish-paymentUses promises for async operations
npm install swish-payment
swish = require('swish-payment')
Library contains only three methods:
- init
- add
- get
See reference below.
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:
cert:
ca:
passphrase:
},
data: {
payeeAlias
currency:
callbackUrl:
}
}
_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'
}
});
Send payment request to Swish.
Takes _data object_ (see below) as argument. Resolves with Swish payment ID if successful.
``DATA OBJECT
{
payeePaymentReference:
payerAlias:
amount:
message:
}
_Example_
``
swish.add({
payeePaymentReference: "snus123",
payerAlias: '0706123456',
amount: "100",
message: "Prima snus"
})
.then(function(id) {
console.log(id); # e.g. "DE6F11C3A0AF4AFC9399C0F0ECC50C5E"
});
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);
});