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
@@ -0,0 +1,18 @@
1
+ require_relative 'service'
2
+
3
+ module Adyen
4
+ class BinLookup < Service
5
+ attr_accessor :version
6
+ DEFAULT_VERSION = 50
7
+
8
+ def initialize(client, version = DEFAULT_VERSION)
9
+ service = 'BinLookup'
10
+ method_names = [
11
+ :get_3ds_availability,
12
+ :get_cost_estimate
13
+ ]
14
+
15
+ super(client, version, service, method_names)
16
+ end
17
+ end
18
+ end
@@ -1,17 +1,22 @@
1
- require_relative 'service'
1
+ require_relative "service"
2
2
 
3
3
  module Adyen
4
4
  class Checkout < Service
5
5
  DEFAULT_VERSION = 50
6
6
 
7
7
  def initialize(client, version = DEFAULT_VERSION)
8
- service = 'Checkout'
8
+ service = "Checkout"
9
9
  method_names = [
10
10
  :payment_methods,
11
- :payment_session
11
+ :payment_session,
12
+ :payment_links,
13
+ ]
14
+ with_application_info = [
15
+ :payment_session,
16
+ :payment_links,
12
17
  ]
13
18
 
14
- super(client, version, service, method_names)
19
+ super(client, version, service, method_names, with_application_info)
15
20
  end
16
21
 
17
22
  # This method can't be dynamically defined because
@@ -24,16 +29,16 @@ module Adyen
24
29
  when 0
25
30
  Adyen::CheckoutDetail.new(@client, @version)
26
31
  else
27
- action = 'payments'
32
+ action = "payments"
28
33
  args[1] ||= {} # optional headers arg
29
- @client.call_adyen_api(@service, action, args[0], args[1], @version)
34
+ @client.call_adyen_api(@service, action, args[0], args[1], @version, true)
30
35
  end
31
36
  end
32
37
  end
33
38
 
34
39
  class CheckoutDetail < Service
35
40
  def initialize(client, version = DEFAULT_VERSION)
36
- @service = 'Checkout'
41
+ @service = "Checkout"
37
42
  @client = client
38
43
  @version = version
39
44
  end
@@ -0,0 +1,17 @@
1
+ require_relative 'service'
2
+
3
+ module Adyen
4
+ class DataProtection < Service
5
+ attr_accessor :version
6
+ DEFAULT_VERSION = 1
7
+
8
+ def initialize(client, version = DEFAULT_VERSION)
9
+ service = 'DataProtectionService'
10
+ method_names = [
11
+ :request_subject_erasure
12
+ ]
13
+
14
+ super(client, version, service, method_names)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'service'
2
+
3
+ module Adyen
4
+ class Dispute < Service
5
+ attr_accessor :version
6
+ DEFAULT_VERSION = 30
7
+
8
+ def initialize(client, version = DEFAULT_VERSION)
9
+ service = 'DisputeService'
10
+ method_names = [
11
+ :retrieve_applicable_defense_reasons,
12
+ :supply_defense_document,
13
+ :delete_dispute_defense_document,
14
+ :defend_dispute,
15
+ ]
16
+
17
+ super(client, version, service, method_names)
18
+ end
19
+ end
20
+ end
@@ -21,6 +21,10 @@ module Adyen
21
21
  def notification
22
22
  @notification ||= Adyen::Marketpay::Notification.new(@client)
23
23
  end
24
+
25
+ def hop
26
+ @hop ||= Adyen::Marketpay::Hop.new(@client)
27
+ end
24
28
  end
25
29
 
26
30
  class Account < Service
@@ -88,5 +92,19 @@ module Adyen
88
92
  super(client, version, service, method_names)
89
93
  end
90
94
  end
95
+
96
+ class Hop < Service
97
+ attr_accessor :version
98
+ DEFAULT_VERSION = 1
99
+
100
+ def initialize(client, version = DEFAULT_VERSION)
101
+ service = 'Hop'
102
+ method_names = [
103
+ :get_onboarding_url
104
+ ]
105
+
106
+ super(client, version, service, method_names)
107
+ end
108
+ end
91
109
  end
92
110
  end
@@ -1,4 +1,4 @@
1
- require_relative 'service'
1
+ require_relative "service"
2
2
 
3
3
  module Adyen
4
4
  class Payments < Service
@@ -6,7 +6,7 @@ module Adyen
6
6
  DEFAULT_VERSION = 50
7
7
 
8
8
  def initialize(client, version = DEFAULT_VERSION)
9
- service = 'Payment'
9
+ service = "Payment"
10
10
  method_names = [
11
11
  :authorise,
12
12
  :authorise3d,
@@ -15,10 +15,16 @@ module Adyen
15
15
  :cancel,
16
16
  :refund,
17
17
  :cancel_or_refund,
18
- :adjust_authorisation
18
+ :adjust_authorisation,
19
+ :donate,
20
+ ]
21
+ with_application_info = [
22
+ :authorise,
23
+ :authorise3d,
24
+ :authorise3ds2,
19
25
  ]
