0.1.0 • Published 3 years ago

swish-merchant v0.1.0

Weekly downloads
13
License
MIT
Repository
github
Last release
3 years ago

Swish For Merchants

Build Status codecov npm

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).

Before you begin

  • Sign up for a 'Swish for Merchants' account with your bank
  • Get your certificates from the Swish Portal.

Installation

  • Install with npm
npm i swish-merchant

API Documentation

Require The Library

const Swish = require('swish-merchant');

Instantiate the class with your details

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) => {});

Create New Payment Request

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'
}

Retrieve Created Payment Request

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
  }
}

Create New Refund Request

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'
}

Retrieve Created Refund Request

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
  }
}
0.1.0

3 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago