Coder Social home page Coder Social logo

swish-payments's Introduction

Swish Payments Library

The Swish Payments library provides convenient access to Swish API from server-side applications.

Documentation

Installation

Install the package with:

npm install swish-payments --save

Usage

import Swish from "swish-payments"

// The package needs to be configured with your Swish certificate and passphrase.
const swish = new Swish({
  endpoint: "https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1",
  serverIP: "213.132.115.94:443",
  cert: {
    pfx: fs.readFileSync(__dirname + "/ssl/1231181189.p12"),
    passphrase: "swish"
  }
})

// Setup payment request webook
app.post("/paymentrequests", swish.createHook(async payment => {
  console.log("incoming payment: ", payment)

  // Refund payment
  const refund = await swish.refundRequest({
    originalPaymentReference: payment.id,
    callbackUrl: "https://example.com/refunds/" // should be absolute url of webhook above
  })

}))

// Setup refund request webook
app.post("/refunds", swish.createHook(refund =>
  console.log("incoming refund: ", refund)
))

const token = await swish.paymentRequest({
  callbackUrl: "https://example.com/paymentrequests/", // should be absolute url of webhook above
  payerAlias: "46700123456",
  payeeAlias: "1231181189",
  amount: "100.00",
  message: "message",
})
// 900D843722644C149995AC246E14D8C6

const payment = await swish.getPayment(token)
/*
{ errorCode: null,
  errorMessage: null,
  id: 'D59CD1A48F764B88BE852F4B8ED944B3',
  payeePaymentReference: null,
  paymentReference: null,
  callbackUrl: 'https://example.com/hooks/payments/',
  payerAlias: '46700123456',
  payeeAlias: '1231181189',
  amount: 100,
  currency: 'SEK',
  message: 'message',
  status: 'CREATED',
  dateCreated: '2018-02-09T16:49:40.201Z',
  datePaid: null }
*/

swish-payments's People

Contributors

carlbarrdahl avatar

Watchers

 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.