pcp-server-ruby-sdk 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb0118721663f462f5bc434e7b2df5d76e517f2865d03d666cd32dbce5133fca
4
- data.tar.gz: 37c389d8f6d02e865f4713f93b7d0745c232846acc797e697a1295de7921db43
3
+ metadata.gz: b8ce0d57a0a0e4d9c198eb972c3be51d325e4f12a54ec51d71dc12e84ad0b6d8
4
+ data.tar.gz: 5768198ed551baecf7a798f281a68e3134b783d49f8eb0848c64ea6cbb1714e3
5
5
  SHA512:
6
- metadata.gz: 4f2912be3416517cb213a8d50196879fe2fa60248d011d83d19bced6d1f4b6d20abbf279b59dd68f837dd1d8df0f243431b50c571a2012a2ae940ca264512b07
7
- data.tar.gz: 48c4c4540f71b982ca05b17c7e4d357835eee938b7164e059890a2dc85a906018a720201c5f3840fb0dc86494f25026beba0e7c5fcbb1108d1574f5f1c99c3ff
6
+ metadata.gz: 6d6b1ff0f33d0d2c138813a86300ad55f6be2763476de2b71448c340d2be00b14cb3bad7a99348452a683042cc6e5f94e8911dccfb7a18a5d1682e27bb77aace
7
+ data.tar.gz: aab39f7785eac2e22e312fe70764840809a74d9b2443d5542650feedd32b41109795c9799b6b4b40e66cb6228f21901823a40ae125d6ac6d86b1ed7f04f947a8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
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
+
1
29
  # [1.3.0](https://github.com/PAYONE-GmbH/PCP-ServerSDK-ruby/compare/v1.2.0...v1.3.0) (2025-07-10)
2
30
 
3
31
  ### Features
data/README.md CHANGED
@@ -113,6 +113,111 @@ When making a request any client may throw a `PCPServerSDK::Errors::ApiException
113
113
 
114
114
  Network errors are not wrap, you can should handle the standard `IOExeption`.
115
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
+
116
221
  ### Client Side
117
222
 
118
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.
@@ -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']
@@ -29,6 +97,9 @@ def run
29
97
  # commerce_case_api_client_example.run_get_one
30
98
  # commerce_case_api_client_example.run_update_one
31
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)
32
103
  end
33
104
 
34
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
- def initialize(api_key, api_secret, host)
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
@@ -9,6 +9,10 @@ module PCPServerSDK
9
9
  module Endpoints
10
10
  # Client for authentication token operations
11
11
  class AuthenticationApiClient < BaseApiClient
12
+ def initialize(config, http_client = nil)
13
+ super(config, http_client)
14
+ end
15
+
12
16
  def get_authentication_tokens(merchant_id, request_id = nil)
13
17
  raise TypeError, MERCHANT_ID_REQUIRED_ERROR if merchant_id.nil? || merchant_id.empty?
14
18
 
@@ -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
- def initialize(config)
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 = Net::HTTP.new(uri.host, uri.port)
37
- http.use_ssl = uri.scheme == 'https'
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)
@@ -11,8 +11,8 @@ module PCPServerSDK
11
11
  module Endpoints
12
12
 
13
13
  class CheckoutApiClient < BaseApiClient
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 checkout
@@ -10,8 +10,8 @@ module PCPServerSDK
10
10
  module Endpoints
11
11
 
12
12
  class CommerceCaseApiClient < 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 a commerce case
@@ -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
@@ -1,4 +1,4 @@
1
1
 
2
2
  module PCPServerSDK
3
- VERSION = '1.3.0'
3
+ VERSION = '1.3.1'
4
4
  end