onlinepayments-sdk-ruby 4.15.0 → 4.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onlinepayments/sdk/communicator.rb +10 -2
- data/lib/onlinepayments/sdk/defaultimpl/default_connection.rb +75 -9
- data/lib/onlinepayments/sdk/domain/card_payment_method_specific_output.rb +4 -0
- data/lib/onlinepayments/sdk/domain/redirect_payment_product5408_specific_input.rb +4 -0
- data/lib/onlinepayments/sdk/multipart_form_data_object.rb +44 -0
- data/lib/onlinepayments/sdk/multipart_form_data_request.rb +9 -0
- data/lib/onlinepayments/sdk/uploadable_file.rb +30 -0
- data/onlinepayments-sdk-ruby.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e68d841d58a8709600390682acb7d45a026ce6996b259bb37291a63d84078ba
|
4
|
+
data.tar.gz: 99c0448333f7ccdacd4fd945b6d712e075dcb39ad27f4d541f66ddbc1558fad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9caf954ae7682487cfd861661aacf9c504bd21cc63bbb0c0deb526b434df8778cd0ba9483104a1875fd7e356c1198a6885bbc749eda4409b3b917853376b43eb
|
7
|
+
data.tar.gz: da2a8e03c1ee39abab4e5713b01f9e175a8213fe5efddfb8d8fc641ccecfb03fffcf98a60ed0665c8a3d8dcbaaa92916c0105db1daaf125aee4771c06bd6a754
|
@@ -104,7 +104,8 @@ module OnlinePayments::SDK
|
|
104
104
|
# @param relative_path [String] Path relative to the API endpoint
|
105
105
|
# @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] Optional array of request headers
|
106
106
|
# @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] Optional request parameters
|
107
|
-
# @param request_body [OnlinePayments::SDK::DataObject
|
107
|
+
# @param request_body [OnlinePayments::SDK::DataObject, OnlinePayments::SDK::MultipartFormDataObject, OnlinePayments::SDK::MultipartFormDataRequest]
|
108
|
+
# The optional request body
|
108
109
|
# @param response_type [Type] The response type.
|
109
110
|
# @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
|
110
111
|
# @return The response of the POST request as the given response type
|
@@ -119,7 +120,14 @@ module OnlinePayments::SDK
|
|
119
120
|
request_headers ||= []
|
120
121
|
|
121
122
|
body = nil
|
122
|
-
if request_body
|
123
|
+
if request_body.is_a? MultipartFormDataObject
|
124
|
+
request_headers.push(RequestHeader.new('Content-Type', request_body.content_type))
|
125
|
+
body = request_body
|
126
|
+
elsif request_body.is_a? MultipartFormDataRequest
|
127
|
+
multipart = request_body.to_multipart_form_data_object
|
128
|
+
request_headers.push(RequestHeader.new('Content-Type', multipart.content_type))
|
129
|
+
body = multipart
|
130
|
+
elsif request_body
|
123
131
|
request_headers.push(RequestHeader.new('Content-Type', 'application/json'))
|
124
132
|
body = @marshaller.marshal(request_body)
|
125
133
|
else
|
@@ -19,6 +19,7 @@ module OnlinePayments::SDK
|
|
19
19
|
using RefineHTTPClient
|
20
20
|
|
21
21
|
CONTENT_TYPE = 'Content-Type'.freeze
|
22
|
+
X_REQUEST_ID_HEADER = 'X-Request-Id'.freeze
|
22
23
|
JSON_CONTENT_TYPE = 'application/json'.freeze
|
23
24
|
|
24
25
|
# @param args [Hash] the parameters to initialize the connection with
|
@@ -144,12 +145,16 @@ module OnlinePayments::SDK
|
|
144
145
|
# @param method [String] 'GET', 'DELETE', 'POST' or 'PUT' depending on the HTTP method being used.
|
145
146
|
# @param uri [URI::HTTP] full URI of the location the request is targeted at, including query parameters.
|
146
147
|
# @param request_headers [Array<OnlinePayments::SDK::RequestHeader>] list of headers that should be used as HTTP headers in the request.
|
147
|
-
# @param body [String] request body.
|
148
|
+
# @param body [String, OnlinePayments::SDK::MultipartFormDataObject] request body.
|
148
149
|
# @yield (Integer, Array<OnlinePayments::SDK::ResponseHeader>, IO) The status code, headers and body of the response.
|
149
150
|
# @raise [OnlinePayments::SDK::CommunicationException] when communication with the Online Payments platform was not successful.
|
150
151
|
def request(method, uri, request_headers, body = nil)
|
151
152
|
request_headers = convert_from_headers(request_headers)
|
152
153
|
request_id = SecureRandom.uuid
|
154
|
+
|
155
|
+
# set X-Request-Id for better traceability
|
156
|
+
request_headers[X_REQUEST_ID_HEADER] = request_id
|
157
|
+
|
153
158
|
content_type = request_headers[CONTENT_TYPE]
|
154
159
|
|
155
160
|
info = { headers: request_headers, content_type: content_type }
|
@@ -163,14 +168,29 @@ module OnlinePayments::SDK
|
|
163
168
|
response_status_code = nil
|
164
169
|
response_content_type = nil
|
165
170
|
response_body = ''
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
171
|
+
|
172
|
+
if body.is_a? OnlinePayments::SDK::MultipartFormDataObject
|
173
|
+
multipart_request(method, uri, request_headers, body) do |status_code, headers, r_content_type, r_body|
|
174
|
+
response_headers = headers
|
175
|
+
response_status_code = status_code
|
176
|
+
response_content_type = r_content_type
|
177
|
+
unless binary_content_type? response_content_type
|
178
|
+
response_body = r_body.read.force_encoding('UTF-8')
|
179
|
+
r_body = StringIO.new(response_body)
|
180
|
+
end
|
181
|
+
|
182
|
+
yield status_code, headers, r_body
|
183
|
+
end
|
184
|
+
else
|
185
|
+
raw_request(method, uri, request_headers, body) do |status_code, headers, r_content_type, r_body|
|
186
|
+
response_headers = headers
|
187
|
+
response_status_code = status_code
|
188
|
+
response_content_type = r_content_type
|
189
|
+
response_body = r_body.read.force_encoding('UTF-8')
|
190
|
+
r_body = StringIO.new(response_body)
|
191
|
+
|
192
|
+
yield status_code, headers, r_body
|
193
|
+
end
|
174
194
|
end
|
175
195
|
|
176
196
|
log_response(request_id, response_status_code, start_time,
|
@@ -290,6 +310,52 @@ module OnlinePayments::SDK
|
|
290
310
|
pipe.close
|
291
311
|
end
|
292
312
|
end
|
313
|
+
|
314
|
+
# Makes a request using the specified method
|
315
|
+
#
|
316
|
+
# Yields a status code, an array of {OnlinePayments::SDK::ResponseHeader},
|
317
|
+
# the content_type and body
|
318
|
+
def multipart_request(method, uri, headers, body = nil)
|
319
|
+
unless body.is_a? OnlinePayments::SDK::MultipartFormDataObject
|
320
|
+
raise ArgumentError, 'body should be a MultipartFormDataObject'
|
321
|
+
end
|
322
|
+
|
323
|
+
if method != 'post' && method != 'put'
|
324
|
+
raise ArgumentError, "method #{method} is not supported"
|
325
|
+
end
|
326
|
+
|
327
|
+
connection = @http_client.send method + '_async',
|
328
|
+
uri,
|
329
|
+
body: multipart_request_body(body),
|
330
|
+
header: headers
|
331
|
+
|
332
|
+
response = connection.pop
|
333
|
+
pipe = response.content
|
334
|
+
response_headers = convert_to_sdk_response_headers(response.headers)
|
335
|
+
|
336
|
+
begin
|
337
|
+
yield response.status_code, response_headers, response.content_type, pipe
|
338
|
+
ensure
|
339
|
+
pipe.close
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
# Creates a request body for the multipart request
|
344
|
+
def multipart_request_body( body )
|
345
|
+
request_body = []
|
346
|
+
body.files.each do |k, v|
|
347
|
+
request_body.push :content => v.content,
|
348
|
+
'Content-Type' => v.content_type,
|
349
|
+
'Content-Disposition' => "form-data; name=\"#{k}\"; filename=\"#{v.file_name}\"",
|
350
|
+
'Content-Transfer-Encoding' => 'binary'
|
351
|
+
end
|
352
|
+
|
353
|
+
body.values.each do |k, v|
|
354
|
+
request_body << { :content => v,
|
355
|
+
'Content-Disposition' => "form-data; name=\"#{k}\"" }
|
356
|
+
end
|
357
|
+
request_body
|
358
|
+
end
|
293
359
|
end
|
294
360
|
end
|
295
361
|
end
|
@@ -22,6 +22,7 @@ module OnlinePayments::SDK
|
|
22
22
|
# @attr [OnlinePayments::SDK::Domain::ExternalTokenLinked] external_token_linked
|
23
23
|
# @attr [OnlinePayments::SDK::Domain::CardFraudResults] fraud_results
|
24
24
|
# @attr [String] initial_scheme_transaction_id
|
25
|
+
# @attr [String] payment_account_reference
|
25
26
|
# @attr [String] payment_option
|
26
27
|
# @attr [OnlinePayments::SDK::Domain::PaymentProduct3208SpecificOutput] payment_product3208_specific_output
|
27
28
|
# @attr [OnlinePayments::SDK::Domain::PaymentProduct3209SpecificOutput] payment_product3209_specific_output
|
@@ -38,6 +39,7 @@ module OnlinePayments::SDK
|
|
38
39
|
attr_accessor :external_token_linked
|
39
40
|
attr_accessor :fraud_results
|
40
41
|
attr_accessor :initial_scheme_transaction_id
|
42
|
+
attr_accessor :payment_account_reference
|
41
43
|
attr_accessor :payment_option
|
42
44
|
attr_accessor :payment_product3208_specific_output
|
43
45
|
attr_accessor :payment_product3209_specific_output
|
@@ -57,6 +59,7 @@ module OnlinePayments::SDK
|
|
57
59
|
hash['externalTokenLinked'] = @external_token_linked.to_h if @external_token_linked
|
58
60
|
hash['fraudResults'] = @fraud_results.to_h if @fraud_results
|
59
61
|
hash['initialSchemeTransactionId'] = @initial_scheme_transaction_id unless @initial_scheme_transaction_id.nil?
|
62
|
+
hash['paymentAccountReference'] = @payment_account_reference unless @payment_account_reference.nil?
|
60
63
|
hash['paymentOption'] = @payment_option unless @payment_option.nil?
|
61
64
|
hash['paymentProduct3208SpecificOutput'] = @payment_product3208_specific_output.to_h if @payment_product3208_specific_output
|
62
65
|
hash['paymentProduct3209SpecificOutput'] = @payment_product3209_specific_output.to_h if @payment_product3209_specific_output
|
@@ -92,6 +95,7 @@ module OnlinePayments::SDK
|
|
92
95
|
@fraud_results = OnlinePayments::SDK::Domain::CardFraudResults.new_from_hash(hash['fraudResults'])
|
93
96
|
end
|
94
97
|
@initial_scheme_transaction_id = hash['initialSchemeTransactionId'] if hash.key? 'initialSchemeTransactionId'
|
98
|
+
@payment_account_reference = hash['paymentAccountReference'] if hash.key? 'paymentAccountReference'
|
95
99
|
@payment_option = hash['paymentOption'] if hash.key? 'paymentOption'
|
96
100
|
if hash.key? 'paymentProduct3208SpecificOutput'
|
97
101
|
raise TypeError, "value '%s' is not a Hash" % [hash['paymentProduct3208SpecificOutput']] unless hash['paymentProduct3208SpecificOutput'].is_a? Hash
|
@@ -8,13 +8,16 @@ module OnlinePayments::SDK
|
|
8
8
|
module Domain
|
9
9
|
|
10
10
|
# @attr [OnlinePayments::SDK::Domain::CustomerBankAccount] customer_bank_account
|
11
|
+
# @attr [true/false] instant_payment_only
|
11
12
|
class RedirectPaymentProduct5408SpecificInput < OnlinePayments::SDK::DataObject
|
12
13
|
attr_accessor :customer_bank_account
|
14
|
+
attr_accessor :instant_payment_only
|
13
15
|
|
14
16
|
# @return (Hash)
|
15
17
|
def to_h
|
16
18
|
hash = super
|
17
19
|
hash['customerBankAccount'] = @customer_bank_account.to_h if @customer_bank_account
|
20
|
+
hash['instantPaymentOnly'] = @instant_payment_only unless @instant_payment_only.nil?
|
18
21
|
hash
|
19
22
|
end
|
20
23
|
|
@@ -24,6 +27,7 @@ module OnlinePayments::SDK
|
|
24
27
|
raise TypeError, "value '%s' is not a Hash" % [hash['customerBankAccount']] unless hash['customerBankAccount'].is_a? Hash
|
25
28
|
@customer_bank_account = OnlinePayments::SDK::Domain::CustomerBankAccount.new_from_hash(hash['customerBankAccount'])
|
26
29
|
end
|
30
|
+
@instant_payment_only = hash['instantPaymentOnly'] if hash.key? 'instantPaymentOnly'
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module OnlinePayments::SDK
|
4
|
+
|
5
|
+
# A representation of a multipart/form-data object
|
6
|
+
class MultipartFormDataObject
|
7
|
+
def initialize
|
8
|
+
@boundary = SecureRandom.uuid
|
9
|
+
@content_type = 'multipart/form-data; boundary=' + @boundary
|
10
|
+
@values = {}
|
11
|
+
@files = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :boundary
|
15
|
+
attr_reader :content_type
|
16
|
+
attr_reader :values
|
17
|
+
attr_reader :files
|
18
|
+
|
19
|
+
def add_value(parameter_name, value)
|
20
|
+
if parameter_name.nil? || parameter_name.strip.empty?
|
21
|
+
raise ArgumentError, 'parameter_name is required'
|
22
|
+
end
|
23
|
+
raise ArgumentError, 'value is required' if value.nil?
|
24
|
+
if @values.include?(parameter_name) || @files.include?(parameter_name)
|
25
|
+
raise ArgumentError, 'duplicate parameterName: ' + parameter_name
|
26
|
+
end
|
27
|
+
|
28
|
+
@values[parameter_name] = value
|
29
|
+
end
|
30
|
+
|
31
|
+
# Adds a file to the multipart Form Data Object
|
32
|
+
def add_file(parameter_name, uploadable_file)
|
33
|
+
if parameter_name.nil? || parameter_name.strip.empty?
|
34
|
+
raise ArgumentError, 'parameter_name is required'
|
35
|
+
end
|
36
|
+
raise ArgumentError, 'uploadable_file is required' if uploadable_file.nil?
|
37
|
+
if @values.include?(parameter_name) || @files.include?(parameter_name)
|
38
|
+
raise ArgumentError, 'duplicate parameterName: ' + parameter_name
|
39
|
+
end
|
40
|
+
|
41
|
+
@files[parameter_name] = uploadable_file
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module OnlinePayments::SDK
|
2
|
+
|
3
|
+
# A file that can be uploaded
|
4
|
+
#
|
5
|
+
# The allowed forms of content are defined by the Connection implementation
|
6
|
+
# The default implementation supports file paths and IO objects.
|
7
|
+
#
|
8
|
+
# @attr_reader [String] file_name The name of the file.
|
9
|
+
# @attr_reader [String, IO] content The file's content.
|
10
|
+
# @attr_reader [String] content_type The file's content type.
|
11
|
+
# @attr_reader [Integer] content_length The file's content length, or -1 if not known.
|
12
|
+
class UploadableFile
|
13
|
+
|
14
|
+
def initialize(file_name, content, content_type, content_length=-1)
|
15
|
+
raise ArgumentError.new("file_name is required") if file_name.nil? or !file_name.strip
|
16
|
+
raise ArgumentError.new("content is required") if content.nil?
|
17
|
+
raise ArgumentError.new("content_type is required") if content_type.nil? or !content_type.strip
|
18
|
+
|
19
|
+
@file_name = file_name
|
20
|
+
@content = content
|
21
|
+
@content_type = content_type
|
22
|
+
@content_length = [content_length, -1].max
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :file_name
|
26
|
+
attr_reader :content
|
27
|
+
attr_reader :content_type
|
28
|
+
attr_reader :content_length
|
29
|
+
end
|
30
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'onlinepayments-sdk-ruby'
|
3
|
-
spec.version = '4.
|
3
|
+
spec.version = '4.17.0'
|
4
4
|
spec.authors = ['Worldline Direct support team']
|
5
5
|
spec.email = ['82139942+worldline-direct-support-team@users.noreply.github.com']
|
6
6
|
spec.summary = %q{SDK to communicate with the Online Payments platform using the Online Payments Server API}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onlinepayments-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Worldline Direct support team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -416,6 +416,8 @@ files:
|
|
416
416
|
- lib/onlinepayments/sdk/merchant/tokens/tokens_client.rb
|
417
417
|
- lib/onlinepayments/sdk/meta_data_provider.rb
|
418
418
|
- lib/onlinepayments/sdk/modules.rb
|
419
|
+
- lib/onlinepayments/sdk/multipart_form_data_object.rb
|
420
|
+
- lib/onlinepayments/sdk/multipart_form_data_request.rb
|
419
421
|
- lib/onlinepayments/sdk/not_found_exception.rb
|
420
422
|
- lib/onlinepayments/sdk/param_request.rb
|
421
423
|
- lib/onlinepayments/sdk/payment_platform_exception.rb
|
@@ -426,6 +428,7 @@ files:
|
|
426
428
|
- lib/onlinepayments/sdk/request_param.rb
|
427
429
|
- lib/onlinepayments/sdk/response_exception.rb
|
428
430
|
- lib/onlinepayments/sdk/response_header.rb
|
431
|
+
- lib/onlinepayments/sdk/uploadable_file.rb
|
429
432
|
- lib/onlinepayments/sdk/validation_exception.rb
|
430
433
|
- lib/onlinepayments/sdk/webhooks.rb
|
431
434
|
- lib/onlinepayments/sdk/webhooks/api_version_mismatch_exception.rb
|