klarna-checkout 0.0.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1b79981f5fb770e090d953d53a6dd120a08494e
4
- data.tar.gz: 2085d55dc1ef5452eba54563ab92a8deac2af02c
3
+ metadata.gz: 9914fd9513d48a6790d8b25e13dd7756f9c93c2b
4
+ data.tar.gz: eb20429a1354aa9048a5d1679423440e60e4f1d6
5
5
  SHA512:
6
- metadata.gz: 852dcf3da70a38b9f2d6c6f169c584ab65a4f5e1f66da2eda6dcbcff230df9c042c1a8495b49abefbff4e04b6ccf0609d5718a99e5298453e0ff38e6ade480c0
7
- data.tar.gz: d1c22b98bf704686e5ced24abee60731a478ede2e7609a04bfeaea6a4389aec2f0a3a033861f0c29f185dabb4b0f07a12e7b57f18dbaf1c999d9764758de1ce9
6
+ metadata.gz: 3accb156ce11c9374f0c165e67655fc6ebbe6b8682b856a334ed21e5d2bc0fcee6f488400835039431720f231295bc04361b336083100aa561dc834933da33ff
7
+ data.tar.gz: cb4b551025ed2fc86f2dbd8b5d8ab283c3dd65a58eb2aee9eb494bac6ba3b108e92c880dec6ea439aeb5c009a2584fe1e0278568a7f1f3ebadeaafde6d49f286
@@ -42,19 +42,7 @@ module Klarna
42
42
  def create_order(order)
43
43
  return false unless order.valid?
44
44
 
45
- request_body = order.to_json
46
- response = https_connection.post do |req|
47
- req.url '/checkout/orders'
48
-
49
- req.headers['Authorization'] = "Klarna #{sign_payload(request_body)}"
50
- req.headers['Accept'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json',
51
- req.headers['Content-Type'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json'
52
- req.headers['Accept-Encoding'] = ''
53
-
54
- req.body = request_body
55
- end
56
- handle_status_code(response.status)
57
-
45
+ response = write_order(order)
58
46
  order.id = response.headers['Location'].split('/').last
59
47
  order
60
48
  end
@@ -75,19 +63,7 @@ module Klarna
75
63
  def update_order(order)
76
64
  return false unless order.valid?
77
65
 
78
- request_body = order.to_json
79
- response = https_connection.post do |req|
80
- req.url "/checkout/orders/#{order.id}"
81
-
82
- req.headers['Authorization'] = "Klarna #{sign_payload(request_body)}"
83
- req.headers['Accept'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json',
84
- req.headers['Content-Type'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json'
85
- req.headers['Accept-Encoding'] = ''
86
-
87
- req.body = request_body
88
- end
89
- handle_status_code(response.status)
90
-
66
+ response = write_order(order)
91
67
  Order.new(JSON.parse(response.body))
92
68
  end
93
69
 
@@ -121,6 +97,25 @@ module Klarna
121
97
 
122
98
  private
123
99
 
100
+ def write_order(order)
101
+ path = "/checkout/orders"
102
+ path += "/#{order.id}" if order.id
103
+
104
+ request_body = order.to_json
105
+ response = https_connection.post do |req|
106
+ req.url path
107
+
108
+ req.headers['Authorization'] = "Klarna #{sign_payload(request_body)}"
109
+ req.headers['Accept'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json',
110
+ req.headers['Content-Type'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json'
111
+ req.headers['Accept-Encoding'] = ''
112
+
113
+ req.body = request_body
114
+ end
115
+ handle_status_code(response.status)
116
+ response
117
+ end
118
+
124
119
  def https_connection
125
120
  @https_connection ||= Faraday.new(url: host)
126
121
  end
@@ -1,4 +1,4 @@
1
- class Klarna::Checkout::Exception < Exception
1
+ class Klarna::Checkout::Exception < StandardError
2
2
  end
3
3
 
4
4
  class Klarna::Checkout::UnauthorizedException < Klarna::Checkout::Exception
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
  require 'active_support/core_ext/hash/slice'
3
+ require 'active_support/core_ext/hash/deep_merge'
3
4
 
4
- require 'klarna/hash/deep_merge'
5
5
  require 'klarna/checkout/concerns/has_one'
6
6
  require 'klarna/checkout/concerns/has_many'
7
7
 
@@ -1,5 +1,5 @@
1
1
  module Klarna
2
2
  module Checkout
3
- VERSION = "0.0.6"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ describe "updating existing order" do
9
9
 
10
10
  let(:client) do
11
11
  Klarna::Checkout::Client.new \
12
- shared_secret: 'dhd1CwWIVrZSp1O'
12
+ shared_secret: 'foobar'
13
13
  end
14
14
 
15
15
  let(:order) { client.read_order('1445FB9ACFD90B11C39E7220000') }
@@ -10,7 +10,7 @@ http_interactions:
10
10
  User-Agent:
11
11
  - Faraday v0.9.0
12
12
  Authorization:
13
- - Klarna QewkVlXa+6xDGNlS6yCgnKFKAZcJ/HAL+ocIwktB2K0=
13
+ - Klarna gone
14
14
  Accept:
15
15
  - application/vnd.klarna.checkout.aggregated-order-v2+json
16
16
  Accept-Encoding:
@@ -41,7 +41,7 @@ http_interactions:
41
41
  <![CDATA[ */(function(w,k,i,d,u,n,c){w[k]=w[k]||function(){(w[k].q=w[k].q||[]).push(arguments)};w[k].config={container:w.document.getElementById(i),ORDER_URL:''https://checkout.testdrive.klarna.com/checkout/orders/1445FB9ACFD90B11C39E7220000'',TESTDRIVE:true,AUTH_HEADER:''KlarnaCheckout
42
42
  aQdfgpMjeNNvH3JorWv3'',LAYOUT:''desktop'',LOCALE:''nb-no'',ORDER_STATUS:''checkout_incomplete'',MERCHANT_TAC_URI:''http://www.example.com/terms'',MERCHANT_TAC_TITLE:''R\u00f8rkj\u00f8p
43
43
  KCO'',MERCHANT_NAME:''R\u00f8rkj\u00f8p KCO'',GUI_OPTIONS:[],ALLOW_SEPARATE_SHIPPING_ADDRESS:false,PURCHASE_COUNTRY:''nor'',PURCHASE_CURRENCY:''nok'',DISALLOW_SKIP_NIN:false,BOOTSTRAP_SRC:u};n=d.createElement(''script'');c=d.getElementById(i);n.async=!0;n.src=u;c.insertBefore(n,c.firstChild);})(this,''_klarnaCheckout'',''klarna-checkout-container'',document,''https://checkout.testdrive.klarna.com/140218-2318fcb/checkout.bootstrap.js'');/*
44
- ]]> */</script><noscript>Please <a href=\"http://enable-javascript.com\">enable\nJavaScript</a>.</noscript></div>"},"options":{"allow_separate_shipping_address":false},"merchant":{"id":"1667","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"}}'
44
+ ]]> */</script><noscript>Please <a href=\"http://enable-javascript.com\">enable\nJavaScript</a>.</noscript></div>"},"options":{"allow_separate_shipping_address":false},"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"}}'
45
45
  http_version:
