Library for using Klarna Checkout with Node.js. Works for merchants in Sweden, Norway, Finland, Austria and Germany.
Uses promises for async operations.
If you find this useful or want to contribute, please send me a line.
npm install klarna-checkout
klarna = require('klarna-checkout')
klarna.init({
eid: <STRING>
secret: <STRING>
live: <BOOLEAN>
})
Pass an object containing
- eid (string)
- Merchant ID supplied by Klarna
- secret (string)
- Shared secret supplied by Klarna
- live (boolean)
true
Live environmentfalse
Test environment (default)
klarna.config({
purchase_country: <STRING>
purchase_currency: <STRING>
locale: <STRING>
layout: <STRING>
terms_uri: <STRING>
cancellation_terms_uri: <STRING>
checkout_uri: <STRING>
confirmation_uri: <STRING>
push_uri: <STRING>
})
Pass an object containing
- purchase_country (string)
- e.g.
'SE'
for Sweden (default)
- e.g.
- purchase_currency (string)
- e.g.
'SEK'
for Swedish Krona (default)
- e.g.
- locale (string)
- e.g.
'sv-se'
for Swedish/Sweden (default)
- e.g.
- layout (string)
'desktop'
(default)'mobile'
- terms_uri (string)
- cancellation_terms_uri (string)
- checkout_uri (string)
- confirmation_uri (string)
- push_uri (string)
See API Docs: resource for more information
klarna.place(cart)
Parameters
- cart (object)
- See API Docs: cart/cart item for instructions on how to format cart properly
Returns promise
- resolved: Klarna order id (string)
- rejected: error (object)
klarna.fetch(id)
Parameters
- id (string): Klarna order id
Returns promise
- resolved: order (object)
- rejected: error (object)
klarna.confirm(id, orderid1, orderid2)
Parameters
- Required
- id (string): Klarna order id
- Optional
- orderid1 (string): Merchant reference #1 (see API docs: merchant reference)
- orderid2 (string): Merchant reference #2 (see API docs: merchant reference)
Returns promise
- resolved: order (object)
- rejected: error (object)
klarna.update(id, data)
Parameters
- id (string)
- data (object)
- See API docs: update for valid keys
Returns promise
- resolved: updated order (object)
- rejected: error (string)
- type (string):
'HTTP'
- HTTP request error (e.g. if network is down)'Klarna'
- HTTP request ok but Klarna responded with an error
- code (string)
- message (sting)
There is an example of a minimal Node.js Express server serving Klarna Checkout in example/
- Recurring orders
- Customization options (colors etc)
Any help is greatly appreciated!
Check out Klarna's API documentation here.