klarna_proxy 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6fb04c6ab07bbf0933c520a916750907cf9f6c3761ced1d3ebe03f9953424d7e
4
+ data.tar.gz: 86111b779f74cfe464e53ebd58fa8a3b81529e877d6a34d34158bc7f10f9fce2
5
+ SHA512:
6
+ metadata.gz: 0a62b31c6e9cb5d90bbb83d03193a68dc934723f3668d990cfe7dfcdae0c541f0f32be5f606d71819039416fe045652681569a7320bec4c6d823a1d182daaa03
7
+ data.tar.gz: c4e0158b312226e55ab60a819467374f8eb68d35305714f3bc2f9aa867643848227e2ca7eb9689b2a7ccf815cdc0a399a2f737bcf2e46443224c2137aa72ba02
@@ -0,0 +1,24 @@
1
+ jobs:
2
+ build:
3
+ docker:
4
+ - image: 'cimg/ruby:2.7'
5
+ environment:
6
+ RAILS_ENV: test
7
+ steps:
8
+ - checkout
9
+ - run:
10
+ name: 'Generate Gemfile.lock'
11
+ command: bundle lock
12
+ when: always
13
+ - ruby/install-deps
14
+ - ruby/rubocop-check:
15
+ format: progress
16
+ label: Inspecting with Rubocop
17
+ - ruby/rspec-test
18
+ orbs:
19
+ ruby: circleci/ruby@1.1.4
20
+ version: 2.1
21
+ workflows:
22
+ build_and_test:
23
+ jobs:
24
+ - build
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ inherit_gem:
2
+ relaxed-rubocop: .rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
6
+
7
+ Lint/MissingSuper:
8
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in klarna.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
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 ADDED
@@ -0,0 +1,22 @@
1
+ # Klarna SDK
2
+
3
+ This is a non-complete implementation of the Klarna Payment and Klarna Order Management API.
4
+
5
+ ## Development
6
+
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:
8
+
9
+ - `KLARNA_API_KEY`
10
+ - `KLARNA_API_SECRET`
11
+
12
+ Both can be obtained from Klarna. There's a third option to set the region; currently tested are `us` (default) and `uk`.
13
+
14
+ - `KLARNA_REGION`
15
+
16
+ ### Dummy HTTP app
17
+
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`.
19
+
20
+ ### Testing
21
+
22
+ The tests can be executed via `rake`.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/app ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'pry'
5
+
6
+ base_dir = File.join(File.expand_path(__dir__), '..')
7
+ $LOAD_PATH.unshift(File.join(base_dir))
8
+ $LOAD_PATH.unshift(File.join(base_dir, 'lib'))
9
+
10
+ require 'klarna'
11
+ require 'spec/support/fake_frontend'
12
+
13
+ FakeFrontend.run!
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'klarna'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ # frozen_string_literal: true
3
+
4
+ set -euo pipefail
5
+ IFS=$'\n\t'
6
+ set -vx
7
+
8
+ bundle install
9
+
10
+ # Do any other automated setup that you need to do here
data/klarna.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'klarna/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'klarna_proxy'
9
+ spec.version = Klarna::VERSION
10
+ spec.authors = ['Andrea Vassallo']
11
+ spec.email = ['andrea.vassallo.94@gmail.com']
12
+
13
+ spec.summary = 'Klarna Ruby Proxy'
14
+ spec.description = 'Provides a Ruby interface to the current Klarna API, forked and inspired by https://rubygems.org/gems/klarna_client/versions/0.1.0'
15
+ spec.homepage = ''
16
+ spec.license = 'Apache-2.0'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+ spec.required_ruby_version = '>= 2.5'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 2.2.22'
25
+ spec.add_development_dependency 'codecov', '~> 0.5.2'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'relaxed-rubocop', '~> 2.5'
28
+ spec.add_development_dependency 'rspec', '~> 3.9'
29
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4.1'
30
+ spec.add_development_dependency 'rubocop', '~> 1.18', '>= 1.18.4'
31
+ spec.add_development_dependency 'simplecov', '~> 0.21.2'
32
+ spec.add_development_dependency 'sinatra-contrib'
33
+ spec.add_development_dependency 'thin'
34
+ spec.add_development_dependency 'vcr', '~> 5.1'
35
+ spec.add_development_dependency 'webmock', '~> 3.8'
36
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ class Capture < Client
5
+ def shipping_info(order_id, capture_id, data)
6
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/captures/#{capture_id}/shipping-info") do |request|
7
+ request.body = data.to_json
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ module Klarna
8
+ class Client
9
+ def initialize(configuration)
10
+ @configuration = configuration
11
+ end
12
+
13
+ private
14
+
15
+ def do_request(type, service)
16
+ uri = URI.parse(configuration.endpoint)
17
+ http = Net::HTTP.new(uri.host, uri.port)
18
+ http.use_ssl = true
19
+
20
+ request = case type
21
+ when :post
22
+ Net::HTTP::Post.new(service)
23
+ when :patch
24
+ Net::HTTP::Patch.new(service)
25
+ when :delete
26
+ Net::HTTP::Delete.new(service)
27
+ when :get
28
+ Net::HTTP::Get.new(service)
29
+ else
30
+ raise "Wrong request type <#{type}>. Allowed [:post, :delete, :get]"
31
+ end
32
+
33
+ request.content_type = 'application/json'
34
+ request.basic_auth(configuration.api_key, configuration.api_secret)
35
+
36
+ if configuration.user_agent
37
+ request['User-Agent'] =
38
+ "Ruby Klarna #{Klarna::VERSION} (#{configuration.user_agent} Ruby/#{RUBY_VERSION})"
39
+ end
40
+
41
+ yield(request) if block_given?
42
+
43
+ http.set_debug_output(configuration.debugger) if configuration.debugger
44
+ response = http.request(request)
45
+ http.set_debug_output(nil) if configuration.debugger
46
+
47
+ Klarna::Response.new(response)
48
+ end
49
+
50
+ attr_reader :configuration
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ class Configuration
5
+ attr_accessor :environment, :country, :zone, :api_key, :api_secret, :debugger, :user_agent
6
+
7
+ def initialize
8
+ @country = :us
9
+ @zone = :us
10
+ @environment = :production
11
+ @debugger = false
12
+
13
+ @endpoints = {
14
+ europe: {
15
+ test: 'https://api.playground.klarna.com',
16
+ production: 'https://api.klarna.com'
17
+ },
18
+ oceania: {
19
+ test: 'https://api-oc.playground.klarna.com',
20
+ production: 'https://api-oc.klarna.com'
21
+ },
22
+ us: {
23
+ test: 'https://api-na.playground.klarna.com',
24
+ production: 'https://api-na.klarna.com'
25
+ }
26
+ }
27
+ end
28
+
29
+ def endpoint
30
+ endpoints[zone.to_sym][environment.to_sym]
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :endpoints
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ class CustomerToken < Client
5
+ def place_order(customer_token, data)
6
+ do_request(:post, "/customer-token/v1/tokens/#{customer_token}/order") do |request|
7
+ request.body = data.to_json
8
+ end
9
+ end
10
+
11
+ def get(customer_token)
12
+ do_request(:get, "/customer-token/v1/tokens/#{customer_token}")
13
+ end
14
+
15
+ def cancel(customer_token)
16
+ do_request(:patch, "/customer-token/v1/tokens/#{customer_token}/status") do |request|
17
+ request.body = { status: 'CANCELLED' }.to_json
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ class Order < Client
5
+ def get(order_id)
6
+ do_request(:get, "/ordermanagement/v1/orders/#{order_id}")
7
+ end
8
+
9
+ def cancel(order_id)
10
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/cancel")
11
+ end
12
+
13
+ def capture(order_id, data)
14
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/captures") do |request|
15
+ request.body = data.to_json
16
+ end
17
+ end
18
+
19
+ # Use this API call to extend the expiry time of an order.
20
+
21
+ # The possibility and length of order expiry extensions is set on a case by case basis in the contract with Klarna.
22
+
23
+ # HTTP REQUEST
24
+ # POST /ordermanagement/v1/orders/{order_id}/extend-authorization-time
25
+ def extend(order_id)
26
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/extend-authorization-time")
27
+ end
28
+
29
+ # 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.
30
+
31
+ # HTTP REQUEST
32
+ # POST /ordermanagement/v1/orders/{order_id}/release-remaining-authorization
33
+ def release(order_id)
34
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/release-remaining-authorization")
35
+ end
36
+
37
+ # This API call is used by merchants to acknowledge the order. You will receive the order confirmation push until the order has been acknowledged.
38
+
39
+ # HTTP REQUEST
40
+ # POST /ordermanagement/v1/orders/{order_id}/acknowledge
41
+ def acknowledge(order_id)
42
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/acknowledge")
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ class Payment < Client
5
+ def create_session(data)
6
+ do_request(:post, '/payments/v1/sessions') do |request|
7
+ request.body = data.to_json
8
+ end
9
+ end
10
+
11
+ def update_session(session_id, data)
12
+ do_request(:post, "/payments/v1/sessions/#{session_id}") do |request|
13
+ request.body = data.to_json
14
+ end
15
+ end
16
+
17
+ def place_order(authorization_token, data)
18
+ do_request(:post, "/payments/v1/authorizations/#{authorization_token}/order") do |request|
19
+ request.body = data.to_json
20
+ end
21
+ end
22
+
23
+ def customer_token(authorization_token, data)
24
+ do_request(:post, "/payments/v1/authorizations/#{authorization_token}/customer-token") do |request|
25
+ request.body = data.to_json
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ class Refund < Client
5
+ # This API call is used to refund an amount of a captured order. The refunded amount will be credited to the customer.
6
+
7
+ # The refunded amount must not be higher than captured_amount. The refunded amount can be accompanied by a descriptive text and order lines.
8
+
9
+ # 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.
10
+
11
+ # HTTP REQUEST
12
+ # POST /ordermanagement/v1/orders/{order_id}/refunds
13
+ def create(order_id, data)
14
+ do_request(:post, "/ordermanagement/v1/orders/#{order_id}/refunds") do |request|
15
+ request.body = data.to_json
16
+ end
17
+ end
18
+
19
+ # This API call is used to read information on a refund.
20
+
21
+ # HTTP REQUEST
22
+ # GET /ordermanagement/v1/orders/{order_id}/refunds/{refund_id}
23
+ def get(order_id, refund_id)
24
+ do_request(:get, "/ordermanagement/v1/orders/#{order_id}/refunds/#{refund_id}")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ class Response
5
+ attr_reader :code, :body, :http_response, :headers
6
+
7
+ def initialize(http_response)
8
+ @http_response = http_response
9
+ @code = http_response.code.to_i
10
+ @body = parse_body
11
+ @headers = http_response.to_hash
12
+ end
13
+
14
+ def success?
15
+ @code < 300
16
+ end
17
+
18
+ def error?
19
+ @code >= 300
20
+ end
21
+
22
+ def [](index)
23
+ http_response.send('[]', index)
24
+ end
25
+
26
+ def method_missing(method, *args, &block)
27
+ return @body[method.to_s] if body_field?(method)
28
+
29
+ super
30
+ end
31
+
32
+ def respond_to_missing?(method, *args, &block)
33
+ return true if body_field?(method)
34
+
35
+ super
36
+ end
37
+
38
+ def error_code
39
+ return @body['error_code'] if body_field?('error_code')
40
+
41
+ @code.to_s
42
+ end
43
+
44
+ private
45
+
46
+ def parse_body
47
+ return nil if @http_response.body.nil? || @http_response.body.empty?
48
+
49
+ case @http_response.content_type
50
+ when 'application/json'
51
+ JSON.parse(@http_response.body)
52
+ when 'text/html'
53
+ http_response.body
54
+ else
55
+ http_response.body
56
+ end
57
+ end
58
+
59
+ def body_field?(field)
60
+ @body.is_a?(Hash) && @body.key?(field.to_s)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Klarna
4
+ VERSION = '0.9.3'
5
+ end
data/lib/klarna.rb ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'klarna/version'
4
+ require 'klarna/configuration'
5
+ require 'klarna/client'
6
+ require 'klarna/response'
7
+ require 'klarna/order'
8
+ require 'klarna/capture'
9
+ require 'klarna/payment'
10
+ require 'klarna/refund'
11
+ require 'klarna/customer_token'
12
+
13
+ module Klarna
14
+ class << self
15
+ attr_writer :configuration
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def self.configure
23
+ yield(configuration)
24
+ end
25
+
26
+ def self.client(type = :order)
27
+ case type
28
+ when :payment
29
+ Payment.new(configuration)
30
+ when :order
31
+ Order.new(configuration)
32
+ when :refund
33
+ Refund.new(configuration)
34
+ when :capture
35
+ Capture.new(configuration)
36
+ when :customer_token
37
+ CustomerToken.new(configuration)
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: klarna_proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.3
5
+ platform: ruby
6
+ authors:
7
+ - Andrea Vassallo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.22
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.22
27
+ - !ruby/object:Gem::Dependency
28
+ name: codecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: relaxed-rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.18'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 1.18.4
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '1.18'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 1.18.4
117
+ - !ruby/object:Gem::Dependency
118
+ name: simplecov
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.21.2
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.21.2
131
+ - !ruby/object:Gem::Dependency
132
+ name: sinatra-contrib
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: thin
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: vcr
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '5.1'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '5.1'
173
+ - !ruby/object:Gem::Dependency
174
+ name: webmock
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '3.8'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '3.8'
187
+ description: Provides a Ruby interface to the current Klarna API, forked and inspired
188
+ by https://rubygems.org/gems/klarna_client/versions/0.1.0
189
+ email:
190
+ - andrea.vassallo.94@gmail.com
191
+ executables: []
192
+ extensions: []
193
+ extra_rdoc_files: []
194
+ files:
195
+ - ".circleci/config.yml"
196
+ - ".gitignore"
197
+ - ".rspec"
198
+ - ".rubocop.yml"
199
+ - ".travis.yml"
200
+ - Gemfile
201
+ - LICENSE.txt
202
+ - README.md
203
+ - Rakefile
204
+ - bin/app
205
+ - bin/console
206
+ - bin/setup
207
+ - klarna.gemspec
208
+ - lib/klarna.rb
209
+ - lib/klarna/capture.rb
210
+ - lib/klarna/client.rb
211
+ - lib/klarna/configuration.rb
212
+ - lib/klarna/customer_token.rb
213
+ - lib/klarna/order.rb
214
+ - lib/klarna/payment.rb
215
+ - lib/klarna/refund.rb
216
+ - lib/klarna/response.rb
217
+ - lib/klarna/version.rb
218
+ homepage: ''
219
+ licenses:
220
+ - Apache-2.0
221
+ metadata: {}
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '2.5'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ requirements: []
237
+ rubygems_version: 3.1.6
238
+ signing_key:
239
+ specification_version: 4
240
+ summary: Klarna Ruby Proxy
241
+ test_files: []