46
46
  recorded_at: Mon, 24 Feb 2014 10:57:04 GMT
47
47
  recorded_with: VCR 2.8.0
@@ -10,7 +10,7 @@ http_interactions:
10
10
  User-Agent:
11
11
  - Faraday v0.9.0
12
12
  Authorization:
13
- - Klarna QewkVlXa+6xDGNlS6yCgnKFKAZcJ/HAL+ocIwktB2K0=
13
+ - Klarna gone
14
14
  Accept:
15
15
  - application/vnd.klarna.checkout.aggregated-order-v2+json
16
16
  Accept-Encoding:
@@ -41,7 +41,7 @@ http_interactions:
41
41
  <![CDATA[ */(function(w,k,i,d,u,n,c){w[k]=w[k]||function(){(w[k].q=w[k].q||[]).push(arguments)};w[k].config={container:w.document.getElementById(i),ORDER_URL:''https://checkout.testdrive.klarna.com/checkout/orders/1445FB9ACFD90B11C39E7220000'',TESTDRIVE:true,AUTH_HEADER:''KlarnaCheckout
42
42
  aQdfgpMjeNNvH3JorWv3'',LAYOUT:''desktop'',LOCALE:''nb-no'',ORDER_STATUS:''checkout_incomplete'',MERCHANT_TAC_URI:''http://www.example.com/terms'',MERCHANT_TAC_TITLE:''R\u00f8rkj\u00f8p
43
43
  KCO'',MERCHANT_NAME:''R\u00f8rkj\u00f8p KCO'',GUI_OPTIONS:[],ALLOW_SEPARATE_SHIPPING_ADDRESS:false,PURCHASE_COUNTRY:''nor'',PURCHASE_CURRENCY:''nok'',DISALLOW_SKIP_NIN:false,BOOTSTRAP_SRC:u};n=d.createElement(''script'');c=d.getElementById(i);n.async=!0;n.src=u;c.insertBefore(n,c.firstChild);})(this,''_klarnaCheckout'',''klarna-checkout-container'',document,''https://checkout.testdrive.klarna.com/140218-2318fcb/checkout.bootstrap.js'');/*
44
- ]]> */</script><noscript>Please <a href=\"http://enable-javascript.com\">enable\nJavaScript</a>.</noscript></div>"},"options":{"allow_separate_shipping_address":false},"merchant":{"id":"1667","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"}}'
44
+ ]]> */</script><noscript>Please <a href=\"http://enable-javascript.com\">enable\nJavaScript</a>.</noscript></div>"},"options":{"allow_separate_shipping_address":false},"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"}}'
45
45
  http_version:
46
46
  recorded_at: Mon, 24 Feb 2014 10:57:02 GMT
47
47
  - request:
