klarna-checkout 1.1.3 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85f81bcdfc8b0b29935fa8a8c78588e1b6c6da64
4
- data.tar.gz: 7c17e895833e3549824685a7a95ab7ae14216619
3
+ metadata.gz: 45b32a14358c5b7931fe51f5bda20c6dc4f1c173
4
+ data.tar.gz: 85feab9c0a60546ad05bb7e737669e3cdf942621
5
5
  SHA512:
6
- metadata.gz: 066f19e7711dda039ae7999b0332e5a59cad1b42d3eb39fd70c90a75b55fafa3e9f2a41dc4e9d6250fdf5cb29308ef88d8c9fb540f97abcd670481ae0d2750aa
7
- data.tar.gz: 355445fd9799f09b86952da608b25c665b8d9d71109d617f4227989d6d7713ae87181d414da54470fa4a5d2118b21c3aada92833ad4b19d0731a3bbe3d4f4bd7
6
+ metadata.gz: c1539b4598e7b985da068f1bd375edd790cbb8f925bcf32185a410606e798e622adc03ab6d08e6bd08ada0e393b87a175af2956856d836b220f67d61b5701338
7
+ data.tar.gz: 41b0af2ec437fb7ee99872ea64f4ce8c44d686c6bab75c4ce2a5c5def6f6f9e4f4fc8e536f6fe32916f2a3daa1493fa72083fbeb6a92f09222c02621724f4bf9
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Theodor Tonum
1
+ Copyright (c) 2014 Skalar AS
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- [ ![Codeship Status for Skalar/klarna-checkout-ruby](https://www.codeship.io/projects/c01f6250-8b2d-0131-29ef-223e3dbeac7e/status?branch=master)](https://www.codeship.io/projects/15721) [![Code Climate](https://codeclimate.com/github/Skalar/klarna-checkout-ruby.png)](https://codeclimate.com/github/Skalar/klarna-checkout-ruby) [![Gem Version](https://badge.fury.io/rb/klarna-checkout.png)](http://badge.fury.io/rb/klarna-checkout)
1
+ [![Build Status](https://travis-ci.org/rorkjop/klarna-checkout-ruby.svg?branch=master)](https://travis-ci.org/rorkjop/klarna-checkout-ruby)
2
+ [![Code Climate](https://codeclimate.com/github/rorkjop/klarna-checkout-ruby/badges/gpa.svg)](https://codeclimate.com/github/rorkjop/klarna-checkout-ruby)
3
+ [![Test Coverage](https://codeclimate.com/github/rorkjop/klarna-checkout-ruby/badges/coverage.svg)](https://codeclimate.com/github/rorkjop/klarna-checkout-ruby/coverage)
4
+ [![Gem Version](https://badge.fury.io/rb/klarna-checkout.png)](http://badge.fury.io/rb/klarna-checkout)
2
5
 
3
6
  # Klarna Checkout
4
7
 
@@ -82,7 +85,7 @@ Klarna::Checkout.configure do |config|
82
85
  end
83
86
 
84
87
 
85
- # Instead of repeating yourself with supplying the same attributes for each
88
+ # Instead of repeating yourself with supplying the same attributes for each
86
89
  # order you can configure some default attributes
87
90
  Klarna::Checkout::Order.defaults = {
88
91
  purchase_country: 'NO',
@@ -110,10 +113,8 @@ order.purchase_country
110
113
 
111
114
  ## Supported Rubies
112
115
 
113
- * 1.9.2
114
- * 1.9.3
115
- * 2.0.0
116
- * 2.1.0
116
+ * 2.2
117
+ * 2.4
117
118
 
118
119
  ## Contributing
119
120
 
@@ -1,9 +1,7 @@
1
1
  require "klarna/checkout/version"
2
2
  require "klarna/checkout/client"
3
3
  require "klarna/checkout/configuration"
4
-
5
4
  require "klarna/checkout/resource"
6
-
7
5
  require "klarna/checkout/address"
8
6
  require "klarna/checkout/cart"
9
7
  require "klarna/checkout/customer"
@@ -7,7 +7,8 @@ module Klarna
7
7
 
8
8
  attr_accessor :type, :ean, :reference, :name, :uri, :image_uri, :quantity,
9
9
  :unit_price, :total_price_excluding_tax, :total_tax_amount,
10
- :total_price_including_tax, :discount_rate, :tax_rate
10
+ :total_price_including_tax, :discount_rate, :tax_rate,
11
+ :merchant_item_data
11
12
 
12
13
  validates_presence_of :reference, :name, :quantity, :unit_price, :tax_rate
13
14
 
@@ -22,7 +23,8 @@ module Klarna
22
23
  :quantity => @quantity,
23
24
  :unit_price => @unit_price,
24
25
  :discount_rate => @discount_rate,
25
- :tax_rate => @tax_rate
26
+ :tax_rate => @tax_rate,
27
+ :merchant_item_data => @merchant_item_data
26
28
  })
27
29
  end
28
30
  end
@@ -25,7 +25,7 @@ module Klarna
25
25
  def environment=(new_env)
26
26
  new_env = new_env.to_sym
27
27
  unless VALID_ENVS.include?(new_env)
28
- raise "Environment must be one of: #{VALID_ENVS.join(', ')}"
28
+ raise ArgumentError, "Environment must be one of: #{VALID_ENVS.join(', ')}"
29
29
  end
30
30
 
31
31
  @environment = new_env
@@ -47,7 +47,7 @@ module Klarna
47
47
  order
48
48
  end
49
49
 
50
- def read_order(id)
50
+ def read_order(id)
51
51
  response = https_connection.get do |req|
52
52
  req.url "/checkout/orders/#{id}"
53
53
 
@@ -74,24 +74,26 @@ module Klarna
74
74
  Digest::SHA256.base64digest(payload)
75
75
  end
76
76
 
77
- def handle_status_code(code, msg = nil, &blk)
77
+ def handle_status_code(code, msg = nil)
78
78
  case Integer(code)
79
- when 200, 201
80
- yield if block_given?
81
- when 401
82
- raise Klarna::Checkout::UnauthorizedException.new(msg)
83
- when 403
84
- raise Klarna::Checkout::ForbiddenException.new(msg)
85
- when 404
86
- raise Klarna::Checkout::NotFoundException.new(msg)
87
- when 405
88
- raise Klarna::Checkout::MethodNotAllowedException.new(msg)
89
- when 406
90
- raise Klarna::Checkout::NotAcceptableException.new(msg)
91
- when 415
92
- raise Klarna::Checkout::UnsupportedMediaTypeException.new(msg)
93
- when 500
94
- raise Klarna::Checkout::InternalServerErrorException.new(msg)
79
+ when 200, 201
80
+ yield if block_given?
81
+ when 400
82
+ raise Klarna::Checkout::BadRequest.new(msg)
83
+ when 401
84
+ raise Klarna::Checkout::UnauthorizedException.new(msg)
85
+ when 403
86
+ raise Klarna::Checkout::ForbiddenException.new(msg)
87
+ when 404
88
+ raise Klarna::Checkout::NotFoundException.new(msg)
89
+ when 405
90
+ raise Klarna::Checkout::MethodNotAllowedException.new(msg)
91
+ when 406
92
+ raise Klarna::Checkout::NotAcceptableException.new(msg)
93
+ when 415
94
+ raise Klarna::Checkout::UnsupportedMediaTypeException.new(msg)
95
+ when 500
96
+ raise Klarna::Checkout::InternalServerErrorException.new(msg)
95
97
  end
96
98
  end
97
99
 
@@ -106,7 +108,7 @@ module Klarna
106
108
  req.url path
107
109
 
108
110
  req.headers['Authorization'] = "Klarna #{sign_payload(request_body)}"
109
- req.headers['Accept'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json',
111
+ req.headers['Accept'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json'
110
112
  req.headers['Content-Type'] = 'application/vnd.klarna.checkout.aggregated-order-v2+json'
111
113
  req.headers['Accept-Encoding'] = ''
112
114
 
@@ -18,7 +18,7 @@ module HasMany
18
18
  new_value = new_value.map { |hash| klass.new(hash) }
19
19
  instance_variable_set(inst_var, new_value)
20
20
  else
21
- raise "Unsupported type for relation #{association}: #{new_value.first.class.to_s}"
21
+ raise "Unsupported type for relation #{association}: #{new_value.first.class}"
22
22
  end
23
23
  end
24
24
  end
@@ -10,7 +10,7 @@ module HasOne
10
10
  when Hash
11
11
  instance_variable_set(inst_var, klass.new(new_value))
12
12
  else
13
- raise "Unsupported type for relation #{association}: #{new_value.class.to_s}"
13
+ raise "Unsupported type for relation #{association}: #{new_value.class}"
14
14
  end
15
15
  end
16
16
  end
@@ -11,7 +11,7 @@ module Klarna
11
11
  end
12
12
  end
13
13
 
14
- def configure(&blk)
14
+ def configure
15
15
  yield(self)
16
16
  end
17
17
 
@@ -1,6 +1,9 @@
1
1
  class Klarna::Checkout::Exception < StandardError
2
2
  end
3
3
 
4
+ class Klarna::Checkout::BadRequest < Klarna::Checkout::Exception
5
+ end
6
+
4
7
  class Klarna::Checkout::UnauthorizedException < Klarna::Checkout::Exception
5
8
  end
6
9
 
@@ -8,7 +8,7 @@ module Klarna
8
8
 
9
9
  attr_accessor :id, :status, :reference, :reservation, :started_at,
10
10
  :completed_at, :created_at, :last_modified_at, :expires_at,
11
- :locale
11
+ :locale, :merchant_order_data
12
12
 
13
13
  attr_accessor :purchase_country, :purchase_currency
14
14
 
@@ -27,12 +27,14 @@ module Klarna
27
27
  def as_json
28
28
  json = json_sanitize({
29
29
  :merchant_reference => (@merchant_reference && @merchant_reference.as_json),
30
- :purchase_country => @purchase_country,
31
- :purchase_currency => @purchase_currency,
32
- :locale => @locale,
33
- :cart => @cart.as_json,
34
- :gui => (@gui && @gui.as_json),
30
+ :purchase_country => @purchase_country,
31
+ :purchase_currency => @purchase_currency,
32
+ :locale => @locale,
33
+ :merchant_order_data => @merchant_order_data,
34
+ :cart => @cart.as_json,
35
+ :gui => (@gui && @gui.as_json),
35
36
  :merchant => @merchant.as_json,
37
+ :status => status,
36
38
  :shipping_address => (@shipping_address && @shipping_address.as_json)
37
39
  })
38
40
  if id || json[:gui].nil?
@@ -41,6 +43,9 @@ module Klarna
41
43
  if id
42
44
  json.delete(:merchant)
43
45
  end
46
+ if status != 'created'
47
+ json.delete(:status)
48
+ end
44
49
  json
45
50
  end
46
51
 
@@ -13,7 +13,7 @@ module Klarna
13
13
 
14
14
  def initialize(args = {})
15
15
  self.class.defaults.deep_merge(args).each_pair do |attr, value|
16
- setter = "#{attr.to_s}="
16
+ setter = "#{attr}="
17
17
  self.send(setter, value) if respond_to?(setter)
18
18
  end
19
19
  end
@@ -24,7 +24,7 @@ module Klarna
24
24
  end
25
25
 
26
26
  def json_sanitize(hash, keys = [])
27
- hash.reject! { |k, v| v.nil? }
27
+ hash.reject! { |_, v| v.nil? }
28
28
  hash.slice!(*Array(keys)) if keys.any?
29
29
  hash
30
30
  end
@@ -1,5 +1,5 @@
1
1
  module Klarna
2
2
  module Checkout
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.5"
4
4
  end
5
5
  end
@@ -32,8 +32,8 @@ describe "updating existing order" do
32
32
  end
33
33
  end
34
34
 
35
- specify { subject.merchant_reference.orderid1.should eq 'newreference' }
36
- specify { subject.cart.items[0].quantity.should eq 50 }
35
+ specify { expect(subject.merchant_reference.orderid1).to eq 'newreference' }
36
+ specify { expect(subject.cart.items[0].quantity).to eq 50 }
37
37
  end
38
38
  end
39
39
  end
@@ -38,7 +38,8 @@ describe Klarna::Checkout::Cart do
38
38
  total_tax_amount: 50,
39
39
  total_price_including_tax: 250,
40
40
  discount_rate: 0,
41
- tax_rate: 2500
41
+ tax_rate: 2500,
42
+ merchant_item_data: 'size=L;'
42
43
  }]
43
44
  end
44
45
 
@@ -50,16 +51,17 @@ describe Klarna::Checkout::Cart do
50
51
  describe "items/0" do
51
52
  subject { json_hash[:items][0] }
52
53
 
53
- its([:type]) { should eq 'physical' }
54
- its([:ean]) { should eq '1123581220325' }
55
- its([:reference]) { should eq '1123581220325' }
56
- its([:name]) { should eq 'Widget' }
57
- its([:uri]) { should eq 'http://www.example.com/product-uri' }
58
- its([:image_uri]) { should eq 'http://www.example.com/product-image-uri' }
59
- its([:quantity]) { should eq 1 }
60
- its([:unit_price]) { should eq 250 }
54
+ its([:type]) { should eq 'physical' }
55
+ its([:ean]) { should eq '1123581220325' }
56
+ its([:reference]) { should eq '1123581220325' }
57
+ its([:name]) { should eq 'Widget' }
58
+ its([:uri]) { should eq 'http://www.example.com/product-uri' }
59
+ its([:image_uri]) { should eq 'http://www.example.com/product-image-uri' }
60
+ its([:quantity]) { should eq 1 }
61
+ its([:unit_price]) { should eq 250 }
61
62
  its([:discount_rate]) { should eq 0 }
62
63
  its([:tax_rate]) { should eq 2500 }
64
+ its([:merchant_item_data]) { should eq 'size=L;' }
63
65
  end
64
66
  end
65
67
  end
@@ -23,28 +23,28 @@ describe Klarna::Checkout::Client do
23
23
  end
24
24
 
25
25
  it "shouldn't be necessary to provide the secret twice" do
26
- described_class.new.shared_secret.should eq 'foobar'
26
+ expect(described_class.new.shared_secret).to eq 'foobar'
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
31
  describe "#environment" do
32
32
  it "defaults to :test" do
33
- subject.environment.should eq :test
33
+ expect(subject.environment).to eq :test
34
34
  end
35
35
 
36
36
  it "doesn't allow arbitrary values" do
37
37
  expect {
38
38
  subject.environment = :foo
39
- }.to raise_error
39
+ }.to raise_error(ArgumentError)
40
40
  end
41
41
 
42
42
  it "accepts strings" do
43
43
  subject.environment = 'test'
44
- subject.environment.should eq :test
44
+ expect(subject.environment).to eq :test
45
45
 
46
46
  subject.environment = 'production'
47
- subject.environment.should eq :production
47
+ expect(subject.environment).to eq :production
48
48
  end
49
49
  end
50
50
 
@@ -77,8 +77,7 @@ describe Klarna::Checkout::Client do
77
77
 
78
78
  assert_requested :post, "https://checkout.testdrive.klarna.com/checkout/orders",
79
79
  :headers => {
80
- # TODO: Investigate double definition in header
81
- # 'Accept' => 'application/vnd.klarna.checkout.aggregated-order-v2+json',
80
+ 'Accept' => 'application/vnd.klarna.checkout.aggregated-order-v2+json',
82
81
  'Authorization' => 'Klarna dM+worqeBUs4UrOB3Jr/jSZWI39vP4LNw7NfDjGtW2w=',
83
82
  'Content-Type' => 'application/vnd.klarna.checkout.aggregated-order-v2+json',
84
83
  },
@@ -87,23 +86,23 @@ describe Klarna::Checkout::Client do
87
86
  end
88
87
 
89
88
  it "checks the response" do
90
- subject.should receive(:handle_status_code).with(201, '')
89
+ expect(subject).to receive(:handle_status_code).with(201, '')
91
90
  subject.create_order(order)
92
91
  end
93
92
 
94
93
  it "returns the order" do
95
94
  return_value = subject.create_order(order)
96
- return_value.should eq order
95
+ expect(return_value).to eq order
97
96
  end
98
97
 
99
98
  context "if the order is invalid" do
100
99
  before(:each) do
101
- order.stub(:valid?) { false }
100
+ allow(order).to receive(:valid?) { false }
102
101
  end
103
102
 
104
103
  it "returns a falsy value" do
105
104
  return_value = subject.create_order(order)
106
- return_value.should be_false
105
+ expect(return_value).to be_falsey
107
106
  end
108
107
  end
109
108
  end
@@ -115,7 +114,7 @@ describe Klarna::Checkout::Client do
115
114
  subject.handle_status_code 200 do
116
115
  yielded = true
117
116
  end
118
- yielded.should be_true
117
+ expect(yielded).to be_truthy
119
118
  end
120
119
 
121
120
  context "without block" do
@@ -133,7 +132,7 @@ describe Klarna::Checkout::Client do
133
132
  subject.handle_status_code 201 do
134
133
  yielded = true
135
134
  end
136
- yielded.should be_true
135
+ expect(yielded).to be_truthy
137
136
  end
138
137
 
139
138
  context "without block" do
@@ -145,19 +144,20 @@ describe Klarna::Checkout::Client do
145
144
  end
146
145
  end
147
146
 
147
+
148
148
  context "with 401" do
149
149
  it "raises a Klarna::Checkout::UnauthorizedException" do
150
150
  expect {
151
- subject.handle_status_code(401)
151
+ subject.handle_status_code(401)
152
152
  }.to raise_error(Klarna::Checkout::UnauthorizedException)
153
153
  end
154
154
 
155
155
  describe "handling status code with a message" do
156
156
  it "has a message" do
157
157
  begin
158
- subject.handle_status_code(401, 'foobar')
158
+ subject.handle_status_code(401, 'foobar')
159
159
  rescue => e
160
- e.message.should eq('foobar')
160
+ expect(e.message).to eq('foobar')
161
161
  end
162
162
  end
163
163
  end
@@ -166,7 +166,7 @@ describe Klarna::Checkout::Client do
166
166
  context "with 403" do
167
167
  it "raises a Klarna::Checkout::ForbiddenException" do
168
168
  expect {
169
- subject.handle_status_code(403)
169
+ subject.handle_status_code(403)
170
170
  }.to raise_error(Klarna::Checkout::ForbiddenException)
171
171
  end
172
172
  end
@@ -174,7 +174,7 @@ describe Klarna::Checkout::Client do
174
174
  context "with 404" do
175
175
  it "raises a Klarna::Checkout::NotFoundException" do
176
176
  expect {
177
- subject.handle_status_code(404)
177
+ subject.handle_status_code(404)
178
178
  }.to raise_error(Klarna::Checkout::NotFoundException)
179
179
  end
180
180
  end
@@ -182,7 +182,7 @@ describe Klarna::Checkout::Client do
182
182
  context "with 405" do
183
183
  it "raises a Klarna::Checkout::MethodNotAllowedException" do
184
184
  expect {
185
- subject.handle_status_code(405)
185
+ subject.handle_status_code(405)
186
186
  }.to raise_error(Klarna::Checkout::MethodNotAllowedException)
187
187
  end
188
188
  end
@@ -190,7 +190,7 @@ describe Klarna::Checkout::Client do
190
190
  context "with 406" do
191
191
  it "raises a Klarna::Checkout::NotAcceptableException" do
192
192
  expect {
193
- subject.handle_status_code(406)
193
+ subject.handle_status_code(406)
194
194
  }.to raise_error(Klarna::Checkout::NotAcceptableException)
195
195
  end
196
196
  end
@@ -198,7 +198,7 @@ describe Klarna::Checkout::Client do
198
198
  context "with 415" do
199
199
  it "raises a Klarna::Checkout::UnsupportedMediaTypeException" do
200
200
  expect {
201
- subject.handle_status_code(415)
201
+ subject.handle_status_code(415)
202
202
  }.to raise_error(Klarna::Checkout::UnsupportedMediaTypeException)
203
203
  end
204
204
  end
@@ -233,7 +233,7 @@ describe Klarna::Checkout::Client do
233
233
  end
234
234
 
235
235
  it "checks the response" do
236
- subject.should receive(:handle_status_code).with(200, JSON.generate({ id: "143F7BC0A1090B11C39E7220000" }))
236
+ expect(subject).to receive(:handle_status_code).with(200, JSON.generate({ id: "143F7BC0A1090B11C39E7220000" }))
237
237
  subject.read_order('143F7BC0A1090B11C39E7220000')
238
238
  end
239
239
  end
@@ -261,23 +261,23 @@ describe Klarna::Checkout::Client do
261
261
  end
262
262
 
263
263
  it "checks the response" do
264
- subject.should receive(:handle_status_code).with(200, JSON.generate({ id: "143F7BC0A1090B11C39E7220000" }))
264
+ expect(subject).to receive(:handle_status_code).with(200, JSON.generate({ id: "143F7BC0A1090B11C39E7220000" }))
265
265
  subject.update_order(order)
266
266
  end
267
267
 
268
268
  it "returns an order" do
269
269
  return_value = subject.update_order(order)
270
- return_value.should be_kind_of(Klarna::Checkout::Order)
270
+ expect(return_value).to be_kind_of(Klarna::Checkout::Order)
271
271
  end
272
272
 
273
273
  context "if the order is invalid" do
274
274
  before(:each) do
275
- order.stub(:valid?) { false }
275
+ allow(order).to receive(:valid?) { false }
276
276
  end
277
277
 
278
278
  it "returns a falsy value" do
279
279
  return_value = subject.update_order(order)
280
- return_value.should be_false
280
+ expect(return_value).to be_falsey
281
281
  end
282
282
  end
283
283
  end
@@ -47,6 +47,7 @@ describe Klarna::Checkout::Order do
47
47
  purchase_country: 'NO',
48
48
  purchase_currency: 'NOK',
49
49
  locale: 'nb-no',
50
+ merchant_order_data: 'ref=test;',
50
51
  cart: {
51
52
  items: [{
52
53
  reference: '1123581220325',
@@ -74,71 +75,71 @@ describe Klarna::Checkout::Order do
74
75
 
75
76
  it "is invalid without a purchase country" do
76
77
  subject.purchase_country = nil
77
- subject.should_not be_valid
78
+ expect(subject).to_not be_valid
78
79
  end
79
80
 
80
81
  it "is invalid without a purchase currency" do
81
82
  subject.purchase_currency = nil
82
- subject.should_not be_valid
83
+ expect(subject).to_not be_valid
83
84
  end
84
85
 
85
86
  it "is invalid without a locale" do
86
87
  subject.locale = nil
87
- subject.should_not be_valid
88
+ expect(subject).to_not be_valid
88
89
  end
89
90
 
90
91
  let(:cart_item) { subject.cart.items[0] }
91
92
 
92
93
  it "is invalid without a cart item reference" do
93
94
  cart_item.reference = nil
94
- subject.should_not be_valid
95
+ expect(subject).to_not be_valid
95
96
  end
96
97
 
97
98
  it "is invalid without a cart item name" do
98
99
  cart_item.name = nil
99
- subject.should_not be_valid
100
+ expect(subject).to_not be_valid
100
101
  end
101
102
 
102
103
  it "is invalid without a cart item quantity" do
103
104
  cart_item.quantity = nil
104
- subject.should_not be_valid
105
+ expect(subject).to_not be_valid
105
106
  end
106
107
 
107
108
  it "is invalid without a cart item unit price" do
108
109
  cart_item.unit_price = nil
109
- subject.should_not be_valid
110
+ expect(subject).to_not be_valid
110
111
  end
111
112
 
112
113
  it "is invalid without a cart item tax rate" do
113
114
  cart_item.tax_rate = nil
114
- subject.should_not be_valid
115
+ expect(subject).to_not be_valid
115
116
  end
116
117
 
117
118
  let(:merchant) { subject.merchant }
118
119
 
119
120
  it "is invalid without a merchant id" do
120
121
  merchant.id = nil
121
- subject.should_not be_valid
122
+ expect(subject).to_not be_valid
122
123
  end
123
124
 
124
125
  it "is invalid without a merchant terms_uri" do
125
126
  merchant.terms_uri = nil
126
- subject.should_not be_valid
127
+ expect(subject).to_not be_valid
127
128
  end
128
129
 
129
130
  it "is invalid without a merchant checkout_uri" do
130
131
  merchant.checkout_uri = nil
131
- subject.should_not be_valid
132
+ expect(subject).to_not be_valid
132
133
  end
133
134
 
134
135
  it "is invalid without a merchant confirmation_uri" do
135
136
  merchant.confirmation_uri = nil
136
- subject.should_not be_valid
137
+ expect(subject).to_not be_valid
137
138
  end
138
139
 
139
140
  it "is invalid without a merchant push_uri" do
140
141
  merchant.push_uri = nil
141
- subject.should_not be_valid
142
+ expect(subject).to_not be_valid
142
143
  end
143
144
  end
144
145
 
@@ -257,15 +258,37 @@ describe Klarna::Checkout::Order do
257
258
  its([:email]) { should eq 'test@example.com' }
258
259
  its([:phone]) { should eq '99988777' }
259
260
  end
261
+
262
+ describe "status" do
263
+ subject { json_hash[:status] }
264
+
265
+ context "with status 'checkout_incomplete'" do
266
+ before { order.status = 'checkout_incomplete' }
267
+
268
+ it { should be_nil }
269
+ end
270
+
271
+ context "with status 'checkout_complete'" do
272
+ before { order.status = 'checkout_complete' }
273
+
274
+ it { should be_nil }
275
+ end
276
+
277
+ context "with status 'created'" do
278
+ before { order.status = 'created' }
279
+
280
+ it { should eq 'created' }
281
+ end
282
+ end
260
283
  end
261
284
 
262
285
  describe "#to_json" do
263
286
  it "bases it output on #as_json" do
264
- subject.stub(:as_json) { { foo: "bar" } }
265
- subject.to_json.should eq JSON.generate({ foo: "bar" })
287
+ allow(subject).to receive(:as_json) { { foo: "bar" } }
288
+ expect(subject.to_json).to eq JSON.generate({ foo: "bar" })
266
289
 
267
- subject.stub(:as_json) { { bar: "foo" } }
268
- subject.to_json.should eq JSON.generate({ bar: "foo" })
290
+ allow(subject).to receive(:as_json) { { bar: "foo" } }
291
+ expect(subject.to_json).to eq JSON.generate({ bar: "foo" })
269
292
  end
270
293
  end
271
294
 
@@ -286,13 +309,13 @@ describe Klarna::Checkout::Order do
286
309
 
287
310
  it "all new orders have the default values" do
288
311
  order = described_class.new
289
- order.purchase_country.should eq 'NO'
290
- order.purchase_currency.should eq 'NOK'
312
+ expect(order.purchase_country).to eq 'NO'
313
+ expect(order.purchase_currency).to eq 'NOK'
291
314
  end
292
315
 
293
316
  it "should be possible to override the default values" do
294
317
  order = described_class.new(purchase_currency: 'SEK')
295
- order.purchase_currency.should eq 'SEK'
318
+ expect(order.purchase_currency).to eq 'SEK'
296
319
  end
297
320
 
298
321
  it "should be possible to provide any nested values without affecting the defaults" do
@@ -301,8 +324,8 @@ describe Klarna::Checkout::Order do
301
324
  terms_uri: 'http://www.example.com/terms'
302
325
  }
303
326
  })
304
- order.merchant.id.should eq '666666'
305
- order.merchant.terms_uri.should eq 'http://www.example.com/terms'
327
+ expect(order.merchant.id).to eq '666666'
328
+ expect(order.merchant.terms_uri).to eq 'http://www.example.com/terms'
306
329
  end
307
330
 
308
331
  context "when I override an already specified default value" do
@@ -314,20 +337,20 @@ describe Klarna::Checkout::Order do
314
337
 
315
338
  it "newly created objects should use the new default value" do
316
339
  order = described_class.new
317
- order.purchase_currency.should eq 'SEK'
340
+ expect(order.purchase_currency).to eq 'SEK'
318
341
  end
319
342
 
320
343
  it "shouldn't remove the old default values" do
321
344
  order = described_class.new
322
- order.purchase_country.should eq 'NO'
323
- order.merchant.id.should eq '666666'
345
+ expect(order.purchase_country).to eq 'NO'
346
+ expect(order.merchant.id).to eq '666666'
324
347
  end
325
348
  end
326
349
  end
327
350
 
328
351
  it "doesn't allow setting something other than a hash" do
329
352
  expect {
330
- described_class.defaults = :foobar
353
+ described_class.defaults = :foobar
331
354
  }.to raise_error(ArgumentError)
332
355
  end
333
356
  end
@@ -347,9 +370,9 @@ describe Klarna::Checkout::Order do
347
370
 
348
371
  it "should use the configuration's default values" do
349
372
  order = described_class.new
350
- order.purchase_country.should eq 'NO'
351
- order.purchase_currency.should eq 'NOK'
352
- order.merchant.id.should eq '424242'
373
+ expect(order.purchase_country).to eq 'NO'
374
+ expect(order.purchase_currency).to eq 'NOK'
375
+ expect(order.merchant.id).to eq '424242'
353
376
  end
354
377
 
355
378
  context "if I specify another default merchant ID" do
@@ -365,10 +388,10 @@ describe Klarna::Checkout::Order do
365
388
 
366
389
  it "should use my default values instead" do
367
390
  order = described_class.new
368
- order.purchase_country.should eq 'SE'
369
- order.purchase_currency.should eq 'SEK'
370
- order.merchant.id.should eq '666666'
391
+ expect(order.purchase_country).to eq 'SE'
392
+ expect(order.purchase_currency).to eq 'SEK'
393
+ expect(order.merchant.id).to eq '666666'
371
394
  end
372
395
  end
373
- end
396
+ end
374
397
  end
@@ -1,5 +1,5 @@
1
1
  require 'klarna/checkout/version'
2
2
 
3
3
  describe Klarna::Checkout::VERSION do
4
- it { should eq '1.1.3' }
4
+ it { should eq '1.1.5' }
5
5
  end
@@ -1,9 +1,11 @@
1
- require 'klarna/checkout'
1
+ require 'simplecov'
2
+ SimpleCov.start { add_filter "/spec" }
2
3
 
3
4
  require 'webmock/rspec'
4
5
  require 'vcr'
6
+ require 'rspec/its'
5
7
 
6
- # require 'shoulda/matchers'
8
+ require 'klarna/checkout'
7
9
 
8
10
  VCR.configure do |c|
9
11
  c.cassette_library_dir = File.expand_path("../fixtures/vcr_cassettes", __FILE__)
@@ -11,7 +13,6 @@ VCR.configure do |c|
11
13
  end
12
14
 
13
15
  RSpec.configure do |config|
14
- config.treat_symbols_as_metadata_keys_with_true_values = true
15
16
  config.run_all_when_everything_filtered = true
16
17
 
17
18
  config.filter_run :focus => true
@@ -4,12 +4,12 @@ RSpec::Matchers.define :have_attribute do |attr_name| # , type|
4
4
  match do |subject|
5
5
  attr_name = attr_name.to_s
6
6
 
7
- subject.should respond_to("#{attr_name}")
8
- subject.should respond_to("#{attr_name}=")
7
+ expect(subject).to respond_to("#{attr_name}")
8
+ expect(subject).to respond_to("#{attr_name}=")
9
9
 
10
10
  # case type
11
11
  # when :readonly
12
- # # expect {
12
+ # # expect {
13
13
  # subject.public_send("#{attr_name}=")
14
14
  # # }.to raise_error(NoMethodError)
15
15
  # when :mandatory
@@ -23,7 +23,7 @@ RSpec::Matchers.define :have_attribute do |attr_name| # , type|
23
23
 
24
24
  # unless type == :readonly
25
25
  # expect {
26
- # subject.public_send("#{attr_name}=", 'new_value')
26
+ # subject.public_send("#{attr_name}=", 'new_value')
27
27
  # }.to change(subject, attr_name).to('new_value')
28
28
  # end
29
29
  end
@@ -2,16 +2,16 @@ require 'rspec/expectations'
2
2
 
3
3
  RSpec::Matchers.define :have_many do |attr_name, options|
4
4
  match do |subject|
5
- subject.should respond_to(attr_name)
6
- subject.should respond_to("#{attr_name}=")
5
+ expect(subject).to respond_to(attr_name)
6
+ expect(subject).to respond_to("#{attr_name}=")
7
7
 
8
8
  if options[:as]
9
9
  subject.public_send("#{attr_name}=", [{}])
10
- subject.public_send(attr_name).first.class.should eq options[:as]
10
+ expect(subject.public_send(attr_name).first.class).to eq options[:as]
11
11
  end
12
12
  end
13
13
 
14
- failure_message_for_should do |klass|
14
+ failure_message do |klass|
15
15
  "expected #{klass.inspect} to have has_many-association #{attr_name}"
16
16
  end
17
17
  end
@@ -2,16 +2,16 @@ require 'rspec/expectations'
2
2
 
3
3
  RSpec::Matchers.define :have_one do |attr_name, options|
4
4
  match do |subject|
5
- subject.should respond_to(attr_name)
6
- subject.should respond_to("#{attr_name}=")
5
+ expect(subject).to respond_to(attr_name)
6
+ expect(subject).to respond_to("#{attr_name}=")
7
7
 
8
8
  if options[:as]
9
9
  subject.public_send("#{attr_name}=", {})
10
- subject.public_send(attr_name).class.should eq options[:as]
10
+ expect(subject.public_send(attr_name).class).to eq options[:as]
11
11
  end
12
12
  end
13
13
 
14
- failure_message_for_should do |klass|
14
+ failure_message do |klass|
15
15
  "expected #{klass.inspect} to have has_one-association #{attr_name}"
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,153 +1,195 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klarna-checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.5
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-03-19 00:00:00.000000000 Z
11
+ date: 2017-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.11'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '4.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '4.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - '>='
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: guard
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - '>='
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - '>='
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: guard-rspec
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - '>='
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - '>='
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: webmock
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - '>='
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
145
  version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - '>='
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: vcr
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - '>='
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: codeclimate-test-reporter
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
144
186
  - !ruby/object:Gem::Version
145
187
  version: '0'
146
188
  type: :development
147
189
  prerelease: false
148
190
  version_requirements: !ruby/object:Gem::Requirement
149
191
  requirements:
150
- - - '>='
192
+ - - ">="
151
193
  - !ruby/object:Gem::Version
152
194
  version: '0'
153
195
  description: Ruby Wrapper for Klarna Checkout Rest API
@@ -159,6 +201,7 @@ extra_rdoc_files: []
159
201
  files:
160
202
  - LICENSE.txt
161
203
  - README.md
204
+ - lib/klarna/checkout.rb
162
205
  - lib/klarna/checkout/address.rb
163
206
  - lib/klarna/checkout/cart.rb
164
207
  - lib/klarna/checkout/cart_item.rb
@@ -174,7 +217,6 @@ files:
174
217
  - lib/klarna/checkout/order.rb
175
218
  - lib/klarna/checkout/resource.rb
176
219
  - lib/klarna/checkout/version.rb
177
- - lib/klarna/checkout.rb
178
220
  - spec/acceptance/create_order_spec.rb
179
221
  - spec/acceptance/read_order_spec.rb
180
222
  - spec/acceptance/update_order_spec.rb
@@ -192,7 +234,7 @@ files:
192
234
  - spec/support/matchers/have_attribute.rb
193
235
  - spec/support/matchers/have_many.rb
194
236
  - spec/support/matchers/have_one.rb
195
- homepage: https://github.com/Skalar/klarna-checkout-ruby
237
+ homepage: https://github.com/rorkjop/klarna-checkout-ruby
196
238
  licenses:
197
239
  - MIT
198
240
  metadata: {}
@@ -202,20 +244,20 @@ require_paths:
202
244
  - lib
203
245
  required_ruby_version: !ruby/object:Gem::Requirement
204
246
  requirements:
205
- - - '>='
247
+ - - "~>"
206
248
  - !ruby/object:Gem::Version
207
- version: '0'
249
+ version: '2.2'
208
250
  required_rubygems_version: !ruby/object:Gem::Requirement
209
251
  requirements:
210
- - - '>='
252
+ - - ">="
211
253
  - !ruby/object:Gem::Version
212
254
  version: '0'
213
255
  requirements: []
214
256
  rubyforge_project:
215
- rubygems_version: 2.1.5
257
+ rubygems_version: 2.6.11
216
258
  signing_key:
217
259
  specification_version: 4
218
- summary: '...'
260
+ summary: "..."
219
261
  test_files:
220
262
  - spec/acceptance/create_order_spec.rb
221
263
  - spec/acceptance/read_order_spec.rb
@@ -234,4 +276,3 @@ test_files:
234
276
  - spec/support/matchers/have_attribute.rb
235
277
  - spec/support/matchers/have_many.rb
236
278
  - spec/support/matchers/have_one.rb
237
- has_rdoc: