klarna_client 0.1.0 → 0.9.0

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: 594984a47138a66cfe1287b38b00794bfee6b456
4
- data.tar.gz: 5fd0758a92f3181a0e7bdbf3dcf92ad19c9ed397
3
+ metadata.gz: 0ee794ceba5b95a796a072c57c091c6dc0b06687
4
+ data.tar.gz: 5446e167d72afc1cf6e0113b157685e7452b4445
5
5
  SHA512:
6
- metadata.gz: 9e15c6f844f006617f211689d52861c6b5f0eb2a2ae336546d09b25f322c037f04148764113878ae93d665975dc22ed39ab08bd5a2710752d77303b16670eb60
7
- data.tar.gz: 33011291812077f5e1f347dfe8c7b5296a3f86d71408d3c4b95c1caf16999cff6ce337b6e76cb461c9dfbba70c4f9ad5b9d1eabcc81660a9314fefda7d7b362f
6
+ metadata.gz: 75ccfaa5cd285b42e7fff3c3c59949de8a6bc0994617f04442bf40d418dbbb189dc68323c0f9dcfe8170bb3901654fda11734ca8b58b05482db7f2a479be3565
7
+ data.tar.gz: b341dfdbe3192a5ffe986405c89f487df21cd3dd8d3d90c5bcacc8db23c3757144c415b8f72c2dcb35682f55eb6665c5668352ed764f2fbe0d1d088c81ac7b02
@@ -1,5 +1,5 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.7
5
- before_install: gem install bundler -v 1.13.6
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.4
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in klarna_client.gemspec
3
+ # Specify your gem's dependencies in klarna.gemspec
4
4
  gemspec
@@ -1,21 +1,202 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Pascal Jungblut
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2017 Klarna AB
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -1,41 +1,22 @@
1
- # KlarnaClient
1
+ # Klarna SDK
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/klarna_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'klarna_client'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install klarna_client
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
3
+ This is a non-complete implementation of the Klarna Credit and Klarna Order Management API.
26
4
 
27
5
  ## Development
28
6
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
7
+ To work properly the library needs credentials for the Klarna API. In development these credentials are read from the environment. In an actual application they are passed in as options to the `Klarna::Client`. There must be two variables set when running the tests or the dummy app:
30
8
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
9
+ - `KLARNA_API_KEY`
10
+ - `KLARNA_API_SECRET`
32
11
 
33
- ## Contributing
12
+ Both can be obtained from Klarna. There's a third option to set the region; currently tested are `us` (default) and `uk`.
34
13
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/klarna_client.
14
+ - `KLARNA_REGION`
36
15
 
16
+ ### Dummy HTTP app
37
17
 
38
- ## License
18
+ The gem comes with a dummy Sinatra app that's used in the specs and can also be used for manual testing against the API. That's because some calls to the API require an `authorization_token` which can only be obtained by running frontend code in an iFrame. To run the app, simply execute `bin/app`.
39
19
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
20
+ ### Testing
41
21
 
