klarna-checkout 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/klarna/checkout/client.rb +25 -2
- data/lib/klarna/checkout/version.rb +1 -1
- data/spec/lib/klarna/checkout/client_spec.rb +34 -0
- data/spec/lib/klarna/checkout/version_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a053d316d105c8a76dd3e33ca77688c8d0b750cd
|
4
|
+
data.tar.gz: 85e72b92faac5dea652d0222ebad043b5bb34abf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52ed946b853c40f42532642834872404372abf665e16587fba4bd6245933391008037cede47e648b7b6a10f2192151fa5457027701c8a6dc6ef9b209d604783d
|
7
|
+
data.tar.gz: 696ada5b3d440b29a3ea74df2cd4257cfd3af2d4f0dbc3814a69d5347bceac3837d23bbf5a35fcacbf0df972864725a542e4eca645038f04339be6fbd3138357
|
data/README.md
CHANGED
@@ -21,7 +21,10 @@ Or install it yourself as:
|
|
21
21
|
```ruby
|
22
22
|
require 'klarna/checkout'
|
23
23
|
|
24
|
-
client = Klarna::Checkout::Client.new({
|
24
|
+
client = Klarna::Checkout::Client.new({
|
25
|
+
shared_secret: 'your-shared-secret',
|
26
|
+
environment: :test # or :production
|
27
|
+
})
|
25
28
|
|
26
29
|
# Initialize an order
|
27
30
|
order = Klarna::Checkout::Order.new({
|
@@ -5,7 +5,7 @@ require 'faraday'
|
|
5
5
|
module Klarna
|
6
6
|
module Checkout
|
7
7
|
class Client
|
8
|
-
attr_accessor :shared_secret
|
8
|
+
attr_accessor :shared_secret, :environment
|
9
9
|
|
10
10
|
def initialize(args = {})
|
11
11
|
args.each do |(k,v)|
|
@@ -13,6 +13,29 @@ module Klarna
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
VALID_ENVS = [:test, :production]
|
17
|
+
|
18
|
+
def environment
|
19
|
+
@environment || :test
|
20
|
+
end
|
21
|
+
|
22
|
+
def environment=(new_env)
|
23
|
+
new_env = new_env.to_sym
|
24
|
+
unless VALID_ENVS.include?(new_env)
|
25
|
+
raise "Environment must be one of: #{VALID_ENVS.join(', ')}"
|
26
|
+
end
|
27
|
+
|
28
|
+
@environment = new_env
|
29
|
+
end
|
30
|
+
|
31
|
+
def host
|
32
|
+
if environment == :production
|
33
|
+
'https://checkout.klarna.com'
|
34
|
+
else
|
35
|
+
'https://checkout.testdrive.klarna.com'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
16
39
|
def create_order(order)
|
17
40
|
request_body = order.to_json
|
18
41
|
response = https_connection.post do |req|
|
@@ -50,7 +73,7 @@ module Klarna
|
|
50
73
|
private
|
51
74
|
|
52
75
|
def https_connection
|
53
|
-
@https_connection ||= Faraday.new(url:
|
76
|
+
@https_connection ||= Faraday.new(url: host)
|
54
77
|
end
|
55
78
|
end
|
56
79
|
end
|
@@ -12,6 +12,40 @@ describe Klarna::Checkout::Client do
|
|
12
12
|
its(:shared_secret) { should eq 'foobar' }
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "#environment" do
|
16
|
+
it "defaults to :test" do
|
17
|
+
subject.environment.should eq :test
|
18
|
+
end
|
19
|
+
|
20
|
+
it "doesn't allow arbitrary values" do
|
21
|
+
expect {
|
22
|
+
subject.environment = :foo
|
23
|
+
}.to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it "accepts strings" do
|
27
|
+
subject.environment = 'test'
|
28
|
+
subject.environment.should eq :test
|
29
|
+
|
30
|
+
subject.environment = 'production'
|
31
|
+
subject.environment.should eq :production
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#host" do
|
36
|
+
context "with production environment" do
|
37
|
+
subject { described_class.new({ environment: :production })}
|
38
|
+
|
39
|
+
its(:host) { should eq 'https://checkout.klarna.com' }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with test environment" do
|
43
|
+
subject { described_class.new({ environment: :test })}
|
44
|
+
|
45
|
+
its(:host) { should eq 'https://checkout.testdrive.klarna.com' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
15
49
|
describe "#create_order" do
|
16
50
|
subject { described_class.new({shared_secret: 'foobar'}) }
|
17
51
|
|