GithubHelp home page GithubHelp logo

nocodehummel / swish-merchant Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stebunting/swish-merchant

0.0 1.0 0.0 425 KB

Swish for Merchants Node.js Integration Library

License: MIT License

JavaScript 100.00%

swish-merchant's Introduction

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

swish-merchant's People

Contributors

stebunting avatar

Watchers

Hummel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.