22
+ The tests can be executed via `rake`.
data/bin/app ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pry'
3
+
4
+ $base_dir = File.join(File.expand_path(__dir__), '..')
5
+ $LOAD_PATH.unshift(File.join($base_dir))
6
+ $LOAD_PATH.unshift(File.join($base_dir, 'lib'))
7
+
8
+ require 'klarna'
9
+ require 'spec/support/fake_frontend.rb'
10
+
11
+ FakeFrontend.run!
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "klarna_client"
4
+ require "klarna"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'klarna/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "klarna_client"
8
+ spec.version = Klarna::VERSION
9
+ spec.authors = ["Jose Antonio Pio Gil", "Pascal Jungblut"]
10
+ spec.email = ["jose.pio@bitspire.de", "pascal.jungblut@bitspire.de"]
11
+
12
+ spec.summary = %q{Klarna Ruby Client}
13
+ spec.description = %q{Provides a Ruby interface to the current Klarna API}
14
+ spec.homepage = ""
15
+ spec.license = "Apache-2.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "poltergeist"
26
+ spec.add_development_dependency "capybara"
27
+ spec.add_development_dependency "capybara-screenshot"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "pry-doc"
30
+ spec.add_development_dependency "json"
31
+ spec.add_development_dependency "sinatra-contrib"
32
+ spec.add_development_dependency "thin"
33
+ spec.add_development_dependency "httplog"
34
+ end
@@ -0,0 +1,35 @@
1
+ require "klarna/version"
2
+ require "klarna/configuration"
3
+ require "klarna/client"
4
+ require "klarna/response"
5
+ require "klarna/order"
6
+ require "klarna/capture"
7
+ require "klarna/credit"
8
+ require "klarna/refund"
9
+
10
+ module Klarna
11
+ class << self
12
+ attr_writer :configuration
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration)
21
+ end
22
+
23
+ def self.client(type = :order)
24
+ case type
25
+ when :credit
26
+ Credit.new(configuration)
27
+ when :order
28
+ Order.new(configuration)
29
+ when :refund
30
+ Refund.new(configuration)
31
+ when :capture
32
+ Capture.new(configuration)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ module Klarna
2
+ class Capture < Client
3
+ def shipping_info(order_id, capture_id, data)
4
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/captures/#{capture_id}/shipping-info") do |request|
5
+ request.body = data.to_json
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+
5
+ module Klarna
6
+ class Client
7
+ def initialize(configuration)
8
+ @configuration = configuration
9
+ end
10
+
11
+
12
+ private
13
+
14
+ def do_request(type, service, &block)
15
+ uri = URI.parse(@configuration.endpoint)
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ http.use_ssl = true
18
+
19
+ request = case type
20
+ when :post
21
+ Net::HTTP::Post.new(service)
22
+ when :delete
23
+ Net::HTTP::Delete.new(service)
24
+ when :get
25
+ Net::HTTP::Get.new(service)
26
+ else
27
+ raise "Wrong request type <#{type}>. Allowed [:post, :delete, :get]"
28
+ end
29
+
30
+
31
+ request.content_type = "application/json"
32
+ request.basic_auth(@configuration.api_key, @configuration.api_secret)
33
+ if @configuration.user_agent
34
+ request["User-Agent"] = "Ruby Klarna #{Klarna::VERSION} (#{@configuration.user_agent.to_s} Ruby/#{RUBY_VERSION})"
35
+ end
36
+
37
+ yield(request) if block_given?
38
+
39
+ http.set_debug_output(@configuration.debugger) if @configuration.debugger
40
+ response = http.request(request)
41
+ http.set_debug_output(nil) if @configuration.debugger
42
+
43
+ Klarna::Response.new(response)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ module Klarna
2
+ class Configuration
3
+ attr_accessor :environment, :country, :api_key, :api_secret, :version, :debugger, :user_agent
4
+
5
+ def initialize
6
+ @country = :us
7
+ @environment = :production
8
+ @endpoints = {
9
+ us: {
10
+ test: "https://api-na.playground.klarna.com",
11
+ production: "https://api-na.klarna.com"
12
+ },
13
+ eu: {
14
+ test: "https://api.playground.klarna.com",
15
+ production: "https://api.klarna.com"
16
+ },
17
+ de: {
18
+ test: "https://api.playground.klarna.com",
19
+ production: "https://api.klarna.com"
20
+ },
21
+ uk: {
22
+ test: "https://api.playground.klarna.com",
23
+ production: "https://api.klarna.com"
24
+ }
25
+ }
26
+ @version = :v1
27
+ @debugger = false #$stdout
28
+ end
29
+
30
+ def endpoint
31
+ @endpoints[@country.to_sym][@environment.to_sym]
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Klarna
2
+ class Credit < Client
3
+
4
+ def create_session(data)
5
+ do_request(:post, "/credit/v1/sessions") do |request|
6
+ request.body = data.to_json
7
+ end
8
+ end
9
+
10
+ def update_session(session_id, data)
11
+ do_request(:post, "/credit/v1/sessions/#{session_id}") do |request|
12
+ request.body = data.to_json
13
+ end
14
+ end
15
+
16
+ def place_order(authorization_token, data)
17
+ do_request(:post, "/credit/v1/authorizations/#{authorization_token}/order") do |request|
18
+ request.body = data.to_json
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ module Klarna
2
+ class Order < Client
3
+ def get(order_id)
4
+ do_request(:get, "/ordermanagement/v1/orders/#{order_id}")
5
+ end
6
+
7
+ def cancel(order_id)
8
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/cancel")
9
+ end
10
+
11
+ def capture(order_id, data)
12
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/captures") do |request|
13
+ request.body = data.to_json
14
+ end
15
+ end
16
+
17
+ # Use this API call to extend the expiry time of an order.
18
+
19
+ # The possibility and length of order expiry extensions is set on a case by case basis in the contract with Klarna.
20
+
21
+ # HTTP REQUEST
22
+ # POST /ordermanagement/v1/orders/{order_id}/extend-authorization-time
23
+ def extend(order_id)
24
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/extend-authorization-time")
25
+ end
26
+
27
+ # This API call is used to release the remaining authorised amount. This means you don't intend do any more captures and that the authorised amount can be returned to the customer.
28
+
29
+ # HTTP REQUEST
30
+ # POST /ordermanagement/v1/orders/{order_id}/release-remaining-authorization
31
+ def release(order_id)
32
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/release-remaining-authorization")
33
+ end
34
+
35
+ # This API call is used by merchants to acknowledge the order. You will receive the order confirmation push until the order has been acknowledged.
36
+
37
+ # HTTP REQUEST
38
+ # POST /ordermanagement/v1/orders/{order_id}/acknowledge
39
+ def acknowledge(order_id)
40
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/acknowledge")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ module Klarna
2
+ class Refund < Client
3
+ # This API call is used to refund an amount of a captured order. The refunded amount will be credited to the customer.
4
+
5
+ # The refunded amount must not be higher than captured_amount. The refunded amount can be accompanied by a descriptive text and order lines.
6
+
7
+ # Note: The response code can vary (by region or by context). Never check for 201 or 204 specifically, use a more general check for 2xx responses.
8
+
9
+ # HTTP REQUEST
10
+ # POST /ordermanagement/v1/orders/{order_id}/refunds
11
+ def create(order_id, data)
12
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/refunds")do |request|
13
+ request.body = data.to_json
14
+ end
15
+ end
16
+
17
+ # This API call is used to read information on a refund.
18
+
19
+ # HTTP REQUEST
20
+ # GET /ordermanagement/v1/orders/{order_id}/refunds/{refund_id}
21
+ def get(order_id, refund_id)
22
+ do_request(:get, "/ordermanagement/v1/orders/#{order_id}/refunds/#{refund_id}")
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ module Klarna
2
+ class Response
3
+ attr_reader :code, :body, :http_response, :headers
4
+
5
+ def initialize(http_response)
6
+ @http_response = http_response
7
+ @code = http_response.code.to_i
8
+ @body = parse_body
9
+ @headers = http_response.to_hash
10
+ end
11
+
12
+ def success?
13
+ @code < 300
14
+ end
15
+
16
+ def error?
17
+ @code >= 300
18
+ end
19
+
20
+ def [](index)
21
+ http_response.send("[]", index)
22
+ end
23
+
24
+ def method_missing(m, *args, &block)
25
+ return @body[m.to_s] if has_body_field(m)
26
+ super
27
+ end
28
+
29
+ def respond_to?(m, *args, &block)
30
+ return true if has_body_field(m)
31
+ super
32
+ end
33
+
34
+ def error_code
35
+ return @body["error_code"] if has_body_field("error_code")
36
+ @code.to_s
37
+ end
38
+
39
+ private
40
+
41
+ def parse_body
42
+ return nil if @http_response.body.nil? || @http_response.body.empty?
43
+
44
+ case @http_response.content_type
45
+ when "application/json"
46
+ JSON.parse(@http_response.body)
47
+ when "text/html"
48
+ http_response.body
49
+ else
50
+ http_response.body
51
+ end
52
+ end
53
+
54
+ def has_body_field(field)
55
+ @body.is_a?(Hash) && @body.has_key?(field.to_s)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Klarna
2
+ VERSION = "0.9.0"
3
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klarna_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Jose Antonio Pio Gil
7
8
  - Pascal Jungblut
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2017-04-20 00:00:00.000000000 Z
12
+ date: 2017-05-08 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -16,14 +17,14 @@ dependencies:
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '1.13'
20
+ version: '1.12'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '1.13'
27
+ version: '1.12'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
@@ -52,8 +53,135 @@ dependencies:
52
53
  - - "~>"
