Skip to content

CrystallizeAPI/node-klarna

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-klarna

Build Status Dependency Status

API Wrapper for Klarna with Crystallize helper functions

Install

$ npm install @crystallize/node-klarna

# Or, if you prefer yarn
$ yarn add @crystallize/node-klarna

Usage

Initialize the Klarna library

const { Klarna, CrystallizeKlarnaHelpers } = require('@crystallize/node-klarna');

const klarna = new Klarna({ username, password, apiEndpoint });
const crystallizeKlarnaHelpers = new CrystallizeKlarnaHelpers({
  host_uri: 'https://localhost:3000',
  purchase_country: 'NO',
  // And other defaults
})

const orderBody = crystallizeKlarnaHelpers.getOrderBody(crystallizeLineItems); // Returns Klarna compatible order body

const order = klarna.checkoutV3.createOrder(orderBody);

The library mimicks the Klarna API path, making module usability more predictable.

Example:

api path: /checkout/v3/orders/:order_id https://developers.klarna.com/api/#checkout-api-retrieve-an-order

is usable like

const order = await klarna.checkoutV3.retrieveOrder(orderId);