A Ruby wrapper for the Klarna XML-RPC API.
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).
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).
Install the gem:
$ gem install klarna
…or if you use Bundler:
Gemfile
:
gem 'klarna'
…and $ bundle install
.
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.
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.
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]
- XML-RPC Client for XML-RPC debugging on OS X.
- Wireshark for platform-independent protocol sniffing, useful for debugging XML-RPC requests/responses.
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.
See the TODO.
Released under the MIT license.
Copyright © Jonas Grimfelt, Merchii