Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

checkout-api

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

checkout-api

A library for the Finnish Checkout online bank payment system integration

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

Checkout API

IMPORTANT NOTICE!

This library uses the legacy api. Documentation for the newer version is available here.

This is a simple library for online payments with the Finnish Checkout online bank payment system

Installing

npm install checkout-api --save

Usage

First you need to require the library and initialize an object with your credentials

var CheckoutApi = require('checkout-api');
// set the merchant authentication and return base url
var checkout = new CheckoutApi({
    merchantId:     '375917',
    merchantSecret: 'SAIPPUAKAUPPIAS',
    baseUrl:        'https://example.com'
  });

I strongly recommend using for example dotenv to load the merchant id and secret. It's a really bad idea to store them in version control.

You can then call the preparePayment(data, options) method to initiate a payment and get payment options

checkout.preparePayment({
  AMOUNT:     100,
  STAMP:      '123',
  REFERENCE:  '456'
}).then(printPaymentButtons);

When the payment has been made the user returns and you can validate the payment with the validateReturnMsg(message) method.

checkout.validateReturnMsg(req.query);

You can poll a payments status by calling pollPayment(data, options). The data parameter must include: STAMP, REFERENCE and AMOUNT and they must be the same as in the payment.

checkout.pollPayment(data, { responseType: 'xml' }).then(resp => { console.log(resp) });

preparePayment

preparePayment(data, options)

Returns: a promise

Data

You can use all options listed in the checkout.fi documentation. AMOUNT, STAMP and REFERENCE are required.

Options

KeyAllowed valuesDefaultDescription
responseTypexml, html, jsonjsonWhat kind of data will the output be
allowSmallPurchasesfalse, truefalseAllow less than 1€ payments

validateReturnMsg

validateReturnMsg(data)

Returns: true / false

data

A javascript object containing the query variables.

pollPayment

pollPayment(data, options)

Returns: a promise

Data

You can use all options listed in the checkout.fi documentation. AMOUNT, STAMP and REFERENCE are required. If you have overriden the defaults while making the preparePayment call, you must make the same overrides here for the checksums to match.

Options

KeyAllowed valuesDefaultDescription
responseTypexml, html, jsonjsonWhat kind of data will the output be

CheckoutApi constructor

new CheckoutApi(options)

KeyDescription
merchantIdYour merchant id
merchantSecretYour merchant secret
baseUrlThe base url of your application
sendRequestYou can use a different method for sending the request than the default Node.js request library. The given function must return a promise. This is usefull for example if you want to use a proxy for static outbound ip or write tests that don't actually send the request.
defaultsYou can define default values for the fields
var checkout = new CheckoutApi({
  merchantId:     process.env.MERCHANT_ID,
  merchantSecret: process.env.MERCHANT_SECRET,
  baseUrl:        process.env.BASE_URL,
  sendRequest:    (url, data) => new Promise(resolve => resolve('Mock response')),
  defaults:       { LANGUAGE: 'EN' }
});

Example

You can take a look at a minimal example in the example folder. It is meant only for displaying the basic functionalities of this library. A real app would not be structured like this.

You can run the example by typing (in the example folder):

npm install
node index.js

and opening http://localhost:3000 in your browser

Running tests

npm run test

FAQs

Package last updated on 20 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts