Skip to content

Commit 3fac613

Browse files
authored
Merge pull request #114 from Adyen/develop
Release 6.2.0
2 parents 1ae41e4 + 83ed3fb commit 3fac613

File tree

18 files changed

+496
-4
lines changed

18 files changed

+496
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Publish Gem
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v1
13+
14+
- name: Release Gem on RubyGems
15+
if: contains(github.ref, 'refs/tags/v')
16+
uses: cadwallion/publish-rubygems-action@master
17+
env:
18+
GITHUB_TOKEN: ${{secrets.TOKEN_RUBYGEMS_RELEASES_WITH_EXPIRATION}}
19+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}

lib/adyen/client.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
module Adyen
77
class Client
88
attr_accessor :ws_user, :ws_password, :api_key, :client, :adapter, :live_url_prefix
9-
attr_reader :env
9+
attr_reader :env, :connection_options
1010

11-
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+
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, connection_options: nil)
1212
@ws_user = ws_user
1313
@ws_password = ws_password
1414
@api_key = api_key
1515
@env = env
1616
@adapter = adapter || Faraday.default_adapter
1717
@mock_service_url_base = mock_service_url_base || "http://localhost:#{mock_port}"
1818
@live_url_prefix = live_url_prefix
19+
@connection_options = connection_options || Faraday::ConnectionOptions.new
1920
end
2021

2122
# make sure that env can only be :live, :test, or :mock
@@ -96,7 +97,7 @@ def call_adyen_api(service, action, request_data, headers, version, with_applica
9697
end
9798

9899
# initialize Faraday connection object
99-
conn = Faraday.new(url: url) do |faraday|
100+
conn = Faraday.new(url, @connection_options) do |faraday|
100101
faraday.adapter @adapter
101102
faraday.headers["Content-Type"] = "application/json"
102103
faraday.headers["User-Agent"] = Adyen::NAME + "/" + Adyen::VERSION

lib/adyen/services/checkout.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def orders(*args)
7171
def apple_pay
7272
@apple_pay ||= Adyen::CheckoutApplePay.new(@client, @version)
7373
end
74+
75+
def modifications
76+
@modifications ||= Adyen::Modifications.new(@client, @version)
77+
end
7478
end
7579

7680
class CheckoutDetail < Service
@@ -147,4 +151,42 @@ def sessions(request, headers = {})
147151
@client.call_adyen_api(@service, action, request, headers, @version)
148152
end
149153
end
154+
155+
class Modifications < Service
156+
def initialize(client, version = DEFAULT_VERSION)
157+
@service = "Checkout"
158+
@client = client
159+
@version = version
160+
end
161+
162+
def capture(linkId, request, headers = {})
163+
action = "payments/" + linkId + "/captures"
164+
@client.call_adyen_api(@service, action, request, headers, @version, false)
165+
end
166+
167+
def cancel(linkId, request, headers = {})
168+
action = "payments/" + linkId + "/cancels"
169+
@client.call_adyen_api(@service, action, request, headers, @version, false)
170+
end
171+
172+
def genericCancel(request, headers = {})
173+
action = "cancels"
174+
@client.call_adyen_api(@service, action, request, headers, @version)
175+
end
176+
177+
def refund(linkId, request, headers = {})
178+
action = "payments/" + linkId + "/refunds"
179+
@client.call_adyen_api(@service, action, request, headers, @version, false)
180+
end
181+
182+
def reversal(linkId, request, headers = {})
183+
action = "payments/" + linkId + "/reversals"
184+
@client.call_adyen_api(@service, action, request, headers, @version, false)
185+
end
186+
187+
def amountUpdate(linkId, request, headers = {})
188+
action = "payments/" + linkId + "/amountUpdates"
189+
@client.call_adyen_api(@service, action, request, headers, @version, false)
190+
end
191+
end
150192
end

lib/adyen/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module Adyen
22
NAME = "adyen-ruby-api-library"
3-
VERSION = "6.1.0".freeze
3+
VERSION = "6.2.0".freeze
44
end

spec/checkout_spec.rb

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,198 @@
405405
to be_a_kind_of Hash
406406
end
407407

408+
it "makes a capture call" do
409+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/capture.json"))
410+
411+
response_body = json_from_file("mocks/responses/Checkout/capture.json")
412+
413+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/captures", @shared_values[:client].checkout.version)
414+
WebMock.stub_request(:post, url).
415+
with(
416+
body: request_body,
417+
headers: {
418+
"x-api-key" => @shared_values[:client].api_key
419+
}
420+
)
421+
.to_return(body: response_body, status: 201)
422+
423+
result = @shared_values[:client].checkout.modifications.capture("12345", request_body)
424+
response_hash = result.response
425+
426+
expect(result.status).
427+
to eq(201)
428+
expect(response_hash).
429+
to eq(JSON.parse(response_body))
430+
expect(response_hash).
431+
to be_a Adyen::HashWithAccessors
432+
expect(response_hash).
433+
to be_a_kind_of Hash
434+
expect(response_hash.reference).
435+
to eq("123456789")
436+
expect(response_hash.pspReference).
437+
to eq("12345")
438+
end
439+
440+
it "makes a psp specific cancel call" do
441+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/psp_cancel.json"))
442+
443+
response_body = json_from_file("mocks/responses/Checkout/psp_cancel.json")
444+
445+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/cancels", @shared_values[:client].checkout.version)
446+
WebMock.stub_request(:post, url).
447+
with(
448+
body: request_body,
449+
headers: {
450+
"x-api-key" => @shared_values[:client].api_key
451+
}
452+
)
453+
.to_return(body: response_body, status: 201)
454+
455+
result = @shared_values[:client].checkout.modifications.cancel("12345", request_body)
456+
response_hash = result.response
457+
458+
expect(result.status).
459+
to eq(201)
460+
expect(response_hash).
461+
to eq(JSON.parse(response_body))
462+
expect(response_hash).
463+
to be_a Adyen::HashWithAccessors
464+
expect(response_hash).
465+
to be_a_kind_of Hash
466+
expect(response_hash.reference).
467+
to eq("123456789")
468+
expect(response_hash.pspReference).
469+
to eq("12345")
470+
end
471+
472+
it "makes a psp specific refunds call" do
473+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/refund.json"))
474+
475+
response_body = json_from_file("mocks/responses/Checkout/refund.json")
476+
477+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/refunds", @shared_values[:client].checkout.version)
478+
WebMock.stub_request(:post, url).
479+
with(
480+
body: request_body,
481+
headers: {
482+
"x-api-key" => @shared_values[:client].api_key
483+
}
484+
)
485+
.to_return(body: response_body, status: 201)
486+
487+
result = @shared_values[:client].checkout.modifications.refund("12345", request_body)
488+
response_hash = result.response
489+
490+
expect(result.status).
491+
to eq(201)
492+
expect(response_hash).
493+
to eq(JSON.parse(response_body))
494+
expect(response_hash).
495+
to be_a Adyen::HashWithAccessors
496+
expect(response_hash).
497+
to be_a_kind_of Hash
498+
expect(response_hash.reference).
499+
to eq("123456789")
500+
expect(response_hash.pspReference).
501+
to eq("12345")
502+
end
503+
504+
it "makes a psp specific reversals call" do
505+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/psp_cancel.json"))
506+
507+
response_body = json_from_file("mocks/responses/Checkout/psp_cancel.json")
508+
509+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/reversals", @shared_values[:client].checkout.version)
510+
WebMock.stub_request(:post, url).
511+
with(
512+
body: request_body,
513+
headers: {
514+
"x-api-key" => @shared_values[:client].api_key
515+
}
516+
)
517+
.to_return(body: response_body, status: 201)
518+
519+
result = @shared_values[:client].checkout.modifications.reversal("12345", request_body)
520+
response_hash = result.response
521+
522+
expect(result.status).
523+
to eq(201)
524+
expect(response_hash).
525+
to eq(JSON.parse(response_body))
526+
expect(response_hash).
527+
to be_a Adyen::HashWithAccessors
528+
expect(response_hash).
529+
to be_a_kind_of Hash
530+
expect(response_hash.reference).
531+
to eq("123456789")
532+
expect(response_hash.pspReference).
533+
to eq("12345")
534+
end
535+
536+
it "makes a psp specific amountUpdates call" do
537+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/amount_updates.json"))
538+
539+
response_body = json_from_file("mocks/responses/Checkout/amount_updates.json")
540+
541+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/amountUpdates", @shared_values[:client].checkout.version)
542+
WebMock.stub_request(:post, url).
543+
with(
544+
body: request_body,
545+
headers: {
546+
"x-api-key" => @shared_values[:client].api_key
547+
}
548+
)
549+
.to_return(body: response_body, status: 201)
550+
551+
result = @shared_values[:client].checkout.modifications.amountUpdate("12345", request_body)
552+
response_hash = result.response
553+
554+
expect(result.status).
555+
to eq(201)
556+
expect(response_hash).
557+
to eq(JSON.parse(response_body))
558+
expect(response_hash).
559+
to be_a Adyen::HashWithAccessors
560+
expect(response_hash).
561+
to be_a_kind_of Hash
562+
expect(response_hash.reference).
563+
to eq("123456789")
564+
expect(response_hash.pspReference).
565+
to eq("12345")
566+
end
567+
568+
it "makes a generic cancel call" do
569+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/generic_cancel.json"))
570+
571+
response_body = json_from_file("mocks/responses/Checkout/generic_cancel.json")
572+
573+
url = @shared_values[:client].service_url(@shared_values[:service], "cancels", @shared_values[:client].checkout.version)
574+
WebMock.stub_request(:post, url).
575+
with(
576+
body: request_body,
577+
headers: {
578+
"x-api-key" => @shared_values[:client].api_key
579+
}
580+
)
581+
.to_return(body: response_body, status: 201)
582+
583+
result = @shared_values[:client].checkout.modifications.genericCancel(request_body)
584+
response_hash = result.response
585+
586+
expect(result.status).
587+
to eq(201)
588+
expect(response_hash).
589+
to eq(JSON.parse(response_body))
590+
expect(response_hash).
591+
to be_a Adyen::HashWithAccessors
592+
expect(response_hash).
593+
to be_a_kind_of Hash
594+
expect(response_hash.reference).
595+
to eq("123456789")
596+
expect(response_hash.pspReference).
597+
to eq("12345")
598+
end
599+
408600
# create client for automated tests
409601
client = create_client(:api_key)
410602

spec/client_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,31 @@
8383
expect(client.service_url_base("Payment")).
8484
to eq("https://abcdef1234567890-TestCompany-pal-live.adyenpayments.com/pal/servlet")
8585
end
86+
87+
it "generates a new set of ConnectionOptions when none are provided" do
88+
expect(Faraday::ConnectionOptions).to receive(:new).and_call_original
89+
client = Adyen::Client.new(env: :test)
90+
end
91+
92+
it "uses the ConnectionOptions provided" do
93+
connection_options = Faraday::ConnectionOptions.new
94+
expect(Faraday::ConnectionOptions).not_to receive(:new)
95+
client = Adyen::Client.new(env: :test, connection_options: connection_options)
96+
end
97+
98+
it "initiates a Faraday connection with the provided options" do
99+
connection_options = Faraday::ConnectionOptions.new
100+
expect(Faraday::ConnectionOptions).not_to receive(:new)
101+
client = Adyen::Client.new(api_key: "api_key", env: :mock, connection_options: connection_options)
102+
103+
mock_faraday_connection = double(Faraday::Connection)
104+
url = client.service_url(@shared_values[:service], "payments/details", client.checkout.version)
105+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment-details.json"))
106+
mock_response = Faraday::Response.new(status: 200)
107+
108+
expect(Adyen::AdyenResult).to receive(:new)
109+
expect(Faraday).to receive(:new).with("http://localhost:3001/v68/payments/details", connection_options).and_return(mock_faraday_connection)
110+
expect(mock_faraday_connection).to receive(:post).and_return(mock_response)
111+
client.checkout.payments.details(request_body)
112+
end
86113
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"amount": {
3+
"currency": "str",
4+
"value": 0
5+
},
6+
"merchantAccount": "TestMerchant",
7+
"reason": "delayedCharge",
8+
"reference": "123456789",
9+
"splits": [
10+
{
11+
"account": "string",
12+
"amount": {
13+
"currency": "str",
14+
"value": 0
15+
},
16+
"description": "string",
17+
"reference": "string",
18+
"type": "BalanceAccount"
19+
}
20+
]
21+
}
22+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"amount": {
3+
"currency": "str",
4+
"value": 0
5+
},
6+
"lineItems": [
7+
{
8+
"amountExcludingTax": 0,
9+
"amountIncludingTax": 0,
10+
"description": "string",
11+
"id": "string",
12+
"imageUrl": "string",
13+
"itemCategory": "string",
14+
"productUrl": "string",
15+
"quantity": 0,
16+
"taxAmount": 0,
17+
"taxPercentage": 0
18+
}
19+
],
20+
"merchantAccount": "string",
21+
"reference": "string",
22+
"splits": [
23+
{
24+
"account": "string",
25+
"amount": {
26+
"currency": "str",
27+
"value": 0
28+
},
29+
"description": "string",
30+
"reference": "string",
31+
"type": "BalanceAccount"
32+
}
33+
]
34+
}

0 commit comments

Comments
 (0)