adyen-ruby-api-library 4.1.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -1
- 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/.gitignore +2 -0
- data/README.md +72 -119
- data/docs/marketpay.html +2 -0
- data/lib/adyen-ruby-api-library.rb +3 -12
- data/lib/adyen/client.rb +49 -23
- data/lib/adyen/services/bin_lookup.rb +18 -0
- data/lib/adyen/services/checkout.rb +88 -8
- data/lib/adyen/services/{checkout_utility.rb → data_protection.rb} +4 -3
- data/lib/adyen/services/dispute.rb +20 -0
- data/lib/adyen/services/marketpay.rb +10 -7
- data/lib/adyen/services/payments.rb +15 -5
- data/lib/adyen/services/payouts.rb +3 -2
- data/lib/adyen/services/recurring.rb +3 -2
- data/lib/adyen/services/service.rb +2 -2
- data/lib/adyen/version.rb +1 -1
- data/spec/account_spec.rb +4 -1
- data/spec/bin_lookup_spec.rb +15 -0
- data/spec/checkout_spec.rb +247 -5
- data/spec/data_protection_spec.rb +14 -0
- data/spec/dispute_spec.rb +17 -0
- data/spec/fund_spec.rb +2 -1
- data/spec/mocks/requests/Account/check_account_holder.json +5 -0
- data/spec/mocks/requests/Account/delete_payout_methods.json +6 -0
- data/spec/mocks/requests/Account/delete_signatories.json +6 -0
- data/spec/mocks/requests/BinLookup/get_3ds_availability.json +4 -0
- data/spec/mocks/requests/BinLookup/get_cost_estimate.json +8 -0
- data/spec/mocks/requests/Checkout/orders.json +6 -0
- data/spec/mocks/requests/Checkout/orders_cancel.json +7 -0
- data/spec/mocks/requests/Checkout/origin_keys.json +3 -0
- data/spec/mocks/requests/Checkout/payment_methods_balance.json +9 -0
- data/spec/mocks/requests/DataProtectionService/request_subject_erasure.json +5 -0
- data/spec/mocks/requests/DisputeService/defend_dispute.json +5 -0
- data/spec/mocks/requests/DisputeService/delete_dispute_defense_document.json +5 -0
- data/spec/mocks/requests/DisputeService/retrieve_applicable_defense_reasons.json +4 -0
- data/spec/mocks/requests/DisputeService/supply_defense_document.json +11 -0
- data/spec/mocks/requests/Fund/refund_funds_transfer.json +7 -0
- data/spec/mocks/requests/Payment/donate.json +10 -0
- data/spec/mocks/requests/Payment/get_authentication_result.json +4 -0
- data/spec/mocks/requests/Payment/retrieve_3ds2_result.json +4 -0
- data/spec/mocks/requests/Payment/technical_cancel.json +4 -0
- data/spec/mocks/requests/Payment/void_pending_refund.json +4 -0
- data/spec/mocks/requests/Payout/payout.json +8 -0
- data/spec/mocks/requests/Recurring/schedule_account_updater.json +12 -0
- data/spec/mocks/responses/Account/check_account_holder.json +3 -0
- data/spec/mocks/responses/Account/delete_payout_methods.json +3 -0
- data/spec/mocks/responses/Account/delete_signatories.json +3 -0
- data/spec/mocks/responses/BinLookup/get_3ds_availability.json +8 -0
- data/spec/mocks/responses/BinLookup/get_cost_estimate.json +8 -0
- data/spec/mocks/responses/Checkout/get-payment-link.json +11 -0
- data/spec/mocks/responses/Checkout/orders.json +8 -0
- data/spec/mocks/responses/Checkout/orders_cancel.json +4 -0
- data/spec/mocks/responses/Checkout/origin_keys.json +5 -0
- data/spec/mocks/responses/Checkout/payment_methods_balance.json +3 -0
- data/spec/mocks/responses/Checkout/update-payment-link.json +11 -0
- data/spec/mocks/responses/DataProtectionService/request_subject_erasure.json +3 -0
- data/spec/mocks/responses/DisputeService/defend_dispute.json +5 -0
- data/spec/mocks/responses/DisputeService/delete_dispute_defense_document.json +5 -0
- data/spec/mocks/responses/DisputeService/retrieve_applicable_defense_reasons.json +28 -0
- data/spec/mocks/responses/DisputeService/supply_defense_document.json +5 -0
- data/spec/mocks/responses/Fund/refund_funds_transfer.json +5 -0
- data/spec/mocks/responses/Payment/donate.json +4 -0
- data/spec/mocks/responses/Payment/get_authentication_result.json +5 -0
- data/spec/mocks/responses/Payment/retrieve_3ds2_result.json +5 -0
- data/spec/mocks/responses/Payment/technical_cancel.json +3 -0
- data/spec/mocks/responses/Payment/void_pending_refund.json +3 -0
- data/spec/mocks/responses/Payout/payout.json +3 -0
- data/spec/mocks/responses/Recurring/schedule_account_updater.json +4 -0
- data/spec/payments_spec.rb +6 -1
- data/spec/payouts_spec.rb +2 -1
- data/spec/recurring_spec.rb +2 -1
- data/spec/service_spec.rb +2 -0
- data/spec/spec_helper.rb +18 -12
- metadata +60 -7
- data/spec/checkout_utility_spec.rb +0 -29
- data/spec/mocks/requests/CheckoutUtility/origin_keys.json +0 -7
- data/spec/mocks/responses/CheckoutUtility/origin_keys.json +0 -7
@@ -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,18 +1,21 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "service"
|
2
2
|
|
3
3
|
module Adyen
|
4
4
|
class Checkout < Service
|
5
|
-
DEFAULT_VERSION =
|
5
|
+
DEFAULT_VERSION = 67
|
6
6
|
|
7
7
|
def initialize(client, version = DEFAULT_VERSION)
|
8
|
-
service =
|
8
|
+
service = "Checkout"
|
9
9
|
method_names = [
|
10
|
-
:payment_methods,
|
11
10
|
:payment_session,
|
12
|
-
:
|
11
|
+
:origin_keys,
|
13
12
|
]
|
14
13
|
|
15
|
-
|
14
|
+
with_application_info = [
|
15
|
+
:payment_session,
|
16
|
+
]
|
17
|
+
|
18
|
+
super(client, version, service, method_names, with_application_info)
|
16
19
|
end
|
17
20
|
|
18
21
|
# This method can't be dynamically defined because
|
@@ -25,7 +28,40 @@ module Adyen
|
|
25
28
|
when 0
|
26
29
|
Adyen::CheckoutDetail.new(@client, @version)
|
27
30
|
else
|
28
|
-
action =
|
31
|
+
action = "payments"
|
32
|
+
args[1] ||= {} # optional headers arg
|
33
|
+
@client.call_adyen_api(@service, action, args[0], args[1], @version, true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def payment_links(*args)
|
38
|
+
case args.size
|
39
|
+
when 0
|
40
|
+
Adyen::CheckoutLink.new(@client, @version)
|
41
|
+
else
|
42
|
+
action = "paymentLinks"
|
43
|
+
args[1] ||= {} # optional headers arg
|
44
|
+
@client.call_adyen_api(@service, action, args[0], args[1], @version, true)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def payment_methods(*args)
|
49
|
+
case args.size
|
50
|
+
when 0
|
51
|
+
Adyen::CheckoutMethod.new(@client, @version)
|
52
|
+
else
|
53
|
+
action = "paymentMethods"
|
54
|
+
args[1] ||= {} # optional headers arg
|
55
|
+
@client.call_adyen_api(@service, action, args[0], args[1], @version)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def orders(*args)
|
60
|
+
case args.size
|
61
|
+
when 0
|
62
|
+
Adyen::CheckoutOrder.new(@client, @version)
|
63
|
+
else
|
64
|
+
action = "orders"
|
29
65
|
args[1] ||= {} # optional headers arg
|
30
66
|
@client.call_adyen_api(@service, action, args[0], args[1], @version)
|
31
67
|
end
|
@@ -34,7 +70,7 @@ module Adyen
|
|
34
70
|
|
35
71
|
class CheckoutDetail < Service
|
36
72
|
def initialize(client, version = DEFAULT_VERSION)
|
37
|
-
@service =
|
73
|
+
@service = "Checkout"
|
38
74
|
@client = client
|
39
75
|
@version = version
|
40
76
|
end
|
@@ -49,4 +85,48 @@ module Adyen
|
|
49
85
|
@client.call_adyen_api(@service, action, request, headers, @version)
|
50
86
|
end
|
51
87
|
end
|
88
|
+
|
89
|
+
class CheckoutLink < Service
|
90
|
+
def initialize(client, version = DEFAULT_VERSION)
|
91
|
+
@service = "Checkout"
|
92
|
+
@client = client
|
93
|
+
@version = version
|
94
|
+
end
|
95
|
+
|
96
|
+
def get(linkId, headers = {})
|
97
|
+
action = { method: 'get', url: "paymentLinks/" + linkId }
|
98
|
+
@client.call_adyen_api(@service, action, {}, headers, @version, true)
|
99
|
+
end
|
100
|
+
|
101
|
+
def update(linkId, request, headers = {})
|
102
|
+
action = { method: 'patch', url: "paymentLinks/" + linkId }
|
103
|
+
@client.call_adyen_api(@service, action, request, headers, @version, false)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class CheckoutMethod < Service
|
108
|
+
def initialize(client, version = DEFAULT_VERSION)
|
109
|
+
@service = "Checkout"
|
110
|
+
@client = client
|
111
|
+
@version = version
|
112
|
+
end
|
113
|
+
|
114
|
+
def balance(request, headers = {})
|
115
|
+
action = "paymentMethods/balance"
|
116
|
+
@client.call_adyen_api(@service, action, request, headers, @version, true)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class CheckoutOrder < Service
|
121
|
+
def initialize(client, version = DEFAULT_VERSION)
|
122
|
+
@service = "Checkout"
|
123
|
+
@client = client
|
124
|
+
@version = version
|
125
|
+
end
|
126
|
+
|
127
|
+
def cancel(request, headers = {})
|
128
|
+
action = "orders/cancel"
|
129
|
+
@client.call_adyen_api(@service, action, request, headers, @version)
|
130
|
+
end
|
131
|
+
end
|
52
132
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require_relative 'service'
|
2
2
|
|
3
3
|
module Adyen
|
4
|
-
class
|
4
|
+
class DataProtection < Service
|
5
|
+
attr_accessor :version
|
5
6
|
DEFAULT_VERSION = 1
|
6
7
|
|
7
8
|
def initialize(client, version = DEFAULT_VERSION)
|
8
|
-
service = '
|
9
|
+
service = 'DataProtectionService'
|
9
10
|
method_names = [
|
10
|
-
:
|
11
|
+
:request_subject_erasure
|
11
12
|
]
|
12
13
|
|
13
14
|
super(client, version, service, method_names)
|
@@ -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
|
@@ -29,7 +29,7 @@ module Adyen
|
|
29
29
|
|
30
30
|
class Account < Service
|
31
31
|
attr_accessor :version
|
32
|
-
DEFAULT_VERSION =
|
32
|
+
DEFAULT_VERSION = 6
|
33
33
|
|
34
34
|
def initialize(client, version = DEFAULT_VERSION)
|
35
35
|
service = 'Account'
|
@@ -44,11 +44,13 @@ module Adyen
|
|
44
44
|
:update_account_holder_state,
|
45
45
|
:delete_bank_accounts,
|
46
46
|
:delete_shareholders,
|
47
|
+
:delete_signatories,
|
47
48
|
:close_account,
|
48
49
|
:close_account_holder,
|
49
|
-
:get_tier_configuration,
|
50
50
|
:suspend_account_holder,
|
51
|
-
:un_suspend_account_holder
|
51
|
+
:un_suspend_account_holder,
|
52
|
+
:delete_payout_methods,
|
53
|
+
:check_account_holder
|
52
54
|
]
|
53
55
|
|
54
56
|
super(client, version, service, method_names)
|
@@ -57,7 +59,7 @@ module Adyen
|
|
57
59
|
|
58
60
|
class Fund < Service
|
59
61
|
attr_accessor :version
|
60
|
-
DEFAULT_VERSION =
|
62
|
+
DEFAULT_VERSION = 6
|
61
63
|
|
62
64
|
def initialize(client, version = DEFAULT_VERSION)
|
63
65
|
service = 'Fund'
|
@@ -67,7 +69,8 @@ module Adyen
|
|
67
69
|
:account_holder_transaction_list,
|
68
70
|
:refund_not_paid_out_transfers,
|
69
71
|
:setup_beneficiary,
|
70
|
-
:transfer_funds
|
72
|
+
:transfer_funds,
|
73
|
+
:refund_funds_transfer
|
71
74
|
]
|
72
75
|
|
73
76
|
super(client, version, service, method_names)
|
@@ -76,7 +79,7 @@ module Adyen
|
|
76
79
|
|
77
80
|
class Notification < Service
|
78
81
|
attr_accessor :version
|
79
|
-
DEFAULT_VERSION =
|
82
|
+
DEFAULT_VERSION = 6
|
80
83
|
|
81
84
|
def initialize(client, version = DEFAULT_VERSION)
|
82
85
|
service = 'Notification'
|
@@ -95,7 +98,7 @@ module Adyen
|
|
95
98
|
|
96
99
|
class Hop < Service
|
97
100
|
attr_accessor :version
|
98
|
-
DEFAULT_VERSION =
|
101
|
+
DEFAULT_VERSION = 6
|
99
102
|
|
100
103
|
def initialize(client, version = DEFAULT_VERSION)
|
101
104
|
service = 'Hop'
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "service"
|
2
2
|
|
3
3
|
module Adyen
|
4
4
|
class Payments < Service
|
5
5
|
attr_accessor :version
|
6
|
-
DEFAULT_VERSION =
|
6
|
+
DEFAULT_VERSION = 64
|
7
7
|
|
8
8
|
def initialize(client, version = DEFAULT_VERSION)
|
9
|
-
service =
|
9
|
+
service = "Payment"
|
10
10
|
method_names = [
|
11
11
|
:authorise,
|
12
12
|
:authorise3d,
|
@@ -15,10 +15,20 @@ module Adyen
|
|
15
15
|
:cancel,
|
16
16
|
:refund,
|
17
17
|
:cancel_or_refund,
|
18
|
-
:adjust_authorisation
|
18
|
+
:adjust_authorisation,
|
19
|
+
:donate,
|
20
|
+
:get_authentication_result,
|
21
|
+
:technical_cancel,
|
22
|
+
:void_pending_refund,
|
23
|
+
:retrieve_3ds2_result
|
24
|
+
]
|
25
|
+
with_application_info = [
|
26
|
+
:authorise,
|
27
|
+
:authorise3d,
|
28
|
+
:authorise3ds2,
|
19
29
|
]
|
20
30
|
|
21
|
-
super(client, version, service, method_names)
|
31
|
+
super(client, version, service, method_names, with_application_info)
|
22
32
|
end
|
23
33
|
end
|
24
34
|
end
|
@@ -3,7 +3,7 @@ require_relative 'service'
|
|
3
3
|
module Adyen
|
4
4
|
class Payouts < Service
|
5
5
|
attr_accessor :version
|
6
|
-
DEFAULT_VERSION =
|
6
|
+
DEFAULT_VERSION = 64
|
7
7
|
|
8
8
|
def initialize(client, version = DEFAULT_VERSION)
|
9
9
|
service = 'Payout'
|
@@ -12,7 +12,8 @@ module Adyen
|
|
12
12
|
:store_detail_and_submit_third_party,
|
13
13
|
:submit_third_party,
|
14
14
|
:confirm_third_party,
|
15
|
-
:decline_third_party
|
15
|
+
:decline_third_party,
|
16
|
+
:payout
|
16
17
|
]
|
17
18
|
|
18
19
|
super(client, version, service, method_names)
|
@@ -3,14 +3,15 @@ require_relative 'service'
|
|
3
3
|
module Adyen
|
4
4
|
class Recurring < Service
|
5
5
|
attr_accessor :version
|
6
|
-
DEFAULT_VERSION =
|
6
|
+
DEFAULT_VERSION = 49
|
7
7
|
|
8
8
|
def initialize(client, version = DEFAULT_VERSION)
|
9
9
|
service = 'Recurring'
|
10
10
|
method_names = [
|
11
11
|
:list_recurring_details,
|
12
12
|
:disable,
|
13
|
-
:store_token
|
13
|
+
:store_token,
|
14
|
+
:schedule_account_updater
|
14
15
|
]
|
15
16
|
|
16
17
|
super(client, version, service, method_names)
|
@@ -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
|
data/lib/adyen/version.rb
CHANGED
data/spec/account_spec.rb
CHANGED
@@ -20,7 +20,10 @@ RSpec.describe Adyen::Payments, service: "marketpay account service" do
|
|
20
20
|
["upload_document", "pspReference", "9914762681460244"],
|
21
21
|
["get_uploaded_documents", "pspReference", "9914694369860322"],
|
22
22
|
["delete_bank_accounts", "pspReference", "9914694372670551"],
|
23
|
-
["delete_shareholders", "pspReference", "9914694372990637"]
|
23
|
+
["delete_shareholders", "pspReference", "9914694372990637"],
|
24
|
+
["delete_signatories", "pspReference", "9914694372990637"],
|
25
|
+
["delete_payout_methods", "pspReference", "9914694372990637"],
|
26
|
+
["check_account_holder", "pspReference", "9914694372990637"],
|
24
27
|
]
|
25
28
|
|
26
29
|
generate_tests(client, "Account", test_sets, client.marketpay.account)
|
@@ -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
|
data/spec/checkout_spec.rb
CHANGED
@@ -13,9 +13,79 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
|
|
13
13
|
|
14
14
|
# must be created manually because every field in the response is an array
|
15
15
|
it "makes a payment_methods call" do
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_methods.json"))
|
17
|
+
|
18
|
+
response_body = json_from_file("mocks/responses/Checkout/payment_methods.json")
|
19
|
+
|
20
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentMethods", @shared_values[:client].checkout.version)
|
21
|
+
WebMock.stub_request(:post, url).
|
22
|
+
with(
|
23
|
+
body: request_body,
|
24
|
+
headers: {
|
25
|
+
"x-api-key" => @shared_values[:client].api_key
|
26
|
+
}
|
27
|
+
).
|
28
|
+
to_return(
|
29
|
+
body: response_body
|
30
|
+
)
|
31
|
+
|
32
|
+
result = @shared_values[:client].checkout.payment_methods(request_body)
|
33
|
+
response_hash = result.response
|
34
|
+
|
35
|
+
expect(result.status).
|
36
|
+
to eq(200)
|
37
|
+
expect(response_hash).
|
38
|
+
to eq(JSON.parse(response_body))
|
39
|
+
expect(response_hash).
|
40
|
+
to be_a Adyen::HashWithAccessors
|
41
|
+
expect(response_hash).
|
42
|
+
to be_a_kind_of Hash
|
43
|
+
end
|
44
|
+
|
45
|
+
it "makes a paymentMethods/balance call" do
|
46
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_methods_balance.json"))
|
47
|
+
request_body[:applicationInfo] = {}
|
48
|
+
request_body[:applicationInfo][:adyenPaymentSource] = {
|
49
|
+
:name => "adyen-test",
|
50
|
+
:version => "1.0.0",
|
51
|
+
}
|
52
|
+
|
53
|
+
@shared_values[:client].add_application_info(request_body)
|
54
|
+
|
55
|
+
response_body = json_from_file("mocks/responses/Checkout/payment_methods_balance.json")
|
56
|
+
|
57
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentMethods/balance", @shared_values[:client].checkout.version)
|
58
|
+
WebMock.stub_request(:post, url).
|
59
|
+
with(
|
60
|
+
body: request_body,
|
61
|
+
headers: {
|
62
|
+
"x-api-key" => @shared_values[:client].api_key
|
63
|
+
}
|
64
|
+
).
|
65
|
+
to_return(
|
66
|
+
body: response_body
|
67
|
+
)
|
68
|
+
|
69
|
+
result = @shared_values[:client].checkout.payment_methods.balance(request_body)
|
70
|
+
# result.response is already a Ruby hash (rather than an unparsed JSON string)
|
71
|
+
response_hash = result.response
|
72
|
+
|
73
|
+
expect(request_body[:applicationInfo][:adyenLibrary][:name]).
|
74
|
+
to eq(Adyen::NAME)
|
75
|
+
expect(request_body[:applicationInfo][:adyenLibrary][:version]).
|
76
|
+
to eq(Adyen::VERSION)
|
77
|
+
expect(request_body[:applicationInfo][:adyenPaymentSource][:name]).
|
78
|
+
to eq("adyen-test")
|
79
|
+
expect(result.status).
|
80
|
+
to eq(200)
|
81
|
+
expect(response_hash).
|
82
|
+
to eq(JSON.parse(response_body))
|
83
|
+
expect(response_hash).
|
84
|
+
to be_a Adyen::HashWithAccessors
|
85
|
+
expect(response_hash).
|
86
|
+
to be_a_kind_of Hash
|
87
|
+
expect(response_hash["balance"]).
|
88
|
+
to eq("100")
|
19
89
|
end
|
20
90
|
|
21
91
|
# must be created manually due to payments/details format
|
@@ -102,6 +172,178 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
|
|
102
172
|
expect(response_hash.resultCode).
|
103
173
|
to eq("Authorised")
|
104
174
|
end
|
175
|
+
|
176
|
+
# must be created manually due to paymentsLinks format
|
177
|
+
it "makes a paymentLinks call" do
|
178
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_links.json"))
|
179
|
+
request_body[:applicationInfo] = {}
|
180
|
+
request_body[:applicationInfo][:adyenPaymentSource] = {
|
181
|
+
:name => "adyen-test",
|
182
|
+
:version => "1.0.0",
|
183
|
+
}
|
184
|
+
|
185
|
+
@shared_values[:client].add_application_info(request_body)
|
186
|
+
|
187
|
+
response_body = json_from_file("mocks/responses/Checkout/payment_links.json")
|
188
|
+
|
189
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks", @shared_values[:client].checkout.version)
|
190
|
+
WebMock.stub_request(:post, url).
|
191
|
+
with(
|
192
|
+
body: request_body,
|
193
|
+
headers: {
|
194
|
+
"x-api-key" => @shared_values[:client].api_key
|
195
|
+
}
|
196
|
+
).
|
197
|
+
to_return(
|
198
|
+
body: response_body
|
199
|
+
)
|
200
|
+
|
201
|
+
result = @shared_values[:client].checkout.payment_links(request_body)
|
202
|
+
response_hash = result.response
|
203
|
+
|
204
|
+
expect(result.status).
|
205
|
+
to eq(200)
|
206
|
+
expect(response_hash).
|
207
|
+
to eq(JSON.parse(response_body))
|
208
|
+
expect(response_hash).
|
209
|
+
to be_a Adyen::HashWithAccessors
|
210
|
+
expect(response_hash).
|
211
|
+
to be_a_kind_of Hash
|
212
|
+
end
|
213
|
+
|
214
|
+
# must be created manually due to paymentsLinks/{linkId} format
|
215
|
+
it "makes a get paymentLinks/{linkId} call" do
|
216
|
+
response_body = json_from_file("mocks/responses/Checkout/get-payment-link.json")
|
217
|
+
|
218
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks/1", @shared_values[:client].checkout.version)
|
219
|
+
WebMock.stub_request(:get, url).
|
220
|
+
with(
|
221
|
+
headers: {
|
222
|
+
"x-api-key" => @shared_values[:client].api_key
|
223
|
+
}
|
224
|
+
).
|
225
|
+
to_return(
|
226
|
+
body: response_body
|
227
|
+
)
|
228
|
+
|
229
|
+
result = @shared_values[:client].checkout.payment_links.get("1")
|
230
|
+
response_hash = result.response
|
231
|
+
|
232
|
+
expect(result.status).
|
233
|
+
to eq(200)
|
234
|
+
expect(response_hash).
|
235
|
+
to eq(JSON.parse(response_body))
|
236
|
+
expect(response_hash).
|
237
|
+
to be_a Adyen::HashWithAccessors
|
238
|
+
expect(response_hash).
|
239
|
+
to be_a_kind_of Hash
|
240
|
+
expect(response_hash["status"]).
|
241
|
+
to eq("active")
|
242
|
+
expect(response_hash.id).
|
243
|
+
to eq("MockId")
|
244
|
+
end
|
245
|
+
|
246
|
+
# must be created manually due to paymentsLinks/{linkId} format
|
247
|
+
it "makes a patch paymentLinks/{linkId} call" do
|
248
|
+
request_body = {
|
249
|
+
:status => "expired",
|
250
|
+
}
|
251
|
+
|
252
|
+
@shared_values[:client].add_application_info(request_body)
|
253
|
+
response_body = json_from_file("mocks/responses/Checkout/update-payment-link.json")
|
254
|
+
|
255
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks/1", @shared_values[:client].checkout.version)
|
256
|
+
WebMock.stub_request(:patch, url).
|
257
|
+
with(
|
258
|
+
body: request_body,
|
259
|
+
headers: {
|
260
|
+
"x-api-key" => @shared_values[:client].api_key
|
261
|
+
}
|
262
|
+
).
|
263
|
+
to_return(
|
264
|
+
body: response_body
|
265
|
+
)
|
266
|
+
|
267
|
+
result = @shared_values[:client].checkout.payment_links.update("1", request_body)
|
268
|
+
response_hash = result.response
|
269
|
+
|
270
|
+
expect(result.status).
|
271
|
+
to eq(200)
|
272
|
+
expect(response_hash).
|
273
|
+
to eq(JSON.parse(response_body))
|
274
|
+
expect(response_hash).
|
275
|
+
to be_a Adyen::HashWithAccessors
|
276
|
+
expect(response_hash).
|
277
|
+
to be_a_kind_of Hash
|
278
|
+
expect(response_hash["status"]).
|
279
|
+
to eq("expired")
|
280
|
+
expect(response_hash.id).
|
281
|
+
to eq("MockId")
|
282
|
+
end
|
283
|
+
|
284
|
+
it "makes an orders call" do
|
285
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/orders.json"))
|
286
|
+
|
287
|
+
response_body = json_from_file("mocks/responses/Checkout/orders.json")
|
288
|
+
|
289
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "orders", @shared_values[:client].checkout.version)
|
290
|
+
WebMock.stub_request(:post, url).
|
291
|
+
with(
|
292
|
+
body: request_body,
|
293
|
+
headers: {
|
294
|
+
"x-api-key" => @shared_values[:client].api_key
|
295
|
+
}
|
296
|
+
).
|
297
|
+
to_return(
|
298
|
+
body: response_body
|
299
|
+
)
|
300
|
+
|
301
|
+
result = @shared_values[:client].checkout.orders(request_body)
|
302
|
+
response_hash = result.response
|
303
|
+
|
304
|
+
expect(result.status).
|
305
|
+
to eq(200)
|
306
|
+
expect(response_hash).
|
307
|
+
to eq(JSON.parse(response_body))
|
308
|
+
expect(response_hash).
|
309
|
+
to be_a Adyen::HashWithAccessors
|
310
|
+
expect(response_hash).
|
311
|
+
to be_a_kind_of Hash
|
312
|
+
expect(response_hash["remainingAmount"]["value"]).
|
313
|
+
to eq(100)
|
314
|
+
end
|
315
|
+
|
316
|
+
it "makes an orders/cancel call" do
|
317
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/orders_cancel.json"))
|
318
|
+
|
319
|
+
response_body = json_from_file("mocks/responses/Checkout/orders_cancel.json")
|
320
|
+
|
321
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "orders/cancel", @shared_values[:client].checkout.version)
|
322
|
+
WebMock.stub_request(:post, url).
|
323
|
+
with(
|
324
|
+
body: request_body,
|
325
|
+
headers: {
|
326
|
+
"x-api-key" => @shared_values[:client].api_key
|
327
|
+
}
|
328
|
+
).
|
329
|
+
to_return(
|
330
|
+
body: response_body
|
331
|
+
)
|
332
|
+
|
333
|
+
result = @shared_values[:client].checkout.orders.cancel(request_body)
|
334
|
+
response_hash = result.response
|
335
|
+
|
336
|
+
expect(result.status).
|
337
|
+
to eq(200)
|
338
|
+
expect(response_hash).
|
339
|
+
to eq(JSON.parse(response_body))
|
340
|
+
expect(response_hash).
|
341
|
+
to be_a Adyen::HashWithAccessors
|
342
|
+
expect(response_hash).
|
343
|
+
to be_a_kind_of Hash
|
344
|
+
expect(response_hash["resultCode"]).
|
345
|
+
to eq("cancelled")
|
346
|
+
end
|
105
347
|
|
106
348
|
# create client for automated tests
|
107
349
|
client = create_client(:api_key)
|
@@ -110,8 +352,8 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
|
|
110
352
|
# format is defined in spec_helper
|
111
353
|
test_sets = [
|
112
354
|
["payment_session", "publicKeyToken", "8115054323780109"],
|
113
|
-
["
|
114
|
-
["
|
355
|
+
["payments", "resultCode", "Authorised"],
|
356
|
+
["origin_keys", "originKeys", { "https://adyen.com" => "mocked_origin_key" }]
|
115
357
|
]
|
116
358
|
|
117
359
|
generate_tests(client, "Checkout", test_sets, client.checkout)
|