adyen-ruby-api-library 4.0.1 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +7 -0
  6. data/.github/dependabot.yml +8 -0
  7. data/.gitignore +2 -0
  8. data/CODE_OF_CONDUCT.md +76 -0
  9. data/Gemfile +2 -2
  10. data/README.md +28 -2
  11. data/docs/checkout.html +17 -0
  12. data/lib/adyen-ruby-api-library.rb +4 -11
  13. data/lib/adyen/client.rb +30 -9
  14. data/lib/adyen/errors.rb +44 -2
  15. data/lib/adyen/services/bin_lookup.rb +18 -0
  16. data/lib/adyen/services/checkout.rb +12 -7
  17. data/lib/adyen/services/data_protection.rb +17 -0
  18. data/lib/adyen/services/dispute.rb +20 -0
  19. data/lib/adyen/services/marketpay.rb +18 -0
  20. data/lib/adyen/services/payments.rb +10 -4
  21. data/lib/adyen/services/postfmapi.rb +19 -0
  22. data/lib/adyen/services/service.rb +2 -2
  23. data/lib/adyen/version.rb +1 -1
  24. data/renovate.json +5 -0
  25. data/spec/bin_lookup_spec.rb +15 -0
  26. data/spec/checkout_spec.rb +1 -0
  27. data/spec/data_protection_spec.rb +14 -0
  28. data/spec/dispute_spec.rb +17 -0
  29. data/spec/errors_spec.rb +33 -3
  30. data/spec/hop_spec.rb +14 -0
  31. data/spec/mocks/requests/BinLookup/get_3ds_availability.json +4 -0
  32. data/spec/mocks/requests/BinLookup/get_cost_estimate.json +8 -0
  33. data/spec/mocks/requests/Checkout/payment_links.json +9 -0
  34. data/spec/mocks/requests/DataProtectionService/request_subject_erasure.json +5 -0
  35. data/spec/mocks/requests/DisputeService/defend_dispute.json +5 -0
  36. data/spec/mocks/requests/DisputeService/delete_dispute_defense_document.json +5 -0
  37. data/spec/mocks/requests/DisputeService/retrieve_applicable_defense_reasons.json +4 -0
  38. data/spec/mocks/requests/DisputeService/supply_defense_document.json +11 -0
  39. data/spec/mocks/requests/Hop/get_onboarding_url.json +4 -0
  40. data/spec/mocks/requests/Payment/donate.json +10 -0
  41. data/spec/mocks/requests/Terminal/assign_terminals.json +6 -0
  42. data/spec/mocks/requests/Terminal/find_terminal.json +3 -0
  43. data/spec/mocks/requests/Terminal/get_terminals_under_account.json +4 -0
  44. data/spec/mocks/responses/BinLookup/get_3ds_availability.json +8 -0
  45. data/spec/mocks/responses/BinLookup/get_cost_estimate.json +8 -0
  46. data/spec/mocks/responses/Checkout/payment_links.json +9 -0
  47. data/spec/mocks/responses/DataProtectionService/request_subject_erasure.json +3 -0
  48. data/spec/mocks/responses/DisputeService/defend_dispute.json +5 -0
  49. data/spec/mocks/responses/DisputeService/delete_dispute_defense_document.json +5 -0
  50. data/spec/mocks/responses/DisputeService/retrieve_applicable_defense_reasons.json +28 -0
  51. data/spec/mocks/responses/DisputeService/supply_defense_document.json +5 -0
  52. data/spec/mocks/responses/Hop/get_onboarding_url.json +7 -0
  53. data/spec/mocks/responses/Payment/donate.json +4 -0
  54. data/spec/mocks/responses/Terminal/assign_terminals.json +5 -0
  55. data/spec/mocks/responses/Terminal/find_terminal.json +6 -0
  56. data/spec/mocks/responses/Terminal/get_terminals_under_account.json +11 -0
  57. data/spec/payments_spec.rb +2 -1
  58. data/spec/postfmapi_spec.rb +16 -0
  59. data/spec/service_spec.rb +3 -0
  60. data/spec/spec_helper.rb +19 -12
  61. metadata +45 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 50ac4158ef06b200711ce1b69d7b6c12cad0df4b