20
26
 
21
- super(client, version, service, method_names)
27
+ super(client, version, service, method_names, with_application_info)
22
28
  end
23
29
  end
24
30
  end
@@ -0,0 +1,19 @@
1
+ require_relative 'service'
2
+
3
+ module Adyen
4
+ class PosTerminalManagement < Service
5
+ attr_accessor :version
6
+ DEFAULT_VERSION = 1
7
+
8
+ def initialize(client, version = DEFAULT_VERSION)
9
+ service = 'Terminal'
10
+ method_names = [
11
+ :assign_terminals,
12
+ :find_terminal,
13
+ :get_terminals_under_account
14
+ ]
15
+
16
+ super(client, version, service, method_names)
17
+ end
18
+ end
19
+ end
@@ -11,7 +11,7 @@ module Adyen
11
11
  method_name.to_s.gsub(/_./) { |x| x[1].upcase }
12
12
  end
13
13
 
14
- def initialize(client, version, service, method_names)
14
+ def initialize(client, version, service, method_names, with_application_info = [])
15
15
  @client = client
16
16
  @version = version
17
17
  @service = service
@@ -20,7 +20,7 @@ module Adyen
20
20
  method_names.each do |method_name|
21
21
  define_singleton_method method_name do |request, headers = {}|
22
22
  action = self.class.action_for_method_name(method_name)
23
- @client.call_adyen_api(@service, action, request, headers, @version)
23
+ @client.call_adyen_api(@service, action, request, headers, @version, with_application_info.include?(method_name))
24
24
  end
25
25
  end
26
26
  end
@@ -1,4 +1,4 @@
1
1
  module Adyen
2
2
  NAME = "adyen-ruby-api-library"
3
- VERSION = "4.0.1".freeze
3
+ VERSION = "4.4.0".freeze
4
4
  end
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "config:base"
4
+ ]
5
+ }
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Adyen::BinLookup, service: "BIN lookup service" do
4
+ # client instance to be used in dynamically generated tests
5
+ client = create_client(:basic)
6
+
7
+ # methods / values to test for
8
+ # format is defined in spec_helper
9
+ test_sets = [
10
+ ["get_3ds_availability", "threeDS2supported", false],
11
+ ["get_cost_estimate", "resultCode", "Success"]
12
+ ]
13
+
14
+ generate_tests(client, "BinLookup", test_sets, client.bin_lookup)
15
+ end
@@ -110,6 +110,7 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
110
110
  # format is defined in spec_helper
111
111
  test_sets = [
112
112
  ["payment_session", "publicKeyToken", "8115054323780109"],
113
+ ["payment_links", "url", "https://checkoutshopper-test.adyen.com"],
113
114
  ["payments", "resultCode", "Authorised"]
114
115
  ]
115
116
 
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Adyen::DataProtection, service: "Data Protection Service" do
4
+ # client instance to be used in dynamically generated tests
5
+ client = create_client(:basic)
6
+
7
+ # methods / values to test for
8
+ # format is defined in spec_helper
9
+ test_sets = [
10
+ ["request_subject_erasure", "result", "SUCCESS"],
11
+ ]
12
+
13
+ generate_tests(client, "DataProtectionService", test_sets, client.data_protection)
14
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Adyen::Dispute, service: "dispute service" do
4
+ # client instance to be used in dynamically generated tests
5
+ client = create_client(:basic)
6
+
7
+ # methods / values to test for
8
+ # format is defined in spec_helper
9
+ test_sets = [
10
+ ["retrieve_applicable_defense_reasons", "disputeServiceResult", { "success" => true }],
11
+ ["supply_defense_document", "disputeServiceResult", { "success" => true }],
12
+ ["delete_dispute_defense_document", "disputeServiceResult", { "success" => true }],
13
+ ["defend_dispute", "disputeServiceResult", { "success" => true }],
14
+ ]
15
+
16
+ generate_tests(client, "DisputeService", test_sets, client.dispute)
17
+ end
@@ -3,15 +3,45 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Adyen::AdyenError do
6
+ before(:all) do
7
+ @shared_values = {
8
+ request: {
9
+ amount: {
10
+ currency: "USD",
11
+ value: 1000
12
+ },
13
+ reference: "Your order number",
14
+ paymentMethod: {
15
+ type: "scheme",
16
+ number: "4111111111111111",
17
+ expiryMonth: "10",
18
+ expiryYear: "2020",
19
+ holderName: "John Smith",
20
+ cvc: "737"
21
+ },
22
+ returnUrl: "https://your-company.com/",
23
+ merchantAccount: "YOUR_MERCHANT_ACCOUNT"
24
+ }
25
+ }
26
+ end
27
+
6
28
  describe '#to_s' do
