adyen-ruby-api-library 3.0.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +20 -0
- data/README.md +10 -2
- data/lib/adyen/client.rb +8 -6
- data/lib/adyen/result.rb +16 -0
- data/lib/adyen/services/checkout.rb +1 -1
- data/lib/adyen/services/payments.rb +1 -1
- data/lib/adyen/util.rb +21 -0
- data/lib/adyen/version.rb +2 -2
- data/spec/checkout_spec.rb +17 -12
- data/spec/client_spec.rb +18 -0
- data/spec/spec_helper.rb +9 -7
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 57203cec793176b8f389062f66cf734dcc43e183
|
4
|
+
data.tar.gz: 6680ea0897e40cad89569ed46c841dcf45b900a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16075771ada5ca4afb71c798e7823fcd1c2b162a6d0d21919b0a3ea8db301ec5379525c726ebc3d71b0b39d87ada719b539b7457fe927a5aa6ef4754b7dca3be
|
7
|
+
data.tar.gz: 968d9f0cb9a426ce89d8bc17a00cdf50766f1f48dacbb58a1966e3d29ae5fe99a3e784e6d0f40fa86f4f0ef5bfad27576124ad1504746e121af9998abd06f8a1
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Contribution guidelines
|
2
|
+
|
3
|
+
## How to contribute step-by-step
|
4
|
+
|
5
|
+
1. Fork the `Adyen/adyen-ruby-api-library` repository.
|
6
|
+
2. Create a new branch from `develop` in your fork. This makes it easier for you to keep track of your changes.
|
7
|
+
3. Make the desired changes to the code.
|
8
|
+
* If you are adding new functionality or fixing a bug, we recommend you add unit tests that cover it.
|
9
|
+
4. Push the changes to your fork.
|
10
|
+
5. Create a pull request to the `Adyen/adyen-ruby-api-library` repository.
|
11
|
+
6. In your pull request, please describe in detail:
|
12
|
+
* What problem you’re solving
|
13
|
+
* Your approach to fixing the problem
|
14
|
+
* Any tests you wrote
|
15
|
+
7. Check Allow edits from maintainers.
|
16
|
+
8. Create the pull request.
|
17
|
+
9. Ensure that all checks have passed.
|
18
|
+
|
19
|
+
After you create your pull request, one of the code owners will review your code.
|
20
|
+
We aim to review your request within 2-3 business days.
|
data/README.md
CHANGED
@@ -66,7 +66,7 @@ response = adyen.checkout.payments({
|
|
66
66
|
|
67
67
|
### Change API Version
|
68
68
|
```ruby
|
69
|
-
adyen.checkout.version =
|
69
|
+
adyen.checkout.version = 50
|
70
70
|
```
|
71
71
|
|
72
72
|
## List of supported methods
|
@@ -139,7 +139,15 @@ adyen.checkout.version = 49
|
|
139
139
|
## Support
|
140
140
|
|
141
141
|
If you have any problems, questions or suggestions, create an issue here or send your inquiry to support@adyen.com.
|
142
|
-
|
142
|
+
|
143
|
+
## Contributing
|
144
|
+
We strongly encourage you to join us in contributing to this repository so everyone can benefit from:
|
145
|
+
* New features and functionality
|
146
|
+
* Resolved bug fixes and issues
|
147
|
+
* Any general improvements
|
148
|
+
|
149
|
+
Read our [**contribution guidelines**](CONTRIBUTING.md) to find out how.
|
150
|
+
|
143
151
|
## Licence
|
144
152
|
|
145
153
|
MIT license. For more information, see the LICENSE file.
|
data/lib/adyen/client.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
require "faraday"
|
2
2
|
require "json"
|
3
3
|
require_relative "./errors"
|
4
|
+
require_relative "./result"
|
5
|
+
require_relative "./util"
|
4
6
|
|
5
7
|
module Adyen
|
6
8
|
class Client
|
7
9
|
attr_accessor :ws_user, :ws_password, :api_key, :client, :adapter, :live_url_prefix
|
8
10
|
attr_reader :env
|
9
11
|
|
10
|
-
def initialize(ws_user: nil, ws_password: nil, api_key: nil, env: :live, adapter: nil, mock_port: 3001, live_url_prefix: nil)
|
12
|
+
def initialize(ws_user: nil, ws_password: nil, api_key: nil, env: :live, adapter: nil, mock_port: 3001, live_url_prefix: nil, mock_service_url_base: nil)
|
11
13
|
@ws_user = ws_user
|
12
14
|
@ws_password = ws_password
|
13
15
|
@api_key = api_key
|
14
16
|
@env = env
|
15
17
|
@adapter = adapter || Faraday.default_adapter
|
16
|
-
@
|
18
|
+
@mock_service_url_base = mock_service_url_base || "http://localhost:#{mock_port}"
|
17
19
|
@live_url_prefix = live_url_prefix
|
18
20
|
end
|
19
21
|
|
@@ -35,7 +37,7 @@ module Adyen
|
|
35
37
|
def service_url_base(service)
|
36
38
|
raise ArgumentError, "Please set Client.live_url_prefix to the portion of your merchant-specific URL prior to '-[service]-live.adyenpayments.com'" if @live_url_prefix.nil? and @env == :live
|
37
39
|
if @env == :mock
|
38
|
-
|
40
|
+
@mock_service_url_base
|
39
41
|
else
|
40
42
|
case service
|
41
43
|
when "Checkout"
|
@@ -111,8 +113,6 @@ module Adyen
|
|
111
113
|
faraday.headers[key] = value
|
112
114
|
end
|
113
115
|
end
|
114
|
-
|
115
|
-
|
116
116
|
# if json string convert to hash
|
117
117
|
# needed to add applicationInfo
|
118
118
|
if request_data.is_a?(String)
|
@@ -144,7 +144,9 @@ module Adyen
|
|
144
144
|
raise Adyen::PermissionError.new("Missing user permissions; https://docs.adyen.com/user-management/user-roles", request_data)
|
145
145
|
end
|
146
146
|
|
147
|
-
response
|
147
|
+
formatted_response = AdyenResult.new(response.body, response.headers, response.status)
|
148
|
+
|
149
|
+
formatted_response
|
148
150
|
end
|
149
151
|
|
150
152
|
# add application_info for analytics
|
data/lib/adyen/result.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Adyen
|
4
|
+
class AdyenResult
|
5
|
+
attr_reader :response, :header, :status
|
6
|
+
|
7
|
+
def initialize(response, header, status)
|
8
|
+
@response = JSON.parse(response)
|
9
|
+
|
10
|
+
# `header` in Faraday response is not a JSON string, but rather a
|
11
|
+
# Faraday `Headers` object. Convert first before parsing
|
12
|
+
@header = JSON.parse(header.to_json)
|
13
|
+
@status = status
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/adyen/util.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This utility method monkey-patches Ruby's Hash class to allow keys to be read
|
2
|
+
# and updated with dot notation. Usage is entirely optional (i.e., hash values
|
3
|
+
# can still be accessed via symbol and string keys).
|
4
|
+
#
|
5
|
+
# Credit: https://gist.github.com/winfred/2185384#file-ruby-dot-hash-access-rb
|
6
|
+
|
7
|
+
class Hash
|
8
|
+
class NoKeyOrMethodError < NoMethodError; end
|
9
|
+
def method_missing(method,*args)
|
10
|
+
m = method.to_s
|
11
|
+
string_key = m.gsub(/=$/,'')
|
12
|
+
sym_key = string_key.to_sym
|
13
|
+
if self.has_key? string_key
|
14
|
+
m.match(/=$/) ? self.send("[#{string_key}]=", *args) : self[string_key]
|
15
|
+
elsif self.has_key? sym_key
|
16
|
+
m.match(/=$/) ? self.send("[#{sym_key}]=", *args) : self[sym_key]
|
17
|
+
else
|
18
|
+
raise NoKeyOrMethodError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/adyen/version.rb
CHANGED
data/spec/checkout_spec.rb
CHANGED
@@ -42,7 +42,10 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
|
|
42
42
|
to_return(
|
43
43
|
body: response_body
|
44
44
|
)
|
45
|
-
|
45
|
+
|
46
|
+
result = @shared_values[:client].checkout.payments.details(request_body)
|
47
|
+
# result.response is already a Ruby hash (rather than an unparsed JSON string)
|
48
|
+
response_hash = result.response
|
46
49
|
|
47
50
|
expect(request_body[:applicationInfo][:adyenLibrary][:name]).
|
48
51
|
to eq(Adyen::NAME)
|
@@ -50,13 +53,13 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
|
|
50
53
|
to eq(Adyen::VERSION)
|
51
54
|
expect(request_body[:applicationInfo][:adyenPaymentSource][:name]).
|
52
55
|
to eq("adyen-test")
|
53
|
-
expect(
|
56
|
+
expect(result.status).
|
54
57
|
to eq(200)
|
55
|
-
expect(
|
56
|
-
to eq(response_body)
|
57
|
-
expect(
|
58
|
+
expect(response_hash).
|
59
|
+
to eq(JSON.parse(response_body))
|
60
|
+
expect(response_hash.class).
|
58
61
|
to be Hash
|
59
|
-
expect(
|
62
|
+
expect(response_hash["resultCode"]).
|
60
63
|
to eq("RedirectShopper")
|
61
64
|
end
|
62
65
|
|
@@ -78,15 +81,17 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
|
|
78
81
|
to_return(
|
79
82
|
body: response_body
|
80
83
|
)
|
81
|
-
response = @shared_values[:client].checkout.payments.result(request_body)
|
82
84
|
|
83
|
-
|
85
|
+
result = @shared_values[:client].checkout.payments.result(request_body)
|
86
|
+
response_hash = result.response
|
87
|
+
|
88
|
+
expect(result.status).
|
84
89
|
to eq(200)
|
85
|
-
expect(
|
86
|
-
to eq(response_body)
|
87
|
-
expect(
|
90
|
+
expect(response_hash).
|
91
|
+
to eq(JSON.parse(response_body))
|
92
|
+
expect(response_hash.class).
|
88
93
|
to be Hash
|
89
|
-
expect(
|
94
|
+
expect(response_hash["resultCode"]).
|
90
95
|
to eq("Authorised")
|
91
96
|
end
|
92
97
|
|
data/spec/client_spec.rb
CHANGED
@@ -38,6 +38,24 @@ RSpec.describe Adyen do
|
|
38
38
|
@shared_values[:client].api_key = "api_key"
|
39
39
|
end
|
40
40
|
|
41
|
+
it "uses the specified mock service URL" do
|
42
|
+
client = Adyen::Client.new(env: :mock, mock_service_url_base: "https://mock.test")
|
43
|
+
expect(client.service_url_base("Account")).
|
44
|
+
to eq("https://mock.test")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "generates localhost service URL when a mock port is specified" do
|
48
|
+
client = Adyen::Client.new(env: :mock, mock_port: 3005)
|
49
|
+
expect(client.service_url_base("Account")).
|
50
|
+
to eq("http://localhost:3005")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "prefers the mock service URL when both mock service URL and port are specified" do
|
54
|
+
client = Adyen::Client.new(env: :mock, mock_port: 3005, mock_service_url_base: "https://this-url-wins.test")
|
55
|
+
expect(client.service_url_base("Account")).
|
56
|
+
to eq("https://this-url-wins.test")
|
57
|
+
end
|
58
|
+
|
41
59
|
it "generates the correct service URL base for CAL TEST" do
|
42
60
|
client = Adyen::Client.new(env: :test)
|
43
61
|
client.live_url_prefix = "abcdef1234567890-TestCompany"
|
data/spec/spec_helper.rb
CHANGED
@@ -48,18 +48,20 @@ def create_test(client, service, method_name, parent_object)
|
|
48
48
|
to_return(
|
49
49
|
body: response_body
|
50
50
|
)
|
51
|
-
|
51
|
+
result = parent_object.public_send(method_name, request_body)
|
52
|
+
|
53
|
+
# result.response is already a Ruby hash (rather than an unparsed JSON string)
|
54
|
+
response_hash = result.response
|
52
55
|
|
53
56
|
# boilerplate error checks
|
54
|
-
expect(
|
57
|
+
expect(result.status).
|
55
58
|
to eq(200)
|
56
|
-
expect(
|
57
|
-
to eq(response_body)
|
58
|
-
expect(
|
59
|
+
expect(response_hash).
|
60
|
+
to eq(JSON.parse(response_body))
|
61
|
+
expect(response_hash.class).
|
59
62
|
to be Hash
|
60
63
|
|
61
|
-
|
62
|
-
parsed_body
|
64
|
+
response_hash
|
63
65
|
end
|
64
66
|
|
65
67
|
# creates tests from an array of arrays
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adyen-ruby-api-library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -78,6 +78,7 @@ extra_rdoc_files: []
|
|
78
78
|
files:
|
79
79
|
- ".gitignore"
|
80
80
|
- ".travis.yml"
|
81
|
+
- CONTRIBUTING.md
|
81
82
|
- Gemfile
|
82
83
|
- LICENSE
|
83
84
|
- README.md
|
@@ -102,6 +103,7 @@ files:
|
|
102
103
|
- lib/adyen-ruby-api-library.rb
|
103
104
|
- lib/adyen/client.rb
|
104
105
|
- lib/adyen/errors.rb
|
106
|
+
- lib/adyen/result.rb
|
105
107
|
- lib/adyen/services/checkout.rb
|
106
108
|
- lib/adyen/services/checkout_utility.rb
|
107
109
|
- lib/adyen/services/marketpay.rb
|
@@ -109,6 +111,7 @@ files:
|
|
109
111
|
- lib/adyen/services/payouts.rb
|
110
112
|
- lib/adyen/services/recurring.rb
|
111
113
|
- lib/adyen/services/service.rb
|
114
|
+
- lib/adyen/util.rb
|
112
115
|
- lib/adyen/version.rb
|
113
116
|
- spec/account_spec.rb
|
114
117
|
- spec/checkout_spec.rb
|
@@ -242,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
245
|
version: '0'
|
243
246
|
requirements: []
|
244
247
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.
|
248
|
+
rubygems_version: 2.2.0
|
246
249
|
signing_key:
|
247
250
|
specification_version: 4
|
248
251
|
summary: Official Adyen Ruby API Library
|