klarna-checkout 0.0.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/klarna/checkout/client.rb +21 -26
- data/lib/klarna/checkout/exceptions.rb +1 -1
- data/lib/klarna/checkout/resource.rb +1 -1
- data/lib/klarna/checkout/version.rb +1 -1
- data/spec/acceptance/update_order_spec.rb +1 -1
- data/spec/fixtures/vcr_cassettes/update_order_spec-2.yml +2 -2
- data/spec/fixtures/vcr_cassettes/update_order_spec.yml +4 -4
- data/spec/lib/klarna/checkout/client_spec.rb +1 -1
- data/spec/lib/klarna/checkout/version_spec.rb +1 -1
- metadata +2 -3
- data/lib/klarna/hash/deep_merge.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9914fd9513d48a6790d8b25e13dd7756f9c93c2b
|
4
|
+
data.tar.gz: eb20429a1354aa9048a5d1679423440e60e4f1d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
10
10
|
User-Agent:
|
11
11
|
- Faraday v0.9.0
|
12
12
|
Authorization:
|
13
|
-
- Klarna
|
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":"
|
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
|
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":"
|
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":"
|
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":"
|
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")
|
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
|
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-
|
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
|