Unofficial Ruby Wrapper for Klarnas Checkout Rest API.
Add this line to your application's Gemfile:
gem 'klarna-checkout'
And then execute:
$ bundle
Or install it yourself as:
$ gem install klarna-checkout
require 'klarna/checkout'
# a) Create a client with shared_secret directly
client = Klarna::Checkout::Client.new({
shared_secret: 'your-shared-secret',
environment: :test # or :production
})
# b) Create a client with shared_secret from module configuration
Klarna::Checkout.configure do |config|
config.shared_secret = 'your-shared-secret'
end
client = Klarna::Checkout::Client.new(environment: :test)
client.shared_secret
# => 'your-shared-secret'
# Initialize an order
order = Klarna::Checkout::Order.new({
purchase_country: 'NO',
purchase_currency: 'NOK',
locale: 'nb-no',
cart: {
items: [{
reference: '1123581220325',
name: 'Widget',
quantity: 1,
unit_price: 666,
tax_rate: 2500
}]
},
merchant: {
id: '1337',
terms_uri: 'http://www.example.com/terms',
checkout_uri: 'http://www.example.com/checkout',
confirmation_uri: 'http://www.example.com/confirmation_uri',
push_uri: 'http://www.example.com/push'
}
})
# Create the order with Klarna
client.create_order(order)
order.id
# => ID of the order (no other attributes are updated)
# Read an order from Klarna
order = client.read_order("1234ABCD")
# Configuring some global variables
Klarna::Checkout.configure do |config|
config.shared_secret = 'your-shared-secret'
config.merchant_id = '12345'
config.default_country = 'NO'
config.default_currency = 'NOK'
end
# Instead of repeating yourself with supplying the same attributes for each
# order you can configure some default attributes
Klarna::Checkout::Order.defaults = {
purchase_country: 'NO',
purchase_currency: 'NOK',
locale: 'nb-no',
merchant: {
id: '1337',
terms_uri: 'http://www.example.com/terms',
checkout_uri: 'http://www.example.com/checkout',
confirmation_uri: 'http://www.example.com/confirmation_uri',
push_uri: 'http://www.example.com/push'
}
}
# All newly created orders will then have these attributes
order = Klarna::Checkout::Order.new
order.purchase_country
# => 'NO'
- Validation of objects according to documentation
- Respect readonly attributes
- 2.2
- 2.4
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes, don't forget to add tests (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request