Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

CrystallizeAPI/node-klarna-deprecated

Repository files navigation

node-klarna

Node Klarna SDK for easy Klarna integration in Node.JS. Generic Klarna Node integration with specific support for the Crystallize headless ecommerce service.

Crystallize enables you to build your next-gen e-commerce business by the help of Fast GraphQL API Service backed by super structured Product Information Management (PIM)

Install

yarn add @crystallize/node-klarna

Usage V3

https://developers.klarna.com/api

const KlarnaV3 = require('@crystallize/node-klarna/v3');

// Initiate the client
const client = new KlarnaV3({
  testDrive: isProd ? false : true,
  username: '...',
  password: '...'
});

// Create order
const { success, order } = await client.createOrder(klarnaCheckoutModel);

// Acknowledge order
const { success } = await client.acknowledgeOrder(order.id);

// Capture order
const { success } = await client.captureOrder(order.id);

// Update order
const { success } = await client.updateOrder(order.id, klarnaCheckoutModel);

// Cancel order
const { success } = await client.cancelOrder(order.id);

// Refund order
const { success } = await client.refundOrder(order.id, amount, description, reference, order_lines);

// Release order authorization
const { success } = await client.releaseAuthorization(order.id);

// Update merchant references
const { success } = await client.updateMerchantReference(order.id, merchant_reference1, merchant_reference2);

Usage V2

https://developers.klarna.com/en/gb/kco-v2

const KlarnaV2 = require('@crystallize/node-klarna/v2');

// For production
const client = new KlarnaV2({
  testDrive: false,
  merchantId: 123456, // Obtain from Klarna merchant site
  sharedSecret: "abcdefgh", // Obtain from Klarna merchant site
  storeName: 'mystore.com' // Obtain from Klarna merchant site
});

// If you don't want to use your own merchant
const client = new KlarnaV2({
  testDrive: true,
  useTestMerchant: true
});

// Create order
const { success, order } = await client.createOrder(klarnaCheckoutModel);

// Confirm order
const { success } = await client.confirmOrder(order.id);

// Capture order
const { success } = await client.captureOrder(order.id);

// Transform a Crystallize basket model (from @crystallize/react-basket) to a Klarna model
const klarnaCart = await client.crystallizeBasketToKlarnaCart(crystallizeBasket.state);

// Trigger a new recurring order
const { success } = await client.createRecurringOrder(options, { recurring_token });

// Get status on a recurring order
const { success } = await client.getRecurringOrderStatus(order.id);