4
- data.tar.gz: 338fbfd9fed83cd6a3569dd1f706fdf439e259c1
2
+ SHA256:
3
+ metadata.gz: e483ea1b71301634db57072423fd8cea1483b160eec7c1ba85fcf62ccbac0414
4
+ data.tar.gz: fa6dd93d1fe95ccf9ce3e9cc4a9956e523e6f25a20ae49fb2529e560c1aec14a
5
5
  SHA512:
6
- metadata.gz: c71dfcff2e34dd0244abdd56da08a0ab430b608de4fc095a472711a69269c416ffcee0b6021ed0db56bff3b8a5d1fc25e1fe13bac4f0c844367a61498ad6de1b
7
- data.tar.gz: 9ea5ee2a69f6de0523ba4fff25975202583bdf3d1218a8cda8d0abe978b57e30158cccd4bb94921c928531ce40442df067089cdb74a066567a4f2cd1f526bcf5
6
+ metadata.gz: 50f51f247bb68817b56ef596ad2b435280fedb1dc06806665a5e48b4c1cfb67fda4c1060f882929c0c40c8b225635cc19d36d6f90be4ae1e0e7149dc8f8638bd
7
+ data.tar.gz: 15273291ffb0122fab7050dc1263028c6a38d6634519c744057d1b3756b62461c028de7982d5c36adfb04e50f25a7d121541d1ef496a91c3c63bd67ee75c7829
@@ -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.
@@ -0,0 +1,7 @@
1
+ **Description**
2
+ <!-- Please provide a description of the changes proposed in the Pull Request -->
3
+
4
+ **Tested scenarios**
5
+ <!-- Description of tested scenarios -->
6
+
7
+ **Fixed issue**: <!-- #-prefixed issue number -->
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "04:00"
8
+ open-pull-requests-limit: 10
data/.gitignore CHANGED
@@ -11,3 +11,5 @@ design.txt
11
11
 
12
12
  .bundle
13
13
  .ruby-version
14
+
15
+ .DS_Store
@@ -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 "> 2.1.0"
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,10 @@ The Library supports all APIs under the following services:
13
13
  * payouts
14
14
  * recurring
15
15
  * marketpay
16
+ * postfmapi
17
+ * data_protection
18
+ * dispute
19
+ * bin_lookup
16
20
 
17
21
  ## Requirements
18
22
 
@@ -77,6 +81,7 @@ adyen.checkout.version = 50
77
81
  - payment_methods
78
82
  - payments
79
83
  - payments.details
84
+ - payment_links
80
85
 
81
86
  **checkout utility:**
82
87
  - origin_keys
@@ -91,6 +96,7 @@ adyen.checkout.version = 50
91
96
  - refund
92
97
  - cancel_or_refund
93
98
  - adjust_authorisation
99
+ - donate
94
100
 
95
101
  **payouts:**
96
102
  - confirm_third_party
@@ -136,9 +142,29 @@ adyen.checkout.version = 50
136
142
  - update_notification_configuration
137
143
  - delete_notification_configurations
138
144
 
139
- ## Support
145
+ **marketpay.hop:**
146
+ - get_onboarding_url
147
+
148
+ **postfmapi:**
149
+ - assign_terminals
150
+ - find_terminal
151
+ - get_terminals_under_account
152
+
153
+ **data_protection:**
154
+ - request_subject_erasure
140
155
 
141
- If you have any problems, questions or suggestions, create an issue here or send your inquiry to support@adyen.com.
156
+ **dispute:**
157
+ - retrieve_applicable_defense_reasons
158
+ - supply_defense_document
159
+ - delete_dispute_defense_document
160
+ - defend_dispute
161
+
162
+ **bin_lookup:**
163
+ - get_3ds_availability
164
+ - get_cost_estimate
165
+
166
+ ## Support
167
+ 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
168
 
143
169
  ## Contributing
144
170
  We strongly encourage you to join us in contributing to this repository so everyone can benefit from:
@@ -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 &mdash; Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
@@ -7,17 +7,10 @@ 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"
12
+ require_relative "adyen/services/data_protection"
13
+ require_relative "adyen/services/dispute"
14
+ require_relative "adyen/services/bin_lookup"
11
15
  require_relative "adyen/hash_with_accessors"
