pcp-server-ruby-sdk 1.2.0 → 1.3.1

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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/PCP-server-Ruby-SDK.gemspec +1 -1
  4. data/README.md +126 -0
  5. data/example-app/commerce_case_api_example.rb +9 -1
  6. data/example-app/example.rb +73 -1
  7. data/lib/PCP-server-Ruby-SDK/communicator_configuration.rb +6 -3
  8. data/lib/PCP-server-Ruby-SDK/endpoints/authentication_api_client.rb +33 -0
  9. data/lib/PCP-server-Ruby-SDK/endpoints/base_api_client.rb +59 -8
  10. data/lib/PCP-server-Ruby-SDK/endpoints/checkout_api_client.rb +2 -2
  11. data/lib/PCP-server-Ruby-SDK/endpoints/commerce_case_api_client.rb +2 -2
  12. data/lib/PCP-server-Ruby-SDK/endpoints/order_management_checkout_actions_api_client.rb +2 -2
  13. data/lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb +2 -2
  14. data/lib/PCP-server-Ruby-SDK/endpoints/payment_information_api_client.rb +2 -2
  15. data/lib/PCP-server-Ruby-SDK/models/authentication_token.rb +189 -0
  16. data/lib/PCP-server-Ruby-SDK/version.rb +1 -1
  17. data/lib/PCP-server-Ruby-SDK.rb +2 -0
  18. data/package-lock.json +187 -187
  19. data/package.json +1 -1
  20. data/spec/communicator_configuration_spec.rb +27 -0
  21. data/spec/endpoints/authentication_api_client_spec.rb +78 -0
  22. data/spec/endpoints/base_api_client_spec.rb +222 -0
  23. data/spec/endpoints/checkout_api_client_spec.rb +1 -1
  24. data/spec/endpoints/commerce_case_api_client_spec.rb +1 -1
  25. data/spec/endpoints/order_management_checkout_actions_api_client_spec.rb +1 -1
  26. data/spec/endpoints/payment_execution_api_client_spec.rb +1 -1
  27. data/spec/endpoints/payment_information_api_client_spec.rb +1 -1
  28. data/spec/spec_helper.rb +9 -0
  29. metadata +24 -3
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pcp-serversdk-ruby",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "type": "commonjs",
5
5
  "scripts": {
6
6
  "changelog": "conventional-changelog -i CHANGELOG.md -s --config ./changelog.config.js"
@@ -19,5 +19,32 @@ RSpec.describe PCPServerSDK::CommunicatorConfiguration do
19
19
  it 'sets host' do
20
20
  expect(config.host).to eq(host)
21
21
  end
22
+
23
+ it 'sets http_client to nil by default' do
24
+ expect(config.http_client).to be_nil
25
+ end
26
+
27
+ context 'with custom http_client' do
28
+ let(:custom_http_client) { Net::HTTP.new('example.com', 80) }
29
+ let(:config_with_client) { PCPServerSDK::CommunicatorConfiguration.new(api_key, api_secret, host, custom_http_client) }
30
+
31
+ it 'sets the custom http_client' do
32
+ expect(config_with_client.http_client).to eq(custom_http_client)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#http_client=' do
38
+ it 'allows setting http_client after initialization' do
39
+ custom_client = Net::HTTP.new('example.com', 80)
40
+ config.http_client = custom_client
41
+ expect(config.http_client).to eq(custom_client)
42
+ end
43
+
44
+ it 'allows setting http_client to a proc' do
45
+ client_factory = proc { |uri| Net::HTTP.new(uri.host, uri.port) }
46
+ config.http_client = client_factory
47
+ expect(config.http_client).to eq(client_factory)
48
+ end
22
49
  end
23
50
  end
@@ -0,0 +1,78 @@
1
+
2
+
3
+ require 'spec_helper'
4
+ require 'net/http'
5
+ require 'json'
6
+ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
7
+
8
+
9
+ RSpec.describe PCPServerSDK::Endpoints::AuthenticationApiClient do
10
+ let(:config) { mock_communicator_config }
11
+ let(:client) { PCPServerSDK::Endpoints::AuthenticationApiClient.new(config) }
12
+
13
+ describe '#get_authentication_tokens' do
14
+ let(:merchant_id) { 'merchant123' }
15
+ let(:request_id) { 'req-456' }
16
+ let(:success_response_body) {
17
+ {
18
+ token: 'jwt-token',
19
+ id: 'uuid-123',
20
+ creationDate: '2025-07-10T12:00:00Z',
21
+ expirationDate: '2025-07-10T12:10:00Z'
22
+ }.to_json
23
+ }
24
+ let(:error_body) {
25
+ PCPServerSDK::Models::ErrorResponse.new(
26
+ error_id: '1',
27
+ errors: [PCPServerSDK::Models::APIError.new(error_code: '1', message: 'Error 1')]
28
+ ).to_body.to_json
29
+ }
30
+
31
+ context 'when request is successful' do
32
+ let(:response) { double('Response', body: success_response_body, code: 200) }
33
+
34
+ before do
35
+ allow(client).to receive(:get_response).and_return(response)
36
+ end
37
+
38
+ it 'returns an AuthenticationToken' do
39
+ token = client.get_authentication_tokens(merchant_id, request_id)
40
+ expect(token).to be_a(PCPServerSDK::Models::AuthenticationToken)
41
+ expect(token.token).to eq('jwt-token')
42
+ expect(token.id).to eq('uuid-123')
43
+ expect(token.creation_date).to be_a(Time)
44
+ expect(token.expiration_date).to be_a(Time)
45
+ end
46
+ end
47
+
48
+ context 'when request is unsuccessful (400)' do
49
+ let(:response) { double('Response', body: error_body, code: 400) }
50
+
51
+ before do
52
+ allow(client).to receive(:get_response).and_return(response)
53
+ end
54
+
55
+ it 'raises an PCPServerSDK::Errors::ApiErrorResponseException' do
56
+ expect { client.get_authentication_tokens(merchant_id, request_id) }.to raise_error(PCPServerSDK::Errors::ApiErrorResponseException)
57
+ end
58
+ end
59
+
60
+ context 'when request is unsuccessful (500)' do
61
+ let(:response) { double('Response', body: '{}', code: 500) }
62
+
63
+ before do
64
+ allow(client).to receive(:get_response).and_return(response)
65
+ end
66
+
67
+ it 'raises an PCPServerSDK::Errors::ApiResponseRetrievalException' do
68
+ expect { client.get_authentication_tokens(merchant_id, request_id) }.to raise_error(PCPServerSDK::Errors::ApiResponseRetrievalException)
69
+ end
70
+ end
71
+
72
+ context 'when merchant_id is nil' do
73
+ it 'raises an ArgumentError' do
74
+ expect { client.get_authentication_tokens(nil, '2') }.to raise_error(TypeError, 'Merchant ID is required')
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,222 @@
1
+ require 'spec_helper'
2
+ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
3
+
4
+ RSpec.describe PCPServerSDK::Endpoints::BaseApiClient do
5
+ let(:api_key) { 'test_api_key' }
6
+ let(:api_secret) { 'test_api_secret' }
7
+ let(:host) { 'https://api.example.com' }
8
+ let(:config) { PCPServerSDK::CommunicatorConfiguration.new(api_key, api_secret, host) }
9
+ let(:client) { PCPServerSDK::Endpoints::BaseApiClient.new(config) }
10
+
11
+ describe '#initialize' do
12
+ it 'sets the config' do
13
+ expect(client.send(:get_config)).to eq(config)
14
+ end
15
+
16
+ it 'sets http_client to nil by default' do
17
+ expect(client.http_client).to be_nil
18
+ end
19
+
20
+ context 'with custom http_client' do
21
+ let(:custom_http_client) { Net::HTTP.new('example.com', 80) }
22
+ let(:client_with_custom) { PCPServerSDK::Endpoints::BaseApiClient.new(config, custom_http_client) }
23
+
24
+ it 'sets the custom http_client' do
25
+ expect(client_with_custom.http_client).to eq(custom_http_client)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#http_client=' do
31
+ it 'allows setting http_client after initialization' do
32
+ custom_client = Net::HTTP.new('example.com', 80)
33
+ client.http_client = custom_client
34
+ expect(client.http_client).to eq(custom_client)
35
+ end
36
+ end
37
+
38
+ describe '#get_http_client (private method)' do
39
+ let(:uri) { URI.parse('https://api.example.com/test') }
40
+
41
+ context 'with client-specific http_client' do
42
+ let(:client_specific_http) { Net::HTTP.new('client.example.com', 443) }
43
+
44
+ before do
45
+ client.http_client = client_specific_http
46
+ end
47
+
48
+ it 'returns the client-specific http client' do
49
+ result = client.send(:get_http_client, uri)
50
+ expect(result).to eq(client_specific_http)
51
+ end
52
+
53
+ it 'prioritizes client-specific over global configuration' do
54
+ global_http = Net::HTTP.new('global.example.com', 443)
55
+ config.http_client = global_http
56
+
57
+ result = client.send(:get_http_client, uri)
58
+ expect(result).to eq(client_specific_http)
59
+ end
60
+ end
61
+
62
+ context 'with global http_client in configuration' do
63
+ let(:global_http) { Net::HTTP.new('global.example.com', 443) }
64
+
65
+ before do
66
+ config.http_client = global_http
67
+ end
68
+
69
+ it 'returns the global http client when no client-specific client is set' do
70
+ result = client.send(:get_http_client, uri)
71
+ expect(result).to eq(global_http)
72
+ end
73
+ end
74
+
75
+ context 'with proc-based http_client factory' do
76
+ let(:http_factory) do
77
+ proc do |uri|
78
+ http = Net::HTTP.new(uri.host, uri.port)
79
+ http.use_ssl = uri.scheme == 'https'
80
+ http.read_timeout = 30
81
+ http
82
+ end
83
+ end
84
+
85
+ before do
86
+ client.http_client = http_factory
87
+ end
88
+
89
+ it 'calls the proc with the URI and returns the result' do
90
+ result = client.send(:get_http_client, uri)
91
+ expect(result).to be_a(Net::HTTP)
92
+ expect(result.address).to eq('api.example.com')
93
+ expect(result.port).to eq(443)
94
+ expect(result.use_ssl?).to be true
95
+ expect(result.read_timeout).to eq(30)
96
+ end
97
+ end
98
+
99
+ context 'with callable object as http_client factory' do
100
+ let(:http_factory) do
101
+ Class.new do
102
+ def call(uri)
103
+ http = Net::HTTP.new(uri.host, uri.port)
104
+ http.use_ssl = uri.scheme == 'https'
105
+ http.open_timeout = 10
106
+ http
107
+ end
108
+ end.new
109
+ end
110
+
111
+ before do
112
+ config.http_client = http_factory
113
+ end
114
+
115
+ it 'calls the callable object with the URI and returns the result' do
116
+ result = client.send(:get_http_client, uri)
117
+ expect(result).to be_a(Net::HTTP)
118
+ expect(result.address).to eq('api.example.com')
119
+ expect(result.port).to eq(443)
120
+ expect(result.use_ssl?).to be true
121
+ expect(result.open_timeout).to eq(10)
122
+ end
123
+ end
124
+
125
+ context 'with default http_client (no customization)' do
126
+ it 'creates a default Net::HTTP client' do
127
+ result = client.send(:get_http_client, uri)
128
+ expect(result).to be_a(Net::HTTP)
129
+ expect(result.address).to eq('api.example.com')
130
+ expect(result.port).to eq(443)
131
+ expect(result.use_ssl?).to be true
132
+ end
133
+ end
134
+
135
+ context 'with invalid http_client' do
136
+ before do
137
+ client.http_client = "invalid_client"
138
+ end
139
+
140
+ it 'raises an ArgumentError' do
141
+ expect {
142
+ client.send(:get_http_client, uri)
143
+ }.to raise_error(ArgumentError, /HTTP client must be a Net::HTTP instance, Proc, or respond to :call/)
144
+ end
145
+ end
146
+ end
147
+
148
+ describe '#resolve_http_client (private method)' do
149
+ let(:uri) { URI.parse('https://api.example.com/test') }
150
+
151
+ context 'with Net::HTTP instance' do
152
+ let(:http_instance) { Net::HTTP.new('example.com', 80) }
153
+
154
+ it 'returns the instance directly' do
155
+ result = client.send(:resolve_http_client, http_instance, uri)
156
+ expect(result).to eq(http_instance)
157
+ end
158
+ end
159
+
160
+ context 'with Proc' do
161
+ let(:http_proc) { proc { |uri| Net::HTTP.new(uri.host, uri.port) } }
162
+
163
+ it 'calls the proc with the URI' do
164
+ result = client.send(:resolve_http_client, http_proc, uri)
165
+ expect(result).to be_a(Net::HTTP)
166
+ expect(result.address).to eq('api.example.com')
167
+ expect(result.port).to eq(443)
168
+ end
169
+ end
170
+
171
+ context 'with callable object' do
172
+ let(:callable) do
173
+ Class.new do
174
+ def call(uri)
175
+ Net::HTTP.new(uri.host, uri.port)
176
+ end
177
+ end.new
178
+ end
179
+
180
+ it 'calls the object with the URI' do
181
+ result = client.send(:resolve_http_client, callable, uri)
182
+ expect(result).to be_a(Net::HTTP)
183
+ expect(result.address).to eq('api.example.com')
184
+ expect(result.port).to eq(443)
185
+ end
186
+ end
187
+
188
+ context 'with invalid object' do
189
+ it 'raises an ArgumentError' do
190
+ expect {
191
+ client.send(:resolve_http_client, "invalid", uri)
192
+ }.to raise_error(ArgumentError, /HTTP client must be a Net::HTTP instance, Proc, or respond to :call/)
193
+ end
194
+ end
195
+ end
196
+
197
+ describe '#create_default_http_client (private method)' do
198
+ context 'with HTTPS URI' do
199
+ let(:uri) { URI.parse('https://api.example.com/test') }
200
+
201
+ it 'creates an HTTPS-enabled client' do
202
+ result = client.send(:create_default_http_client, uri)
203
+ expect(result).to be_a(Net::HTTP)
204
+ expect(result.address).to eq('api.example.com')
205
+ expect(result.port).to eq(443)
206
+ expect(result.use_ssl?).to be true
207
+ end
208
+ end
209
+
210
+ context 'with HTTP URI' do
211
+ let(:uri) { URI.parse('http://api.example.com/test') }
212
+
213
+ it 'creates an HTTP client' do
214
+ result = client.send(:create_default_http_client, uri)
215
+ expect(result).to be_a(Net::HTTP)
216
+ expect(result.address).to eq('api.example.com')
217
+ expect(result.port).to eq(80)
218
+ expect(result.use_ssl?).to be false
219
+ end
220
+ end
221
+ end
222
+ end
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
5
5
 
6
6
 
7
7
  RSpec.describe PCPServerSDK::Endpoints::CheckoutApiClient do
8
- let(:config) { double("PCPServerSDK::CommunicatorConfiguration", api_key: "", api_secret: "", host: 'https://api.example.com') }
8
+ let(:config) { mock_communicator_config }
9
9
  let(:client) { described_class.new(config) }
10
10
  let(:error_body) { PCPServerSDK::Models::ErrorResponse.new(
11
11
  error_id: '1',
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
5
5
 
6
6
 
7
7
  RSpec.describe PCPServerSDK::Endpoints::CommerceCaseApiClient do
8
- let(:config) { double("PCPServerSDK::CommunicatorConfiguration", api_key: "", api_secret: "", host: 'https://api.example.com') }
8
+ let(:config) { mock_communicator_config }
9
9
  let(:client) { described_class.new(config) }
10
10
  let(:error_body) {
11
11
  PCPServerSDK::Models::ErrorResponse.new(
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
5
5
 
6
6
 
7
7
  RSpec.describe PCPServerSDK::Endpoints::OrderManagementCheckoutActionsApiClient do
8
- let(:config) { double("PCPServerSDK::CommunicatorConfiguration", api_key: "", api_secret: "", host: 'https://api.example.com') }
8
+ let(:config) { mock_communicator_config }
9
9
  let(:client) { described_class.new(config) }
10
10
  let(:error_body) {
11
11
  PCPServerSDK::Models::ErrorResponse.new(
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
5
5
 
6
6
 
7
7
  RSpec.describe PCPServerSDK::Endpoints::PaymentExecutionApiClient do
8
- let(:config) { double("PCPServerSDK::CommunicatorConfiguration", api_key: "", api_secret: "", host: 'https://api.example.com') }
8
+ let(:config) { mock_communicator_config }
9
9
  let(:client) { described_class.new(config) }
10
10
  let(:error_body) {
11
11
  PCPServerSDK::Models::ErrorResponse.new(
@@ -5,7 +5,7 @@ require_relative '../../lib/PCP-server-Ruby-SDK.rb'
5
5
 
6
6
 
7
7
  RSpec.describe PCPServerSDK::Endpoints::PaymentInformationApiClient do
8
- let(:config) { double("PCPServerSDK::CommunicatorConfiguration", api_key: "", api_secret: "", host: 'https://api.example.com') }
8
+ let(:config) { mock_communicator_config }
9
9
  let(:client) { described_class.new(config) }
10
10
  let(:error_body) {
11
11
  PCPServerSDK::Models::ErrorResponse.new(
data/spec/spec_helper.rb CHANGED
@@ -25,4 +25,13 @@ RSpec.configure do |config|
25
25
  end
26
26
  end
27
27
 
28
+ # Helper method to create properly mocked CommunicatorConfiguration
29
+ def mock_communicator_config(api_key: '', api_secret: '', host: 'https://api.example.com', http_client: nil)
30
+ double('PCPServerSDK::CommunicatorConfiguration',
31
+ api_key: api_key,
32
+ api_secret: api_secret,
33
+ host: host,
34
+ http_client: http_client)
35
+ end
36
+
28
37
  require 'rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcp-server-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PAYONE GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-26 00:00:00.000000000 Z
11
+ date: 2025-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http
@@ -102,6 +102,7 @@ files:
102
102
  - lefthook.yml
103
103
  - lib/PCP-server-Ruby-SDK.rb
104
104
  - lib/PCP-server-Ruby-SDK/communicator_configuration.rb
105
+ - lib/PCP-server-Ruby-SDK/endpoints/authentication_api_client.rb
105
106
  - lib/PCP-server-Ruby-SDK/endpoints/base_api_client.rb
106
107
  - lib/PCP-server-Ruby-SDK/endpoints/checkout_api_client.rb
107
108
  - lib/PCP-server-Ruby-SDK/endpoints/commerce_case_api_client.rb
@@ -127,6 +128,7 @@ files:
127
128
  - lib/PCP-server-Ruby-SDK/models/applepay/apple_pay_payment_method.rb
128
129
  - lib/PCP-server-Ruby-SDK/models/applepay/apple_pay_payment_method_type.rb
129
130
  - lib/PCP-server-Ruby-SDK/models/applepay/apple_pay_payment_token.rb
131
+ - lib/PCP-server-Ruby-SDK/models/authentication_token.rb
130
132
  - lib/PCP-server-Ruby-SDK/models/authorization_mode.rb
131
133
  - lib/PCP-server-Ruby-SDK/models/avs_result.rb
132
134
  - lib/PCP-server-Ruby-SDK/models/bank_account_information.rb
@@ -278,6 +280,8 @@ files:
278
280
  - scripts.sh
279
281
  - sonar-project.properties
280
282
  - spec/communicator_configuration_spec.rb
283
+ - spec/endpoints/authentication_api_client_spec.rb
284
+ - spec/endpoints/base_api_client_spec.rb
281
285
  - spec/endpoints/checkout_api_client_spec.rb
282
286
  - spec/endpoints/commerce_case_api_client_spec.rb
283
287
  - spec/endpoints/order_management_checkout_actions_api_client_spec.rb
@@ -315,4 +319,21 @@ rubygems_version: 3.4.20
315
319
  signing_key:
316
320
  specification_version: 4
317
321
  summary: Commerce Platform API Ruby Gem
318
- test_files: []
322
+ test_files:
323
+ - spec/communicator_configuration_spec.rb
324
+ - spec/endpoints/authentication_api_client_spec.rb
325
+ - spec/endpoints/commerce_case_api_client_spec.rb
326
+ - spec/endpoints/payment_execution_api_client_spec.rb
327
+ - spec/endpoints/checkout_api_client_spec.rb
328
+ - spec/endpoints/payment_information_api_client_spec.rb
329
+ - spec/endpoints/base_api_client_spec.rb
330
+ - spec/endpoints/order_management_checkout_actions_api_client_spec.rb
331
+ - spec/errors/api_error_response_exception_spec.rb
332
+ - spec/errors/api_exception_spec.rb
333
+ - spec/errors/api_response_retrieval_exception_spec.rb
334
+ - spec/queries/get_checkouts_query_spec.rb
335
+ - spec/queries/get_commerce_cases_query_spec.rb
336
+ - spec/request_header_generator_spec.rb
337
+ - spec/spec_helper.rb
338
+ - spec/transformer/apple_pay_transformer_spec.rb
339
+ - spec/utils/server_meta_info_spec.rb