@crystallize/node-klarna
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

node-klarna

API Wrapper for Klarna with Crystallize helper functions

Install

Add wrapper as dependency:

yarn add @crystallize/node-klarna

Or, if you prefer NPM:

npm install @crystallize/node-klarna

Usage

Klarna Library

Initialize the Klarna library:

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

const klarna = new Klarna({
    username: 'username provided by Klarna',
    password: 'password provided by Klarna',
    apiEndpoint: 'api.playground.klarna.com', // Optional, this value by default
    logs: { // Optional, logs disabled by default
        enabled: false,
        useNodeEnv: true, // Use NODE_ENV variable, logs enabled in non 'production' environment
    }
})

Create Klarna order using the library:

const response = await klarna.checkoutV3.createOrder({
    // body structure follows Klarna API spec
})

The library has also built-in TypeScript support:

import {OrderBody, OrderResponse} from '@crystallize/node-klarna'

const body: OrderBody = {
    // ...
}

const response: OrderResponse = await klarna.checkoutV3.createOrder(body)

Crystallize Klarna helpers

Initialize Crystallize helpers:

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

const crystallizeKlarnaHelpers = new CrystallizeKlarnaHelpers({
    host_uri: 'http://localhost:3000',
    purchase_country: 'NO',
    logs: { // Optional, logs disabled by default
        enabled: false,
        useNodeEnv: true, // Use NODE_ENV variable, logs enabled in non 'production' environment
    }
    // And other defaults
})

Generate Klarna order body from Crystallize order items:

const klarnaOrderBody = crystallizeKlarnaHelpers.getOrderBody(crystallizeLineItems);

Dependents (1)

Package Sidebar

Install

npm i @crystallize/node-klarna

Weekly Downloads

19

Version

6.0.0

License

MIT

Unpacked Size

82.5 kB

Total Files

114

Last publish

Collaborators

  • crystallize-admin