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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e38e512946fd7304c91accccae965f8742e3c99
4
- data.tar.gz: 575e40eeb308bede813d8837e379968de3fd478d
3
+ metadata.gz: a053d316d105c8a76dd3e33ca77688c8d0b750cd
4
+ data.tar.gz: 85e72b92faac5dea652d0222ebad043b5bb34abf
5
5
  SHA512:
6
- metadata.gz: 76593c8f81683dbdf32e7a76517ca3dcfc0e8b41abb8cbe2e77831d27d5c2c682e7579d27388b2f0c815cff9519a71097c578ec227408bf405471d9d24d5e91d
7
- data.tar.gz: d791fc372219a818af9398670c3f204d161aec6cd129a5504ebbca34659ccccc2bd72f646ce906aa51199d134bf97305bd3e8a50edade37f3f0eabf31b6962e7
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({ shared_secret: 'your-shared-secret' })
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: 'https://checkout.testdrive.klarna.com')
76
+ @https_connection ||= Faraday.new(url: host)
54
77
  end
55
78
  end
56
79
  end
@@ -1,5 +1,5 @@
1
1
  module Klarna
2
2
  module Checkout
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  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
 
@@ -1,5 +1,5 @@
1
- require 'klarna/checkout/client'
1
+ require 'klarna/checkout/version'
2
2
 
3
3
  describe Klarna::Checkout::VERSION do
4
- it { should eq '0.0.1' }
4
+ it { should eq '0.0.3' }
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klarna-checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theodor Tonum