@crystallize/node-klarna
v6.0.0
Published
API Wrapper for Klarna with Crystallize helper functions
Downloads
152
Readme
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);