@@ -49,7 +49,7 @@ http_interactions:
49
49
  uri: https://checkout.testdrive.klarna.com/checkout/orders/1445FB9ACFD90B11C39E7220000
50
50
  body:
51
51
  encoding: UTF-8
52
- string: '{"merchant_reference":{"orderid1":"newreference"},"purchase_country":"no","purchase_currency":"nok","locale":"nb-no","cart":{"items":[{"type":"physical","reference":"1123581220325","name":"Widget","quantity":50,"unit_price":666,"discount_rate":0,"tax_rate":2500}]},"merchant":{"id":"1667","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"}}'
52
+ string: '{"merchant_reference":{"orderid1":"newreference"},"purchase_country":"no","purchase_currency":"nok","locale":"nb-no","cart":{"items":[{"type":"physical","reference":"1123581220325","name":"Widget","quantity":50,"unit_price":666,"discount_rate":0,"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"}}'
53
53
  headers:
54
54
  User-Agent:
55
55
  - Faraday v0.9.0
@@ -83,7 +83,7 @@ http_interactions:
83
83
  <![CDATA[ */(function(w,k,i,d,u,n,c){w[k]=w[k]||function(){(w[k].q=w[k].q||[]).push(arguments)};w[k].config={container:w.document.getElementById(i),ORDER_URL:''https://checkout.testdrive.klarna.com/checkout/orders/1445FB9ACFD90B11C39E7220000'',TESTDRIVE:true,AUTH_HEADER:''KlarnaCheckout
84
84
  aQdfgpMjeNNvH3JorWv3'',LAYOUT:''desktop'',LOCALE:''nb-no'',ORDER_STATUS:''checkout_incomplete'',MERCHANT_TAC_URI:''http://www.example.com/terms'',MERCHANT_TAC_TITLE:''R\u00f8rkj\u00f8p
85
85
  KCO'',MERCHANT_NAME:''R\u00f8rkj\u00f8p KCO'',GUI_OPTIONS:[],ALLOW_SEPARATE_SHIPPING_ADDRESS:false,PURCHASE_COUNTRY:''nor'',PURCHASE_CURRENCY:''nok'',DISALLOW_SKIP_NIN:false,BOOTSTRAP_SRC:u};n=d.createElement(''script'');c=d.getElementById(i);n.async=!0;n.src=u;c.insertBefore(n,c.firstChild);})(this,''_klarnaCheckout'',''klarna-checkout-container'',document,''https://checkout.testdrive.klarna.com/140218-2318fcb/checkout.bootstrap.js'');/*
86
- ]]> */</script><noscript>Please <a href=\"http://enable-javascript.com\">enable\nJavaScript</a>.</noscript></div>"},"options":{"allow_separate_shipping_address":false},"merchant":{"id":"1667","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"}}'
86
+ ]]> */</script><noscript>Please <a href=\"http://enable-javascript.com\">enable\nJavaScript</a>.</noscript></div>"},"options":{"allow_separate_shipping_address":false},"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"}}'
87
87
  http_version:
88
88
  recorded_at: Mon, 24 Feb 2014 10:57:03 GMT
89
89
  recorded_with: VCR 2.8.0
@@ -65,7 +65,7 @@ describe Klarna::Checkout::Client do
65
65
  describe "#create_order" do
66
66
  subject { described_class.new({shared_secret: 'foobar'}) }
67
67
 
68
- let(:order) { double('Order', to_json: JSON.generate({ foo: "bar" }), :id= => true, valid?: true) }
68
+ let(:order) { double('Order', to_json: JSON.generate({ foo: "bar" }), id: nil, :id= => true, valid?: true) }
69
69
 
70
70
  before(:each) do
71
71
  stub_request(:post, "https://checkout.testdrive.klarna.com/checkout/orders")
@@ -1,5 +1,5 @@
1
1
  require 'klarna/checkout/version'
2
2
 
3
3
  describe Klarna::Checkout::VERSION do
4
- it { should eq '0.0.6' }
4
+ it { should eq '1.0.0' }
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klarna-checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theodor Tonum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-24 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -175,7 +175,6 @@ files:
175
175
  - lib/klarna/checkout/resource.rb
176
176
  - lib/klarna/checkout/version.rb
177
177
  - lib/klarna/checkout.rb
178
- - lib/klarna/hash/deep_merge.rb
179
178
  - spec/acceptance/create_order_spec.rb
180
179
  - spec/acceptance/read_order_spec.rb
181
180
  - spec/acceptance/update_order_spec.rb
@@ -1,17 +0,0 @@
1
- # Borrowed from activesupport
2
-
3
- unless Hash.respond_to?(:deep_merge)
4
- class Hash
5
- def deep_merge(other_hash)
6
- dup.deep_merge!(other_hash)
7
- end
8
-
9
- def deep_merge!(other_hash)
10
- other_hash.each_pair do |k,v|
11
- tv = self[k]
12
- self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
13
- end
14
- self
15
- end
16
- end
17
- end