adyen-ruby-api-library 4.0.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +7 -0
- data/.github/dependabot.yml +8 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +2 -2
- data/README.md +16 -2
- data/docs/checkout.html +17 -0
- data/lib/adyen-ruby-api-library.rb +4 -11
- data/lib/adyen/client.rb +16 -3
- data/lib/adyen/errors.rb +44 -2
- data/lib/adyen/hash_with_accessors.rb +38 -0
- data/lib/adyen/result.rb +2 -2
- data/lib/adyen/services/checkout.rb +2 -1
- data/lib/adyen/services/data_protection.rb +17 -0
- data/lib/adyen/services/marketpay.rb +18 -0
- data/lib/adyen/services/payments.rb +2 -1
- data/lib/adyen/services/postfmapi.rb +19 -0
- data/lib/adyen/services/service.rb +10 -1
- data/lib/adyen/utils/hmac_validator.rb +48 -0
- data/lib/adyen/version.rb +2 -2
- data/renovate.json +5 -0
- data/spec/checkout_spec.rb +13 -4
- data/spec/checkout_utility_spec.rb +4 -2
- data/spec/data_protection_spec.rb +14 -0
- data/spec/errors_spec.rb +33 -3
- data/spec/hash_with_accessors_spec.rb +127 -0
- data/spec/hop_spec.rb +14 -0
- data/spec/mocks/requests/Checkout/payment_links.json +9 -0
- data/spec/mocks/requests/DataProtectionService/request_subject_erasure.json +5 -0
- data/spec/mocks/requests/Hop/get_onboarding_url.json +4 -0
- data/spec/mocks/requests/Payment/donate.json +10 -0
- data/spec/mocks/requests/Terminal/assign_terminals.json +6 -0
- data/spec/mocks/requests/Terminal/find_terminal.json +3 -0
- data/spec/mocks/requests/Terminal/get_terminals_under_account.json +4 -0
- data/spec/mocks/responses/Checkout/payment_links.json +9 -0
- data/spec/mocks/responses/DataProtectionService/request_subject_erasure.json +3 -0
- data/spec/mocks/responses/Hop/get_onboarding_url.json +7 -0
- data/spec/mocks/responses/Payment/donate.json +4 -0
- data/spec/mocks/responses/Terminal/assign_terminals.json +5 -0
- data/spec/mocks/responses/Terminal/find_terminal.json +6 -0
- data/spec/mocks/responses/Terminal/get_terminals_under_account.json +11 -0
- data/spec/payments_spec.rb +2 -1
- data/spec/postfmapi_spec.rb +16 -0
- data/spec/service_spec.rb +45 -0
- data/spec/spec_helper.rb +7 -4
- data/spec/utils/hmac_validator_spec.rb +52 -0
- metadata +34 -5
- data/lib/adyen/util.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5d77315c126cb7ae2f8600f5bc8e853fd868a6bc6c30c36add08cfbe93285488
|
4
|
+
data.tar.gz: bf4c1f6498020da769aecba45b4fe6ce43f017ca71e083723b2bfa8903d3932e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd3c31163dae11854ef0d921ff772ddd3d5b526c2bef106a26edd150e2f517fd306cde43e7839313e134dd72f86eb6f0c37a2a19cb52efc169892e8849b9ceb0
|
7
|
+
data.tar.gz: c51e518693653f525a5dc06ee71d859614f5a741b4109ded91a29e9327c768c9b7c0c5f1783fdceeb740b1e6f95074bfc7f0336b7228eb1a3e66a34bd3730bd1
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @crrood @hbkwong @KadoBOT @Aleffio @rikterbeek
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**How to reproduce**
|
14
|
+
Steps to reproduce the behavior.
|
15
|
+
|
16
|
+
**Expected behavior**
|
17
|
+
A clear and concise description of what you expected to happen.
|
18
|
+
|
19
|
+
**Screenshots**
|
20
|
+
If applicable, add screenshots to help explain your problem.
|
21
|
+
|
22
|
+
**Desktop (please complete the following information):**
|
23
|
+
- ruby Version: [x.y.z]
|
24
|
+
- Library Version: [x.y.z]
|
25
|
+
|
26
|
+
**Additional context**
|
27
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**ruby version**: x.y.z
|
11
|
+
**Library version**: x.y.z
|
12
|
+
|
13
|
+
**Is your feature request related to a problem? Please describe.**
|
14
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
15
|
+
|
16
|
+
**Describe the solution you'd like**
|
17
|
+
A clear and concise description of what you want to happen.
|
18
|
+
|
19
|
+
**Describe alternatives you've considered**
|
20
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
21
|
+
|
22
|
+
**Additional context**
|
23
|
+
Add any other context or screenshots about the feature request here.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at support@adyen.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
data/Gemfile
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
ruby "
|
5
|
+
ruby ">= 2.1.0"
|
6
6
|
|
7
7
|
gem "faraday"
|
8
8
|
|
9
9
|
gem "bundler", :group => :development
|
10
10
|
gem "webmock", :group => :development
|
11
11
|
gem "rspec", :group => :development
|
12
|
-
gem "activesupport", :group => :development
|
12
|
+
gem "activesupport", :group => :development
|
data/README.md
CHANGED
@@ -13,6 +13,8 @@ The Library supports all APIs under the following services:
|
|
13
13
|
* payouts
|
14
14
|
* recurring
|
15
15
|
* marketpay
|
16
|
+
* postfmapi
|
17
|
+
* data_protection
|
16
18
|
|
17
19
|
## Requirements
|
18
20
|
|
@@ -77,6 +79,7 @@ adyen.checkout.version = 50
|
|
77
79
|
- payment_methods
|
78
80
|
- payments
|
79
81
|
- payments.details
|
82
|
+
- payment_links
|
80
83
|
|
81
84
|
**checkout utility:**
|
82
85
|
- origin_keys
|
@@ -91,6 +94,7 @@ adyen.checkout.version = 50
|
|
91
94
|
- refund
|
92
95
|
- cancel_or_refund
|
93
96
|
- adjust_authorisation
|
97
|
+
- donate
|
94
98
|
|
95
99
|
**payouts:**
|
96
100
|
- confirm_third_party
|
@@ -136,9 +140,19 @@ adyen.checkout.version = 50
|
|
136
140
|
- update_notification_configuration
|
137
141
|
- delete_notification_configurations
|
138
142
|
|
139
|
-
|
143
|
+
**marketpay.hop:**
|
144
|
+
- get_onboarding_url
|
145
|
+
|
146
|
+
**postfmapi:**
|
147
|
+
- assign_terminals
|
148
|
+
- find_terminal
|
149
|
+
- get_terminals_under_account
|
140
150
|
|
141
|
-
|
151
|
+
**data_protection:**
|
152
|
+
- request_subject_erasure
|
153
|
+
|
154
|
+
## Support
|
155
|
+
If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our [support team](https://support.adyen.com/hc/en-us/requests/new?ticket_form_id=360000705420).
|
142
156
|
|
143
157
|
## Contributing
|
144
158
|
We strongly encourage you to join us in contributing to this repository so everyone can benefit from:
|
data/docs/checkout.html
CHANGED
@@ -41,6 +41,8 @@
|
|
41
41
|
<li>payments</li>
|
42
42
|
|
43
43
|
<li>payments.details</li>
|
44
|
+
|
45
|
+
<li>payment_links</li>
|
44
46
|
</ul>
|
45
47
|
|
46
48
|
<h2 id="authentication">Authentication</h2>
|
@@ -99,7 +101,22 @@
|
|
99
101
|
|
100
102
|
<p>A successful call to payment_methods will return a list of supported payment methods along with redirect URL's so that you can send your shoppers directly to the issuer's site without losing control of front-end styling / logic.</p>
|
101
103
|
|
104
|
+
You can also create a link to Adyen's hosted payment form:
|
105
|
+
|
106
|
+
<pre><code class="ruby language-ruby">response = adyen.checkout.payment_links('{
|
107
|
+
"amount": {
|
108
|
+
"value": 1500,
|
109
|
+
"currency": "EUR"
|
110
|
+
},
|
111
|
+
"countryCode": "US",
|
112
|
+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
|
113
|
+
"reference": "YOUR_REFERENCE"
|
114
|
+
}')</code></pre>
|
115
|
+
|
116
|
+
<p>A successful call to payment_links will return a url, which directs a user to Adyen's hosted payment form.</p>
|
102
117
|
</section>
|
118
|
+
|
119
|
+
|
103
120
|
<footer>
|
104
121
|
<p>This project is maintained by <a href="https://github.com/Adyen">Adyen</a></p>
|
105
122
|
<p><small>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
|
@@ -7,15 +7,8 @@ require_relative "adyen/services/payments"
|
|
7
7
|
require_relative "adyen/services/payouts"
|
8
8
|
require_relative "adyen/services/recurring"
|
9
9
|
require_relative "adyen/services/marketpay"
|
10
|
+
require_relative "adyen/services/postfmapi"
|
10
11
|
require_relative "adyen/services/service"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
# i.e. snake_case -> snakeCase
|
16
|
-
# note that the first letter is not capitalized as normal
|
17
|
-
class String
|
18
|
-
def to_camel_case
|
19
|
-
split("_").collect.with_index{ |x, i| i > 0 ? x.capitalize : x }.join
|
20
|
-
end
|
21
|
-
end
|
12
|
+
require_relative "adyen/services/data_protection"
|
13
|
+
require_relative "adyen/hash_with_accessors"
|
14
|
+
require_relative "adyen/utils/hmac_validator"
|
data/lib/adyen/client.rb
CHANGED
@@ -2,7 +2,6 @@ require "faraday"
|
|
2
2
|
require "json"
|
3
3
|
require_relative "./errors"
|
4
4
|
require_relative "./result"
|
5
|
-
require_relative "./util"
|
6
5
|
|
7
6
|
module Adyen
|
8
7
|
class Client
|
@@ -46,12 +45,18 @@ module Adyen
|
|
46
45
|
when "CheckoutUtility"
|
47
46
|
url = "https://checkout-#{@env}.adyen.com/checkout"
|
48
47
|
supports_live_url_prefix = true
|
49
|
-
when "Account", "Fund", "Notification"
|
48
|
+
when "Account", "Fund", "Notification", "Hop"
|
50
49
|
url = "https://cal-#{@env}.adyen.com/cal/services"
|
51
50
|
supports_live_url_prefix = false
|
52
51
|
when "Recurring", "Payment", "Payout"
|
53
52
|
url = "https://pal-#{@env}.adyen.com/pal/servlet"
|
54
53
|
supports_live_url_prefix = true
|
54
|
+
when "Terminal"
|
55
|
+
url = "https://postfmapi-#{@env}.adyen.com/postfmapi/terminal"
|
56
|
+
supports_live_url_prefix = false
|
57
|
+
when "DataProtectionService"
|
58
|
+
url = "https://ca-#{@env}.adyen.com/ca/services"
|
59
|
+
supports_live_url_prefix = false
|
55
60
|
else
|
56
61
|
raise ArgumentError, "Invalid service specified"
|
57
62
|
end
|
@@ -67,7 +72,7 @@ module Adyen
|
|
67
72
|
|
68
73
|
# construct full URL from service and endpoint
|
69
74
|
def service_url(service, action, version)
|
70
|
-
if service == "Checkout" || service == "CheckoutUtility"
|
75
|
+
if service == "Checkout" || service == "CheckoutUtility" || service == "Terminal"
|
71
76
|
"#{service_url_base(service)}/v#{version}/#{action}"
|
72
77
|
else
|
73
78
|
"#{service_url_base(service)}/#{service}/v#{version}/#{action}"
|
@@ -188,5 +193,13 @@ module Adyen
|
|
188
193
|
def marketpay
|
189
194
|
@marketpay ||= Adyen::Marketpay::Marketpay.new(self)
|
190
195
|
end
|
196
|
+
|
197
|
+
def postfmapi
|
198
|
+
@postfmapi ||= Adyen::PosTerminalManagement.new(self)
|
199
|
+
end
|
200
|
+
|
201
|
+
def data_protection
|
202
|
+
@data_protection ||= Adyen::DataProtection.new(self)
|
203
|
+
end
|
191
204
|
end
|
192
205
|
end
|
data/lib/adyen/errors.rb
CHANGED
@@ -3,19 +3,61 @@ module Adyen
|
|
3
3
|
attr_reader :code, :response, :request, :msg
|
4
4
|
|
5
5
|
def initialize(request = nil, response = nil, msg = nil, code = nil)
|
6
|
+
mask_fields(request)
|
7
|
+
|
8
|
+
# components of formatted error message
|
6
9
|
attributes = {
|
7
10
|
code: code,
|
11
|
+
msg: msg,
|
8
12
|
request: request,
|
9
|
-
response: response
|
10
|
-
msg: msg
|
13
|
+
response: response
|
11
14
|
}.select { |_k, v| v }.map { |k, v| "#{k}:#{v}" }.join(', ')
|
12
15
|
message = "#{self.class.name} #{attributes}"
|
13
16
|
super(message)
|
17
|
+
|
18
|
+
# internal variables
|
14
19
|
@code = code
|
15
20
|
@response = response
|
16
21
|
@request = request
|
17
22
|
@msg = msg
|
18
23
|
end
|
24
|
+
|
25
|
+
# mask PCI data in request
|
26
|
+
def mask_fields(request)
|
27
|
+
return if request.nil?
|
28
|
+
|
29
|
+
# sensitive fields
|
30
|
+
fields_to_mask = [
|
31
|
+
:expiryMonth,
|
32
|
+
:expiryYear,
|
33
|
+
:encryptedCardNumber,
|
34
|
+
:encryptedExpiryMonth,
|
35
|
+
:encryptedExpiryYear,
|
36
|
+
:encryptedSecurityCode
|
37
|
+
]
|
38
|
+
|
39
|
+
# convert to hash if necessary
|
40
|
+
request = request.is_a?(Hash) ? request : JSON.parse(request)
|
41
|
+
|
42
|
+
# iterate through request to find fields to mask
|
43
|
+
request.each do |k, v|
|
44
|
+
if request[k].is_a?(Hash)
|
45
|
+
# recursively traverse multi-level hashes
|
46
|
+
mask_fields(request[k])
|
47
|
+
else
|
48
|
+
if k == :number
|
49
|
+
# show first 6 and last 4 for cards
|
50
|
+
request[k] = "#{v[0,6]}******#{v[12,16]}"
|
51
|
+
elsif k == :cvc
|
52
|
+
# show length of cvc for debugging
|
53
|
+
request[k] = "*" * v.length
|
54
|
+
elsif fields_to_mask.include? k
|
55
|
+
# generic mask for other fields
|
56
|
+
request[k] = "***"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
19
61
|
end
|
20
62
|
|
21
63
|
class AuthenticationError < AdyenError
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# This utility method inherits from Hash, but allows 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
|
+
# Based on: https://gist.github.com/winfred/2185384#file-ruby-dot-hash-access-rb
|
6
|
+
module Adyen
|
7
|
+
class HashWithAccessors < Hash
|
8
|
+
def method_missing(method, *args)
|
9
|
+
string_key = method.to_s.sub(/=\z/, '')
|
10
|
+
sym_key = string_key.to_sym
|
11
|
+
|
12
|
+
key = if has_key?(string_key)
|
13
|
+
string_key
|
14
|
+
elsif has_key?(sym_key)
|
15
|
+
sym_key
|
16
|
+
end
|
17
|
+
|
18
|
+
return super unless key
|
19
|
+
|
20
|
+
assignment = sym_key != method
|
21
|
+
|
22
|
+
if assignment
|
23
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 1)" unless args.size == 1
|
24
|
+
|
25
|
+
self[key] = args.first
|
26
|
+
else
|
27
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)" unless args.size == 0
|
28
|
+
|
29
|
+
self[key]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def respond_to_missing?(method, include_private = false)
|
34
|
+
string_key = method.to_s.sub(/=\z/, '')
|
35
|
+
has_key?(string_key) || has_key?(string_key.to_sym) || super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/adyen/result.rb
CHANGED
@@ -5,11 +5,11 @@ module Adyen
|
|
5
5
|
attr_reader :response, :header, :status
|
6
6
|
|
7
7
|
def initialize(response, header, status)
|
8
|
-
@response = JSON.parse(response)
|
8
|
+
@response = JSON.parse(response, object_class: HashWithAccessors)
|
9
9
|
|
10
10
|
# `header` in Faraday response is not a JSON string, but rather a
|
11
11
|
# Faraday `Headers` object. Convert first before parsing
|
12
|
-
@header = JSON.parse(header.to_json)
|
12
|
+
@header = JSON.parse(header.to_json, object_class: HashWithAccessors)
|
13
13
|
@status = status
|
14
14
|
end
|
15
15
|
end
|