Code Monkey home page Code Monkey logo

klarna-checkout-ruby's Introduction

Build Status Code Climate Test Coverage Gem Version

Klarna Checkout

Unofficial Ruby Wrapper for Klarnas Checkout Rest API.

Installation

Add this line to your application's Gemfile:

gem 'klarna-checkout'

And then execute:

$ bundle

Or install it yourself as:

$ gem install klarna-checkout

Usage

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'

TODO

  • Validation of objects according to documentation
  • Respect readonly attributes

Supported Rubies

  • 2.2
  • 2.4

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes, don't forget to add tests (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

klarna-checkout-ruby's People

Contributors

2rba avatar gudleik avatar ovelar avatar paneq avatar theodorton avatar walm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

klarna-checkout-ruby's Issues

Update reservation status from "checkout_complete" to "created"

I'am looking for a way to update only the status of a reservation:

Klarna gives a Python example:

if order['status'] == 'checkout_complete':
    # At this point make sure the order is created in your system and send a
    # confirmation email to the customer
    update_data = {}
    update_data['status'] = 'created'
    update_data['merchant_reference'] = {
        'orderid1': uuid1()
    }
    order.update(update_data)

Could you give me a hint please?
Your help is greatly appreciated.

Thanx
Jochen

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.