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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: b38d6b5e903949dd5f611270b52d7d232b7446053e4af782809ec0ee80c2072c
4
- data.tar.gz: ddb1fa60f2b6dd3d1b177c651ae59372d8065a13193f7b2ef1cbe5c3744b0312
2
+ SHA1:
3
+ metadata.gz: 57203cec793176b8f389062f66cf734dcc43e183
4
+ data.tar.gz: 6680ea0897e40cad89569ed46c841dcf45b900a4
5
5
  SHA512:
6
- metadata.gz: be7130f49c9247fd8f8edb0c0ff8f11d6ed95ac19e1ffc3b15db0d9e758c092ed1850d22c64b1ec17c9b4f63fa22a0149fd3ba9dca4d5b6b7a56baca5c6b98f4
7
- data.tar.gz: 9bb005f7548edea11ba546ee08ed045a7ecd743c1691a25aaa9c38b5940a29fbd9d8454cc894553920f20f0f4cf2174dc7e3c4fbe53c2bdf2bc606d1c5a720af
6
+ metadata.gz: 16075771ada5ca4afb71c798e7823fcd1c2b162a6d0d21919b0a3ea8db301ec5379525c726ebc3d71b0b39d87ada719b539b7457fe927a5aa6ef4754b7dca3be
7
+ data.tar.gz: 968d9f0cb9a426ce89d8bc17a00cdf50766f1f48dacbb58a1966e3d29ae5fe99a3e784e6d0f40fa86f4f0ef5bfad27576124ad1504746e121af9998abd06f8a1
@@ -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 = 49
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.
@@ -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
- @mock_port = mock_port
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
- "http://localhost:#{@mock_port}"
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
@@ -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
@@ -2,7 +2,7 @@ require_relative 'service'
2
2
 
3
3
  module Adyen
4
4
  class Checkout < Service
5
- DEFAULT_VERSION = 49
5
+ DEFAULT_VERSION = 50
6
6
 
7
7
  def initialize(client, version = DEFAULT_VERSION)
8
8
  service = 'Checkout'
@@ -3,7 +3,7 @@ require_relative 'service'
3
3
  module Adyen
4
4
  class Payments < Service
5
5
  attr_accessor :version
6
- DEFAULT_VERSION = 49
6
+ DEFAULT_VERSION = 50
7
7
 
8
8
  def initialize(client, version = DEFAULT_VERSION)
9
9
  service = 'Payment'
@@ -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
@@ -1,4 +1,4 @@
1
- module Adyen
1
+ module Adyen
2
2
  NAME = "adyen-ruby-api-library"
3
- VERSION = "3.0.2".freeze
3
+ VERSION = "4.0.0".freeze
4
4
  end
@@ -42,7 +42,10 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
42
42
  to_return(
43
43
  body: response_body
44
44
  )
45
- response = @shared_values[:client].checkout.payments.details(request_body)
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(response.status).
56
+ expect(result.status).
54
57
  to eq(200)
55
- expect(response.body).
56
- to eq(response_body)
57
- expect((parsed_body = JSON.parse(response.body)).class).
58
+ expect(response_hash).
59
+ to eq(JSON.parse(response_body))
60
+ expect(response_hash.class).
58
61
  to be Hash
59
- expect(parsed_body["resultCode"]).
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
- expect(response.status).
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(response.body).
86
- to eq(response_body)
87
- expect((parsed_body = JSON.parse(response.body)).class).
90
+ expect(response_hash).
91
+ to eq(JSON.parse(response_body))
92
+ expect(response_hash.class).
88
93
  to be Hash
89
- expect(parsed_body["resultCode"]).
94
+ expect(response_hash["resultCode"]).
90
95
  to eq("Authorised")
91
96
  end
92
97
 
@@ -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"
@@ -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
- response = parent_object.public_send(method_name, request_body)
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(response.status).
57
+ expect(result.status).
55
58
  to eq(200)
56
- expect(response.body).
57
- to eq(response_body)
58
- expect((parsed_body = JSON.parse(response.body)).class).
59
+ expect(response_hash).
60
+ to eq(JSON.parse(response_body))
61
+ expect(response_hash.class).
59
62
  to be Hash
60
63
 
61
- # return hash of response
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: 3.0.2
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-07 00:00:00.000000000 Z
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.7.8
248
+ rubygems_version: 2.2.0
246
249
  signing_key:
247
250
  specification_version: 4
248
251
  summary: Official Adyen Ruby API Library