53
54
  - !ruby/object:Gem::Version
54
55
  version: '3.0'
55
- description: Klarna API client
56
+ - !ruby/object:Gem::Dependency
57
+ name: poltergeist
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: capybara
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: capybara-screenshot
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: pry-doc
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: json
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: sinatra-contrib
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: thin
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: httplog
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ description: Provides a Ruby interface to the current Klarna API
56
183
  email:
184
+ - jose.pio@bitspire.de
57
185
  - pascal.jungblut@bitspire.de
58
186
  executables: []
59
187
  extensions: []
@@ -66,14 +194,22 @@ files:
66
194
  - LICENSE.txt
67
195
  - README.md
68
196
  - Rakefile
197
+ - bin/app
69
198
  - bin/console
70
199
  - bin/setup
71
- - klarna_client.gemspec
72
- - lib/klarna_client.rb
73
- - lib/klarna_client/version.rb
74
- homepage: https://github.com/bitspire/klarna_client
200
+ - klarna.gemspec
201
+ - lib/klarna.rb
202
+ - lib/klarna/capture.rb
203
+ - lib/klarna/client.rb
204
+ - lib/klarna/configuration.rb
205
+ - lib/klarna/credit.rb
206
+ - lib/klarna/order.rb
207
+ - lib/klarna/refund.rb
208
+ - lib/klarna/response.rb
209
+ - lib/klarna/version.rb
210
+ homepage: ''
75
211
  licenses:
76
- - MIT
212
+ - Apache-2.0
77
213
  metadata: {}
78
214
  post_install_message:
79
215
  rdoc_options: []
@@ -94,5 +230,5 @@ rubyforge_project:
94
230
  rubygems_version: 2.2.5
95
231
  signing_key:
96
232
  specification_version: 4
97
- summary: Klarna API client
233
+ summary: Klarna Ruby Client
98
234
  test_files: []
@@ -1,27 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'klarna_client/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "klarna_client"
8
- spec.version = KlarnaClient::VERSION
9
- spec.authors = ["Pascal Jungblut"]
10
- spec.email = ["pascal.jungblut@bitspire.de"]
11
-
12
- spec.summary = %q{Klarna API client}
13
- spec.description = %q{Klarna API client}
14
- spec.homepage = "https://github.com/bitspire/klarna_client"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_development_dependency "bundler", "~> 1.13"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.0"
27
- end
@@ -1,5 +0,0 @@
1
- require "klarna_client/version"
2
-
3
- module KlarnaClient
4
- # Your code goes here...
5
- end
@@ -1,3 +0,0 @@
1
- module KlarnaClient
2
- VERSION = "0.1.0"
3
- end