7
29
  it 'describes using the error properties' do
8
- expect(Adyen::AdyenError.new('request', 'response', 'message', 'code').to_s).to eq('Adyen::AdyenError code:code, request:request, response:response, msg:message')
30
+ expect(Adyen::AdyenError.new(@shared_values[:request], 'response', 'message', 'code').to_s).to eq("Adyen::AdyenError code:code, msg:message, request:#{@shared_values[:request]}, response:response")
9
31
  end
10
32
  it 'skips the null properties' do
11
- expect(Adyen::AdyenError.new('request', nil, nil, 'code').to_s).to eq('Adyen::AdyenError code:code, request:request')
33
+ expect(Adyen::AdyenError.new(@shared_values[:request], nil, nil, 'code').to_s).to eq("Adyen::AdyenError code:code, request:#{@shared_values[:request]}")
12
34
  end
13
35
  it 'uses the proper error class name' do
14
- expect(Adyen::PermissionError.new('a message', 'a request').to_s).to eq('Adyen::PermissionError code:403, request:a request, msg:a message')
36
+ expect(Adyen::PermissionError.new('message', @shared_values[:request]).to_s).to eq("Adyen::PermissionError code:403, msg:message, request:#{@shared_values[:request]}")
37
+ end
38
+ end
39
+ describe '#masking' do
40
+ it 'masks card number when logging request in errors' do
41
+ expect(Adyen::AdyenError.new(@shared_values[:request], 'response', 'message', 'code').request[:paymentMethod][:number]).to eq('411111******1111')
42
+ end
43
+ it 'masks CVC when logging request in errors' do
44
+ expect(Adyen::AdyenError.new(@shared_values[:request], 'response', 'message', 'code').request[:paymentMethod][:cvc]).to eq('***')
15
45
  end
16
46
  end
17
47
  end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Adyen::Payments, service: "marketpay hop service" do
4
+ # client instance to be used in dynamically generated tests
5
+ client = create_client(:basic)
6
+
7
+ # methods / values to test for
8
+ # format is defined in spec_helper
9
+ test_sets = [
10
+ ["get_onboarding_url", "pspReference", "8815850625171183"]
11
+ ]
12
+
13
+ generate_tests(client, "Hop", test_sets, client.marketpay.hop)
14
+ end
@@ -0,0 +1,4 @@
1
+ {
2
+ "merchantAccount": "TestMerchant",
3
+ "cardNumber": "4111111111111111"
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "amount": {
3
+ "currency": "EUR",
4
+ "value": 1000
5
+ },
6
+ "cardNumber": "5101180000000007",
7
+ "merchantAccount": "TestMerchant"
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "amount": {
3
+ "currency": "USD",
4
+ "value": 1000
5
+ },
6
+ "countryCode": "US",
7
+ "merchantAccount": "TestMerchant",
8
+ "reference": "Merchant Reference"
9
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "merchantAccount": "test_merchant",
3
+ "pspReference": "test_reference",
4
+ "forceErasure": true
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "disputePspReference": "9913486733050065",
3
+ "defenseReasonCode": "SupplyDefenseMaterial",
4
+ "merchantAccountCode": "YOUR_MERCHANT_ACCOUNT"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "disputePspReference": "9913486733050065",
3
+ "merchantAccountCode": "YOUR_MERCHANT_ACCOUNT",
4
+ "defenseDocumentType": "MerchandiseDescription"
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "merchantAccount": "YOUR_MERCHANT_ACCOUNT",
3
+ "disputePspReference": "9913486733050065"
4
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "defenseDocuments": [
3
+ {
4
+ "content": "JVBERi0xLjMKJcTl8uXrp...",
5
+ "contentType": "application/pdf",
6
+ "defenseDocumentTypeCode": "MerchandiseDescription"
7
+ }
8
+ ],
9
+ "disputePspReference": "9913486733050065",
10
+ "merchantAccountCode": "YOUR_MERCHANT_ACCOUNT"
11
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "accountHolderCode": "YourUniqueAccountHolderCode",
3
+ "returnUrl": "https://your.return-url.com/?submerchant=123"
4
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "originalReference": "882594077439995E",
3
+ "modificationAmount": {
4
+ "value": 100,
5
+ "currency": "USD"
6
+ },
7
+ "reference": "Donation",
8
+ "donationAccount": "TestMerchantDonations",
9
+ "merchantAccount": "TestMerchant"
10
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "companyAccount": "TestCompany",
3
+ "merchantAccount": "TestMerchant",
4
+ "merchantInventory": false,
5
+ "terminals": ["e285-123456789"]
6
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "terminal": "e285-123456789"
3
+ }