Code Monkey home page Code Monkey logo

klarna-ruby's Introduction

KLARNA

A Ruby wrapper for the Klarna XML-RPC API.

What is Klarna?

Klarna is a payment solution with focus on e-commerce. Visit klarna.com for more information, or why not Wikipedia: Klarna. We might be biased, but at Merchii we currently consider Klarna the most convenient online payment solution that exists – and that’s why we lean on it.

Supported countries:

Sweden (SE), Norway (NO), Denmark (DK), Finland (FI), Germany (DE), Netherlands (NL).

Implementation/Background

This gem was developed as a semi-1:1 implementation of the corresponding API implementations provided by Klarna (with a few simple justifications and heavily refactored methods). Klarnas official implementations were not implemented using OO patterns and as their implementation was changing very often without any notice/versioning I kept it simple as possible.

Since Klarna 2.0 was released they’va refactored their implementations a lot which makes it a good idea to review this implementation as well. Like stated in the TODO I had a clean classy DSL in mind.

This is not a complete implementation, but not far from it and enough for most use cases – a few of the more advanced API methods needs a review/revisit (code disabled now).

Setup

Install the gem:

  $ gem install klarna

…or if you use Bundler:

Gemfile:

  gem 'klarna'

…and $ bundle install.

Usage

Trivial example looking up an address using – in this case – a Swedish SSN:

  require 'rubygems'
  require 'klarna'

  Klarna.configure do |c|
    c.store_id = 123
    c.store_secret = 'secret'

    c.mode = :test
    c.http_logging = false
  end

  client = Klarna::API::Client.new

  client.get_addresses("430415-8399", :SE)

See the code/docs for more information.

Testing

A couple of ways…

Specs

To run unit/integration tests, simply do:

  $ bundle exec rake test

…or if you use Guard:

  $ bundle exec guard

Dummie client

  $ cd examples
  $ ruby console.rb

Web/Sinatra app

1. Start the server…

  $ cd examples
  $ ruby web.rb
  ...
  >> Listening on 0.0.0.0:4567, CTRL+C to stop

2. Open it up!

http://localhost:4567

NOTE: The web app actions/forms are probably completely broken currently as it hasn’t been updated to reflect the current library implementation.

Debugging

HTTP-debugging in Wireshark

Ensure port 4567 (port used for Klarna API integration test/debugging) is in the list of captured ports in the HTTP/HTTPS preferences, or these requests/responses will not be captured. Note: Port 80 (port used for Klarna API integration in production) is captured by default.

XML-RPC-debugging in a XML-RPC client

Try this:

Endpoint: http://beta-test.klarna.com:4567
Method: get_addresses
Params: ["1.0","ruby/xmlrpc","430415-8399",2,"AY2qnVNi8ccTsuDw2XNovQ==",2,2]

References

Tools

  • XML-RPC Client for XML-RPC debugging on OS X.
  • Wireshark for platform-independent protocol sniffing, useful for debugging XML-RPC requests/responses.

Notes

This gem was developed for our own requirements at Merchii, so feel free to send pull-requests with enhancements of any kind (features, bug-fixes, documentation, tests, etc.) to make it better or useful for you as well.

To-do

See the TODO.

License

Released under the MIT license.
Copyright © Jonas Grimfelt, Merchii

klarna-ruby's People

Contributors

grimen avatar pwigle avatar

Stargazers

 avatar

Watchers

 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.