Promise-based Node.js library for integrating Swish for Merchants quickly and simply.
- Supports creating payments, getting payment details, creating refunds and retrieving refunds.
- Add your certificate files as files or strings (auto-checking).
- Sign up for a 'Swish for Merchants' account with your bank
- Get your certificates from the Swish Portal.
- Install with npm
npm i swish-merchant
Require The Library
const Swish = require('swish-merchant');
const swish = new Swish({
alias: 'YOUR_SWISH_FOR_MERCHANTS_ALIAS',
paymentRequestCallback: 'YOUR_CALLBACK_URL_FOR_PAYMENT_REQUESTS',
refundRequestCallback: 'YOUR_CALLBACK_URL_FOR_REFUND_REQUESTS',
cert: 'PATH_TO_YOUR_SWISH_CERT_FILE',
key: 'PATH_TO_YOUR_SWISH_KEY_FILE',
test: 'SET_TO_TRUE_TO_USE_SIMULATOR'
}).then((response) => {})
.catch((error) => {});
swish.createPaymentRequest({
phoneNumber: 'USERS_PHONE_NUMER', // Required
amount: 'AMOUNT_TO_REQUEST', // Required
message: 'MESSAGE_TO_USER', // Optional
payeePaymentReference: 'CUSTOM_REFERENCE', // Optional
personNummer: 'USERS_PERSONNUMMER', // Optional
ageLimit: 'AGE_LIMIT_FOR_PURCHASE' // Optional
}).then((response) => {})
.catch((error) => {});
Response contains success flag and payment ID.
{
success: true,
id: 'ID_TO_CREATED_PAYMENT'
}
swish.retrievePaymentRequest({
id: 'PAYMENT_REQUEST_ID', // Required
}).then((response) => {})
.catch((error) => {});
Response contains success flag and payment details.
{
success: true,
data: {
id: 'PAYMENT_ID',
payeePaymentReference: 'CUSTOM_REFERENCE',
paymentReference: 'PAYMENT_REFERENCE',
callbackUrl: 'YOUR_CALLBACK_URL',
payerAlias: 'PAYER_SWISH_ALIAS',
payeeAlias: 'YOUR_SWISH_FOR_MERCHANTS_ALIAS',
amount: 'AMOUNT',
currency: 'SEK',
message: 'CUSTOM_MESSAGE',
status: 'PAID',
dateCreated: 'TIMESTAMP',
datePaid: 'TIMESTAMP',
errorCode: null,
errorMessage: null
}
}
swish.createRefundRequest({
originalPaymentReference: 'PAYMENT_TO_REFUND' // Required
amount: 'AMOUNT_TO_REFUND', // Required
message: 'MESSAGE_TO_USER' // Optional
payerPaymentReference: 'CUSTOM_REFERENCE' // Optional
}).then((response) => {})
.catch((error) => {});
Response contains success flag and refund ID.
{
success: true,
id: 'ID_TO_CREATED_REFUND'
}
swish.retrieveRefundRequest({
id: 'REFUND_REQUEST_ID', // Required
}).then((response) => {})
.catch((error) => {});
Response contains success flag and refund details.
{
success: true,
data: {
id: 'REFUND_ID',
paymentReference: 'PAYMENT_REFERENCE',
payerPaymentReference: 'CUSTOM_PAYMENT_REFERENCE',
originalPaymentReference: 'ORIGINAL_PAYMENT_REFERENCE',
callbackUrl: 'YOUR_CALLBACK_URL',
payerAlias: 'YOUR_SWISH_FOR_MERCHANTS_ALIAS',
payeeAlias: null,
amount: 'AMOUNT',
currency: 'SEK',
message: 'CUSTOM_MESSAGE',
status: 'CREATED',
dateCreated: 'TIMESTAMP',
datePaid: 'TIMESTAMP',
errorCode: null,
errorMessage: null,
additionalInformation: null
}
}