Git Product home page Git Product logo

klarnaofflinesdk's Introduction

Klarna Offline SDK

Library that integrates and utilizes the Klarna offline API

The full API specs are avaliable at apiary -> http://docs.klarnaoffline.apiary.io/

Installing the SDK

Install-Package Mnording.Klarna.Offline

Setting up the cart and config

Firstly you create a config of the current culture, your currency, country, shared secret and store ID.

MerchantConfig config = MerchantConfig(CultureInfo.CurrentCulture, Currency.SEK, Country.SE, "YOURSharedSECRET", "MERCHANT_ID");

To recieve your merchant ID and shared secret for your integration you will need to reach out to Klarna.

You then create a cart, and populate it with items

Cart cart = new Cart();  
cart.addProduct(new CartRow("Prod1234", "New Shoes for you", 1, 10000, 25));  
cart.addProduct(new CartRow("Prod1233", "New purple for you", 1, 10000, 25));

You are also able to define discounts for the cart.

cart.addDiscount(new CartRow("discount-1", "Summer sales", 1, -1000,25));

Note: Prices are entered with amount of cents. Meaning a product that costs 10 SEK, you must enter 1000.

Creating the order

First you send in the cart and config and an optional push url

Use polling method
By only starting the order, you will receive a status url hosted by klarna that will communicate the order details once the customer has completed the purchase.

OfflineOrder offlineOrder = new OfflineOrder(cart, config, "terminal", phone, "Merchant_OrderReference");

Use push url method If you define a status url, then order-data will be pushed to that url when customer has completed the purchase.

OfflineOrder offlineOrder = new OfflineOrder(cart, config, "terminal", phone, "1", new Uri("https://URLThatShouldReceiveOrderInformation.com"));

Create the order
The create call will create the actual KCO session and send out the SMS to the consumer

offlineOrder.Create();

If you did not define your own status URL, Klarna will create one for you that you will use for polling the result of the transaction

Cancel ongoing order

offlineOrder.Cancel();

Note: Order must have been created before you can cancel it.

Reading the customer details

Using polling method:
If you wanted Klarna to create a status url for you, you can use the url that is created on the order, to poll for information.

string url = offlineOrder.GetStatusUrl();

This url will timeout every 60 seconds and you will need to re-trigger it to check as long as the customer has not completed the purchase

OrderDetails details = offlineOrder.pollData(url);

Using status url method
If you defined your own statusurl, Klarna will post data to that url. To read all order-data you can use the JsonConverter.

OrderDetails details =JsonConverter.GetOrderFromString(jsonString);

klarnaofflinesdk's People

Contributors

mnording avatar starkridah avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.