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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/PCP-server-Ruby-SDK.gemspec +1 -1
- data/README.md +126 -0
- data/example-app/commerce_case_api_example.rb +9 -1
- data/example-app/example.rb +73 -1
- data/lib/PCP-server-Ruby-SDK/communicator_configuration.rb +6 -3
- data/lib/PCP-server-Ruby-SDK/endpoints/authentication_api_client.rb +33 -0
- data/lib/PCP-server-Ruby-SDK/endpoints/base_api_client.rb +59 -8
- data/lib/PCP-server-Ruby-SDK/endpoints/checkout_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/commerce_case_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/order_management_checkout_actions_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/endpoints/payment_information_api_client.rb +2 -2
- data/lib/PCP-server-Ruby-SDK/models/authentication_token.rb +189 -0
- data/lib/PCP-server-Ruby-SDK/version.rb +1 -1
- data/lib/PCP-server-Ruby-SDK.rb +2 -0
- data/package-lock.json +187 -187
- data/package.json +1 -1
- data/spec/communicator_configuration_spec.rb +27 -0
- data/spec/endpoints/authentication_api_client_spec.rb +78 -0
- data/spec/endpoints/base_api_client_spec.rb +222 -0
- data/spec/endpoints/checkout_api_client_spec.rb +1 -1
- data/spec/endpoints/commerce_case_api_client_spec.rb +1 -1
- data/spec/endpoints/order_management_checkout_actions_api_client_spec.rb +1 -1
- data/spec/endpoints/payment_execution_api_client_spec.rb +1 -1
- data/spec/endpoints/payment_information_api_client_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8ce0d57a0a0e4d9c198eb972c3be51d325e4f12a54ec51d71dc12e84ad0b6d8
|
4
|
+
data.tar.gz: 5768198ed551baecf7a798f281a68e3134b783d49f8eb0848c64ea6cbb1714e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d6b1ff0f33d0d2c138813a86300ad55f6be2763476de2b71448c340d2be00b14cb3bad7a99348452a683042cc6e5f94e8911dccfb7a18a5d1682e27bb77aace
|
7
|
+
data.tar.gz: aab39f7785eac2e22e312fe70764840809a74d9b2443d5542650feedd32b41109795c9799b6b4b40e66cb6228f21901823a40ae125d6ac6d86b1ed7f04f947a8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
## [1.3.1](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/compare/v0.0.6...v1.3.1) (2025-09-04)
|
2
|
+
|
3
|
+
### Bug Fixes
|
4
|
+
|
5
|
+
* fix: update version script to actually set the version ([9193d60c4e3f3160ef628c8e093573394a802bc4](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/9193d60c4e3f3160ef628c8e093573394a802bc4))
|
6
|
+
|
7
|
+
### Documentation
|
8
|
+
|
9
|
+
* docs: add section about custom http client to readme ([07992f759ba6fe9b435ce37a17eb3aeff537456c](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/07992f759ba6fe9b435ce37a17eb3aeff537456c))
|
10
|
+
* docs: clarify comment for category attribute in APIError class ([ccafb6db2bc474bb07a30a1fda7ff6e730a8137d](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/ccafb6db2bc474bb07a30a1fda7ff6e730a8137d))
|
11
|
+
* docs: improve comment clarity for tax_amount_per_unit attribute in OrderLineDetailsInput model ([37fcf28f22a1a9ccf93689c21c07f06d2e3249a8](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/37fcf28f22a1a9ccf93689c21c07f06d2e3249a8))
|
12
|
+
* docs: update docs ([a4b33ef94dc183847f5be0288c84312c0dd8cfba](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/a4b33ef94dc183847f5be0288c84312c0dd8cfba))
|
13
|
+
* docs: update readme ([39af578246533fda6b3bed100a4fbf66371885b7](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/39af578246533fda6b3bed100a4fbf66371885b7))
|
14
|
+
* docs: update README with new badge links and API version ([c69507cd4b9da665fb686576c0900570462fc1bf](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/c69507cd4b9da665fb686576c0900570462fc1bf))
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* feat: add apple pay transformer and tests ([110182da3735202d0d3ee2b6bde2f57739221d49](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/110182da3735202d0d3ee2b6bde2f57739221d49))
|
19
|
+
* feat: add auth client ([c8fd009b11a8ec3416a33ecab949ec2c51406e7e](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/c8fd009b11a8ec3416a33ecab949ec2c51406e7e))
|
20
|
+
* feat: add BusinessRelation class and update customer model to use it ([68ab9fc5c41aad7f3f967b75b1ecdd0ac02cba63](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/68ab9fc5c41aad7f3f967b75b1ecdd0ac02cba63))
|
21
|
+
* feat: add CustomerAccount class and integrate it into Customer class ([ee1600ec78d66498cc758b4c931f510dd3ffb4c7](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/ee1600ec78d66498cc758b4c931f510dd3ffb4c7))
|
22
|
+
* feat: add fraud_net_id attribute to RedirectPaymentProduct840SpecificInput model ([27ec17cce2fb42eb37116790ce2dd106502487c0](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/27ec17cce2fb42eb37116790ce2dd106502487c0))
|
23
|
+
* feat: add RecurringPaymentSequenceIndicator class and update CardRecurrenceDetails to use it ([e2507f4328a297dc700fa1635029a1599fa58101](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/e2507f4328a297dc700fa1635029a1599fa58101))
|
24
|
+
* feat: allow customization of http client ([98df1ad32cfa6956b3710f3b22dd6ad1cd61fa3c](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/98df1ad32cfa6956b3710f3b22dd6ad1cd61fa3c))
|
25
|
+
* feat: implement ActionType class and update MerchantAction to use it ([8e259dc45f4e20ea0a10a351a3abdc86926b91f1](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/8e259dc45f4e20ea0a10a351a3abdc86926b91f1))
|
26
|
+
* feat: implement api level 1.28.0 ([b26df0bc2da08cd900775c45bd64f5db120ede0a](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/b26df0bc2da08cd900775c45bd64f5db120ede0a))
|
27
|
+
* feat: implement AvsResult enum class and update CardFraudResults to use it ([c0a40cc08aa878afaae93851be1619907e7c5e86](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/c0a40cc08aa878afaae93851be1619907e7c5e86))
|
28
|
+
|
29
|
+
# [1.3.0](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/compare/v1.2.0...v1.3.0) (2025-07-10)
|
30
|
+
|
31
|
+
### Features
|
32
|
+
|
33
|
+
* feat: add auth client ([c8fd009b11a8ec3416a33ecab949ec2c51406e7e](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/commit/c8fd009b11a8ec3416a33ecab949ec2c51406e7e))
|
34
|
+
|
1
35
|
# [1.2.0](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/compare/v1.1.0...v1.2.0) (2025-05-26)
|
2
36
|
|
3
37
|
### Documentation
|
data/PCP-server-Ruby-SDK.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_development_dependency 'simplecov', '~> 0.22.0'
|
26
26
|
|
27
27
|
s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
|
28
|
-
s.test_files = `find
|
28
|
+
s.test_files = `find spec/*`.split("\n")
|
29
29
|
s.executables = []
|
30
30
|
s.require_paths = ["lib"]
|
31
31
|
end
|
data/README.md
CHANGED
@@ -19,6 +19,7 @@ This SDK requires Ruby 3.2 or later.
|
|
19
19
|
- [Installation](#installation)
|
20
20
|
- [Usage](#usage)
|
21
21
|
- [General](#general)
|
22
|
+
- [Authentication Token Retrieval](#authentication-token-retrieval)
|
22
23
|
- [Error Handling](#error-handling)
|
23
24
|
- [Client Side](#client-side)
|
24
25
|
- [Apple Pay](#apple-pay)
|
@@ -83,6 +84,26 @@ createCommerceCaseResponse = client.create_commerce_case_request('merchant_id',
|
|
83
84
|
|
84
85
|
The models directly map to the API as described in [PAYONE Commerce Platform API Reference](https://docs.payone.com/pcp/commerce-platform-api). For an in depth example you can take a look at the [demo app](#demo-app).
|
85
86
|
|
87
|
+
|
88
|
+
### Authentication Token Retrieval
|
89
|
+
|
90
|
+
To interact with certain client-side SDKs (such as the credit card tokenizer), you need to generate a short-lived authentication JWT token for your merchant. This token can be retrieved using the SDK as follows:
|
91
|
+
|
92
|
+
```rb
|
93
|
+
require 'pcp-server-ruby-sdk'
|
94
|
+
|
95
|
+
authentication_client = PCPServerSDK::Endpoints::AuthenticationApiClient.new(communicator_configuration)
|
96
|
+
token = authentication_client.get_authentication_tokens(merchant_id)
|
97
|
+
puts "JWT Token: #{token.token}"
|
98
|
+
puts "Token ID: #{token.id}"
|
99
|
+
puts "Created: #{token.creation_date}"
|
100
|
+
puts "Expires: #{token.expiration_date}"
|
101
|
+
```
|
102
|
+
|
103
|
+
This token can then be used for secure operations such as initializing the credit card tokenizer or other client-side SDKs that require merchant authentication. The token is valid for a limited time (10 minutes) and should be handled securely.
|
104
|
+
|
105
|
+
**Note:** The `get_authentication_tokens` method requires a valid `merchant_id`. Optionally, you can provide an `X-Request-ID` header for tracing requests.
|
106
|
+
|
86
107
|
### Error Handling
|
87
108
|
|
88
109
|
When making a request any client may throw a `PCPServerSDK::Errors::ApiException`. There two subtypes of this exception:
|
@@ -92,6 +113,111 @@ When making a request any client may throw a `PCPServerSDK::Errors::ApiException
|
|
92
113
|
|
93
114
|
Network errors are not wrap, you can should handle the standard `IOExeption`.
|
94
115
|
|
116
|
+
### HTTP Client Customization
|
117
|
+
|
118
|
+
The SDK allows you to customize the underlying HTTP client used for API requests. This provides flexibility to configure timeouts, SSL settings, proxies, and other HTTP-specific options according to your application's needs.
|
119
|
+
|
120
|
+
#### Global HTTP Client Configuration
|
121
|
+
|
122
|
+
You can set a global HTTP client that will be used by all API clients:
|
123
|
+
|
124
|
+
```rb
|
125
|
+
require 'pcp-server-ruby-sdk'
|
126
|
+
|
127
|
+
# Option 1: Using a custom Net::HTTP instance
|
128
|
+
custom_http = Net::HTTP.new('api.preprod.commerce.payone.com', 443)
|
129
|
+
custom_http.use_ssl = true
|
130
|
+
custom_http.read_timeout = 30
|
131
|
+
custom_http.open_timeout = 10
|
132
|
+
|
133
|
+
communicator_configuration = PCPServerSDK::CommunicatorConfiguration.new(
|
134
|
+
api_key,
|
135
|
+
api_secret,
|
136
|
+
'https://api.preprod.commerce.payone.com',
|
137
|
+
custom_http
|
138
|
+
)
|
139
|
+
|
140
|
+
# Option 2: Using a factory proc for dynamic client creation
|
141
|
+
http_factory = proc do |uri|
|
142
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
143
|
+
http.use_ssl = uri.scheme == 'https'
|
144
|
+
http.read_timeout = 60
|
145
|
+
http.open_timeout = 15
|
146
|
+
# Add custom headers, proxy settings, etc.
|
147
|
+
http
|
148
|
+
end
|
149
|
+
|
150
|
+
communicator_configuration = PCPServerSDK::CommunicatorConfiguration.new(
|
151
|
+
api_key,
|
152
|
+
api_secret,
|
153
|
+
'https://api.preprod.commerce.payone.com',
|
154
|
+
http_factory
|
155
|
+
)
|
156
|
+
|
157
|
+
# Option 3: Set after initialization
|
158
|
+
communicator_configuration.http_client = custom_http
|
159
|
+
```
|
160
|
+
|
161
|
+
#### Client-Specific HTTP Client Configuration
|
162
|
+
|
163
|
+
You can also set HTTP clients for individual API clients, which will override the global configuration:
|
164
|
+
|
165
|
+
```rb
|
166
|
+
require 'pcp-server-ruby-sdk'
|
167
|
+
|
168
|
+
# Create a specific HTTP client for this API client
|
169
|
+
commerce_case_http = Net::HTTP.new('api.preprod.commerce.payone.com', 443)
|
170
|
+
commerce_case_http.use_ssl = true
|
171
|
+
commerce_case_http.read_timeout = 45
|
172
|
+
|
173
|
+
# Pass it to the API client constructor
|
174
|
+
commerce_case_client = PCPServerSDK::Endpoints::CommerceCaseApiClient.new(
|
175
|
+
communicator_configuration,
|
176
|
+
commerce_case_http
|
177
|
+
)
|
178
|
+
|
179
|
+
# Or set it after initialization
|
180
|
+
commerce_case_client.http_client = commerce_case_http
|
181
|
+
```
|
182
|
+
|
183
|
+
#### Priority Logic
|
184
|
+
|
185
|
+
The SDK uses the following priority order when determining which HTTP client to use:
|
186
|
+
|
187
|
+
1. **Client-specific HTTP client** (set on individual API client instances)
|
188
|
+
2. **Global HTTP client** (set in CommunicatorConfiguration)
|
189
|
+
3. **Default HTTP client** (created automatically by the SDK)
|
190
|
+
|
191
|
+
#### HTTP Client Factory Pattern
|
192
|
+
|
193
|
+
For advanced use cases, you can provide a factory (Proc or any callable object) that creates HTTP clients dynamically:
|
194
|
+
|
195
|
+
```rb
|
196
|
+
# Factory that creates clients with different configurations based on the URI
|
197
|
+
adaptive_factory = proc do |uri|
|
198
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
199
|
+
http.use_ssl = uri.scheme == 'https'
|
200
|
+
|
201
|
+
# Configure based on environment or URI
|
202
|
+
if uri.host.include?('preprod')
|
203
|
+
http.read_timeout = 60 # Longer timeout for preprod
|
204
|
+
else
|
205
|
+
http.read_timeout = 30 # Standard timeout for production
|
206
|
+
end
|
207
|
+
|
208
|
+
http
|
209
|
+
end
|
210
|
+
|
211
|
+
communicator_configuration.http_client = adaptive_factory
|
212
|
+
```
|
213
|
+
|
214
|
+
This customization allows you to:
|
215
|
+
- Configure custom timeouts and connection settings
|
216
|
+
- Set up proxy configurations
|
217
|
+
- Add custom SSL/TLS settings
|
218
|
+
- Implement retry logic or circuit breakers
|
219
|
+
- Add request/response logging or monitoring
|
220
|
+
|
95
221
|
### Client Side
|
96
222
|
|
97
223
|
For most [payment methods](https://docs.payone.com/pcp/commerce-platform-payment-methods) some information from the client is needed, e.g. payment information given by Apple when a payment via ApplePay suceeds. PAYONE provides client side SDKs which helps you interact the third party payment providers. You can find the SDKs under the [PAYONE GitHub organization](https://github.com/PAYONE-GmbH). Either way ensure to never store or even send credit card information to your server. The PAYONE Commerce Platform never needs access to the credit card information. The client side is responsible for safely retrieving a credit card token. This token must be used with this SDK.
|
@@ -1,12 +1,20 @@
|
|
1
1
|
require_relative '../lib/PCP-server-Ruby-SDK.rb'
|
2
2
|
class CommerceCaseApiExample
|
3
|
-
attr_accessor :client, :merchant_id, :commerce_case_id
|
3
|
+
attr_accessor :client, :merchant_id, :commerce_case_id, :auth_client
|
4
4
|
|
5
5
|
def initialize(config)
|
6
6
|
@client = PCPServerSDK::Endpoints::CommerceCaseApiClient.new(config)
|
7
|
+
@auth_client = PCPServerSDK::Endpoints::AuthenticationApiClient.new(config)
|
7
8
|
@merchant_id = ENV['MERCHANT_ID']
|
8
9
|
@commerce_case_id = ENV['COMMERCE_CASE_ID']
|
9
10
|
end
|
11
|
+
def run_auth_token_example
|
12
|
+
token = @auth_client.get_authentication_tokens(@merchant_id)
|
13
|
+
puts "JWT Token: #{token.token}"
|
14
|
+
puts "Token ID: #{token.id}"
|
15
|
+
puts "Created: #{token.creation_date}"
|
16
|
+
puts "Expires: #{token.expiration_date}"
|
17
|
+
end
|
10
18
|
|
11
19
|
def run_post_one
|
12
20
|
payload = {}
|
data/example-app/example.rb
CHANGED
@@ -3,6 +3,74 @@
|
|
3
3
|
require_relative '../lib/PCP-server-Ruby-SDK.rb'
|
4
4
|
require_relative 'commerce_case_api_example'
|
5
5
|
|
6
|
+
def demonstrate_http_client_customization(api_key, api_secret)
|
7
|
+
puts "\n=== HTTP Client Customization Examples ==="
|
8
|
+
|
9
|
+
# Example 1: Global HTTP client with custom timeouts
|
10
|
+
puts "\n1. Global HTTP client with custom timeouts:"
|
11
|
+
custom_http = Net::HTTP.new('api.preprod.commerce.payone.com', 443)
|
12
|
+
custom_http.use_ssl = true
|
13
|
+
custom_http.read_timeout = 30
|
14
|
+
custom_http.open_timeout = 10
|
15
|
+
|
16
|
+
config_with_custom_http = PCPServerSDK::CommunicatorConfiguration.new(
|
17
|
+
api_key,
|
18
|
+
api_secret,
|
19
|
+
'https://api.preprod.commerce.payone.com',
|
20
|
+
custom_http
|
21
|
+
)
|
22
|
+
|
23
|
+
puts " - Read timeout: #{config_with_custom_http.http_client.read_timeout}s"
|
24
|
+
puts " - Open timeout: #{config_with_custom_http.http_client.open_timeout}s"
|
25
|
+
|
26
|
+
# Example 2: HTTP client factory with dynamic configuration
|
27
|
+
puts "\n2. HTTP client factory with dynamic configuration:"
|
28
|
+
http_factory = proc do |uri|
|
29
|
+
puts " - Creating HTTP client for: #{uri.host}:#{uri.port}"
|
30
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
31
|
+
http.use_ssl = uri.scheme == 'https'
|
32
|
+
http.read_timeout = 60
|
33
|
+
http.open_timeout = 15
|
34
|
+
http
|
35
|
+
end
|
36
|
+
|
37
|
+
config_with_factory = PCPServerSDK::CommunicatorConfiguration.new(
|
38
|
+
api_key,
|
39
|
+
api_secret,
|
40
|
+
'https://api.preprod.commerce.payone.com',
|
41
|
+
http_factory
|
42
|
+
)
|
43
|
+
|
44
|
+
puts " - Factory configured for dynamic client creation"
|
45
|
+
|
46
|
+
# Example 3: Client-specific HTTP client
|
47
|
+
puts "\n3. Client-specific HTTP client override:"
|
48
|
+
client_specific_http = Net::HTTP.new('api.preprod.commerce.payone.com', 443)
|
49
|
+
client_specific_http.use_ssl = true
|
50
|
+
client_specific_http.read_timeout = 45
|
51
|
+
|
52
|
+
commerce_case_client = PCPServerSDK::Endpoints::CommerceCaseApiClient.new(
|
53
|
+
config_with_custom_http,
|
54
|
+
client_specific_http
|
55
|
+
)
|
56
|
+
|
57
|
+
puts " - Client-specific timeout: #{commerce_case_client.http_client.read_timeout}s"
|
58
|
+
puts " - This overrides the global configuration"
|
59
|
+
|
60
|
+
# Example 4: Setting HTTP client after initialization
|
61
|
+
puts "\n4. Setting HTTP client after initialization:"
|
62
|
+
auth_client = PCPServerSDK::Endpoints::AuthenticationApiClient.new(config_with_custom_http)
|
63
|
+
|
64
|
+
post_init_http = Net::HTTP.new('api.preprod.commerce.payone.com', 443)
|
65
|
+
post_init_http.use_ssl = true
|
66
|
+
post_init_http.read_timeout = 20
|
67
|
+
|
68
|
+
auth_client.http_client = post_init_http
|
69
|
+
puts " - HTTP client set after initialization with #{auth_client.http_client.read_timeout}s timeout"
|
70
|
+
|
71
|
+
puts "\n=== HTTP Client Customization Examples Complete ==="
|
72
|
+
end
|
73
|
+
|
6
74
|
def run
|
7
75
|
api_key = ENV['API_KEY']
|
8
76
|
api_secret = ENV['API_SECRET']
|
@@ -26,8 +94,12 @@ def run
|
|
26
94
|
# commerce_case_api_client_example.run_post_one
|
27
95
|
# commerce_case_api_client_example.run_get_all
|
28
96
|
|
29
|
-
commerce_case_api_client_example.run_get_one
|
97
|
+
# commerce_case_api_client_example.run_get_one
|
30
98
|
# commerce_case_api_client_example.run_update_one
|
99
|
+
commerce_case_api_client_example.run_auth_token_example
|
100
|
+
|
101
|
+
# Demonstrate HTTP client customization
|
102
|
+
demonstrate_http_client_customization(api_key, api_secret)
|
31
103
|
end
|
32
104
|
|
33
105
|
run
|
@@ -2,15 +2,18 @@
|
|
2
2
|
module PCPServerSDK
|
3
3
|
class CommunicatorConfiguration
|
4
4
|
attr_reader :api_key, :api_secret, :host
|
5
|
-
|
5
|
+
attr_accessor :http_client
|
6
|
+
|
6
7
|
# The constructor
|
7
8
|
# @param [String] api_key
|
8
9
|
# @param [String] api_secret
|
9
10
|
# @param [String] host
|
10
|
-
|
11
|
+
# @param [Net::HTTP, Proc, nil] http_client Optional HTTP client instance or factory proc
|
12
|
+
def initialize(api_key, api_secret, host, http_client = nil)
|
11
13
|
@api_key = api_key
|
12
14
|
@api_secret = api_secret
|
13
15
|
@host = host
|
16
|
+
@http_client = http_client
|
14
17
|
end
|
15
|
-
end
|
18
|
+
end
|
16
19
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../errors/api_error_response_exception'
|
4
|
+
require_relative '../errors/api_response_retrieval_exception'
|
5
|
+
require_relative '../models/authentication_token'
|
6
|
+
require_relative 'base_api_client'
|
7
|
+
|
8
|
+
module PCPServerSDK
|
9
|
+
module Endpoints
|
10
|
+
# Client for authentication token operations
|
11
|
+
class AuthenticationApiClient < BaseApiClient
|
12
|
+
def initialize(config, http_client = nil)
|
13
|
+
super(config, http_client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_authentication_tokens(merchant_id, request_id = nil)
|
17
|
+
raise TypeError, MERCHANT_ID_REQUIRED_ERROR if merchant_id.nil? || merchant_id.empty?
|
18
|
+
|
19
|
+
url = URI.join(get_config.host, "/v1/#{merchant_id}/authentication-tokens")
|
20
|
+
|
21
|
+
request_init = {
|
22
|
+
method: 'POST',
|
23
|
+
headers: { 'Content-Type' => 'application/json' },
|
24
|
+
body: ''
|
25
|
+
}
|
26
|
+
request_init[:headers]['X-Request-ID'] = request_id unless request_id.nil?
|
27
|
+
|
28
|
+
response = make_api_call(url.to_s, request_init)
|
29
|
+
deserialize_json(response, PCPServerSDK::Models::AuthenticationToken)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -15,11 +15,13 @@ PAYLOAD_REQUIRED_ERROR = 'Payload is required'
|
|
15
15
|
|
16
16
|
module PCPServerSDK
|
17
17
|
module Endpoints
|
18
|
-
|
19
18
|
class BaseApiClient
|
20
|
-
|
19
|
+
attr_accessor :http_client
|
20
|
+
|
21
|
+
def initialize(config, http_client = nil)
|
21
22
|
@config = config
|
22
23
|
@request_header_generator = RequestHeaderGenerator.new(config)
|
24
|
+
@http_client = http_client
|
23
25
|
end
|
24
26
|
|
25
27
|
protected
|
@@ -33,13 +35,12 @@ module PCPServerSDK
|
|
33
35
|
# @param [Hash] request_init
|
34
36
|
def make_api_call(url, request_init)
|
35
37
|
uri = URI.parse(url)
|
36
|
-
http =
|
37
|
-
|
38
|
-
|
38
|
+
http = get_http_client(uri)
|
39
|
+
|
39
40
|
modified_request = @request_header_generator.generate_additional_request_headers(url, request_init || {})
|
40
|
-
|
41
|
+
|
41
42
|
request = build_http_request(uri, modified_request)
|
42
|
-
response = get_response(http, request)
|
43
|
+
response = get_response(http, request)
|
43
44
|
handle_error(response)
|
44
45
|
|
45
46
|
JSON.parse(response.body)
|
@@ -51,12 +52,62 @@ module PCPServerSDK
|
|
51
52
|
|
52
53
|
private
|
53
54
|
|
55
|
+
# Get the HTTP client with priority logic:
|
56
|
+
# 1. Client-specific http_client (instance variable)
|
57
|
+
# 2. Global http_client from configuration
|
58
|
+
# 3. Default Net::HTTP client
|
59
|
+
# @param [URI] uri
|
60
|
+
# @return [Net::HTTP]
|
61
|
+
def get_http_client(uri)
|
62
|
+
# Priority 1: Client-specific HTTP client
|
63
|
+
if @http_client
|
64
|
+
return resolve_http_client(@http_client, uri)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Priority 2: Global HTTP client from configuration
|
68
|
+
if @config.http_client
|
69
|
+
return resolve_http_client(@config.http_client, uri)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Priority 3: Default HTTP client
|
73
|
+
create_default_http_client(uri)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Resolve HTTP client from various input types
|
77
|
+
# @param [Net::HTTP, Proc, Object] client_or_factory
|
78
|
+
# @param [URI] uri
|
79
|
+
# @return [Net::HTTP]
|
80
|
+
def resolve_http_client(client_or_factory, uri)
|
81
|
+
case client_or_factory
|
82
|
+
when Net::HTTP
|
83
|
+
client_or_factory
|
84
|
+
when Proc
|
85
|
+
client_or_factory.call(uri)
|
86
|
+
else
|
87
|
+
# If it responds to call, treat it as a factory
|
88
|
+
if client_or_factory.respond_to?(:call)
|
89
|
+
client_or_factory.call(uri)
|
90
|
+
else
|
91
|
+
raise ArgumentError, "HTTP client must be a Net::HTTP instance, Proc, or respond to :call"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Create default HTTP client
|
97
|
+
# @param [URI] uri
|
98
|
+
# @return [Net::HTTP]
|
99
|
+
def create_default_http_client(uri)
|
100
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
101
|
+
http.use_ssl = uri.scheme == 'https'
|
102
|
+
http
|
103
|
+
end
|
104
|
+
|
54
105
|
# Get the response
|
55
106
|
# @param [Net::HTTP] http
|
56
107
|
# @param [Net::HTTP::Request] request
|
57
108
|
# @return [Net::HTTP::Response]
|
58
109
|
def get_response(http, request)
|
59
|
-
http.request(request)
|
110
|
+
http.request(request)
|
60
111
|
end
|
61
112
|
|
62
113
|
def handle_error(response)
|
@@ -10,8 +10,8 @@ module PCPServerSDK
|
|
10
10
|
module Endpoints
|
11
11
|
|
12
12
|
class OrderManagementCheckoutActionsApiClient < BaseApiClient
|
13
|
-
def initialize(config)
|
14
|
-
super(config)
|
13
|
+
def initialize(config, http_client = nil)
|
14
|
+
super(config, http_client)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Create an order
|
@@ -13,8 +13,8 @@ module PCPServerSDK
|
|
13
13
|
class PaymentExecutionApiClient < BaseApiClient
|
14
14
|
PAYMENT_EXECUTION_ID_REQUIRED_ERROR = 'Payment Execution ID is required'
|
15
15
|
|
16
|
-
def initialize(config)
|
17
|
-
super(config)
|
16
|
+
def initialize(config, http_client = nil)
|
17
|
+
super(config, http_client)
|
18
18
|
end
|
19
19
|
|
20
20
|
# Create a payment
|
@@ -11,8 +11,8 @@ module PCPServerSDK
|
|
11
11
|
class PaymentInformationApiClient < BaseApiClient
|
12
12
|
PAYMENT_INFORMATION_ID_REQUIRED_ERROR = 'Payment Information ID is required'
|
13
13
|
|
14
|
-
def initialize(config)
|
15
|
-
super(config)
|
14
|
+
def initialize(config, http_client = nil)
|
15
|
+
super(config, http_client)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Create a payment information
|