12
16
  require_relative "adyen/utils/hmac_validator"
13
-
14
- # add snake case to camel case converter to String
15
- # to convert rubinic method names to Adyen API methods
16
- #
17
- # i.e. snake_case -> snakeCase
18
- # note that the first letter is not capitalized as normal
19
- class String
20
- def to_camel_case
21
- split("_").collect.with_index{ |x, i| i > 0 ? x.capitalize : x }.join
22
- end
23
- end
@@ -45,12 +45,18 @@ module Adyen
45
45
  when "CheckoutUtility"
46
46
  url = "https://checkout-#{@env}.adyen.com/checkout"
47
47
  supports_live_url_prefix = true
48
- when "Account", "Fund", "Notification"
48
+ when "Account", "Fund", "Notification", "Hop"
49
49
  url = "https://cal-#{@env}.adyen.com/cal/services"
50
50
  supports_live_url_prefix = false
51
- when "Recurring", "Payment", "Payout"
51
+ when "Recurring", "Payment", "Payout", "BinLookup"
52
52
  url = "https://pal-#{@env}.adyen.com/pal/servlet"
53
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", "DisputeService"
58
+ url = "https://ca-#{@env}.adyen.com/ca/services"
59
+ supports_live_url_prefix = false
54
60
  else
55
61
  raise ArgumentError, "Invalid service specified"
56
62
  end
@@ -66,7 +72,7 @@ module Adyen
66
72
 
67
73
  # construct full URL from service and endpoint
68
74
  def service_url(service, action, version)
69
- if service == "Checkout" || service == "CheckoutUtility"
75
+ if service == "Checkout" || service == "CheckoutUtility" || service == "Terminal"
70
76
  "#{service_url_base(service)}/v#{version}/#{action}"
71
77
  else
72
78
  "#{service_url_base(service)}/#{service}/v#{version}/#{action}"
@@ -74,7 +80,7 @@ module Adyen
74
80
  end
75
81
 
76
82
  # send request to adyen API
77
- def call_adyen_api(service, action, request_data, headers, version)
83
+ def call_adyen_api(service, action, request_data, headers, version, with_application_info = false)
78
84
  # get URL for requested endpoint
79
85
  url = service_url(service, action, version)
80
86
 
@@ -119,7 +125,7 @@ module Adyen
119
125
  end
120
126
 
121
127
  # add application only on checkout service
122
- if service == 'Checkout' || service == 'CheckoutUtility'
128
+ if with_application_info
123
129
  add_application_info(request_data)
124
130
  end
125
131
 
@@ -151,16 +157,15 @@ module Adyen
151
157
  # add application_info for analytics
152
158
  def add_application_info(request_data)
153
159
  adyenLibrary = {
154
- :name => Adyen::NAME,
155
- :version => Adyen::VERSION.to_s
160
+ :name => Adyen::NAME,
161
+ :version => Adyen::VERSION.to_s,
156
162
  }
157
163
 
158
164
  if request_data[:applicationInfo].nil?
159
- request_data[:applicationInfo] = {};
165
+ request_data[:applicationInfo] = {}
160
166
  end
161
167
 
162
168
  request_data[:applicationInfo][:adyenLibrary] = adyenLibrary
163
- request_data[:applicationInfo][:adyenLibraryTest] = adyenLibrary
164
169
  end
165
170
 
166
171
  # services
@@ -187,5 +192,21 @@ module Adyen
187
192
  def marketpay
188
193
  @marketpay ||= Adyen::Marketpay::Marketpay.new(self)
189
194
  end
195
+
196
+ def postfmapi
197
+ @postfmapi ||= Adyen::PosTerminalManagement.new(self)
198
+ end
199
+
200
+ def data_protection
201
+ @data_protection ||= Adyen::DataProtection.new(self)
202
+ end
203
+
204
+ def dispute
205
+ @dispute ||= Adyen::Dispute.new(self)
206
+ end
207
+
208
+ def bin_lookup
209
+ @bin_lookup ||= Adyen::BinLookup.new(self)
210
+ end
190
211
  end
191
212
  end
@@ -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