acquiring-sdk-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +140 -0
  5. data/Rakefile +34 -0
  6. data/acquiring-sdk-ruby.gemspec +30 -0
  7. data/lib/worldline/acquiring/sdk/api_resource.rb +53 -0
  8. data/lib/worldline/acquiring/sdk/authentication/authenticator.rb +21 -0
  9. data/lib/worldline/acquiring/sdk/authentication/authorization_type.rb +17 -0
  10. data/lib/worldline/acquiring/sdk/authentication/oauth2_authenticator.rb +142 -0
  11. data/lib/worldline/acquiring/sdk/authentication/oauth2_exception.rb +15 -0
  12. data/lib/worldline/acquiring/sdk/authentication.rb +1 -0
  13. data/lib/worldline/acquiring/sdk/call_context.rb +9 -0
  14. data/lib/worldline/acquiring/sdk/client.rb +69 -0
  15. data/lib/worldline/acquiring/sdk/communication/communication_exception.rb +21 -0
  16. data/lib/worldline/acquiring/sdk/communication/connection.rb +50 -0
  17. data/lib/worldline/acquiring/sdk/communication/default_connection.rb +429 -0
  18. data/lib/worldline/acquiring/sdk/communication/metadata_provider.rb +162 -0
  19. data/lib/worldline/acquiring/sdk/communication/multipart_form_data_object.rb +54 -0
  20. data/lib/worldline/acquiring/sdk/communication/multipart_form_data_request.rb +15 -0
  21. data/lib/worldline/acquiring/sdk/communication/not_found_exception.rb +21 -0
  22. data/lib/worldline/acquiring/sdk/communication/param_request.rb +16 -0
  23. data/lib/worldline/acquiring/sdk/communication/pooled_connection.rb +28 -0
  24. data/lib/worldline/acquiring/sdk/communication/request_header.rb +64 -0
  25. data/lib/worldline/acquiring/sdk/communication/request_param.rb +30 -0
  26. data/lib/worldline/acquiring/sdk/communication/response_exception.rb +58 -0
  27. data/lib/worldline/acquiring/sdk/communication/response_header.rb +80 -0
  28. data/lib/worldline/acquiring/sdk/communication.rb +1 -0
  29. data/lib/worldline/acquiring/sdk/communicator.rb +506 -0
  30. data/lib/worldline/acquiring/sdk/communicator_configuration.rb +197 -0
  31. data/lib/worldline/acquiring/sdk/domain/data_object.rb +34 -0
  32. data/lib/worldline/acquiring/sdk/domain/shopping_cart_extension.rb +62 -0
  33. data/lib/worldline/acquiring/sdk/domain/uploadable_file.rb +35 -0
  34. data/lib/worldline/acquiring/sdk/domain.rb +1 -0
  35. data/lib/worldline/acquiring/sdk/factory.rb +183 -0
  36. data/lib/worldline/acquiring/sdk/json/default_marshaller.rb +36 -0
  37. data/lib/worldline/acquiring/sdk/json/marshaller.rb +29 -0
  38. data/lib/worldline/acquiring/sdk/json/marshaller_syntax_exception.rb +11 -0
  39. data/lib/worldline/acquiring/sdk/json.rb +1 -0
  40. data/lib/worldline/acquiring/sdk/logging/communicator_logger.rb +26 -0
  41. data/lib/worldline/acquiring/sdk/logging/log_message_builder.rb +91 -0
  42. data/lib/worldline/acquiring/sdk/logging/logging_capable.rb +19 -0
  43. data/lib/worldline/acquiring/sdk/logging/obfuscation/body_obfuscator.rb +101 -0
  44. data/lib/worldline/acquiring/sdk/logging/obfuscation/header_obfuscator.rb +54 -0
  45. data/lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_capable.rb +23 -0
  46. data/lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_rule.rb +49 -0
  47. data/lib/worldline/acquiring/sdk/logging/obfuscation.rb +1 -0
  48. data/lib/worldline/acquiring/sdk/logging/request_log_message_builder.rb +52 -0
  49. data/lib/worldline/acquiring/sdk/logging/response_log_message_builder.rb +43 -0
  50. data/lib/worldline/acquiring/sdk/logging/ruby_communicator_logger.rb +63 -0
  51. data/lib/worldline/acquiring/sdk/logging/stdout_communicator_logger.rb +33 -0
  52. data/lib/worldline/acquiring/sdk/logging.rb +1 -0
  53. data/lib/worldline/acquiring/sdk/proxy_configuration.rb +76 -0
  54. data/lib/worldline/acquiring/sdk/v1/acquirer/acquirer_client.rb +35 -0
  55. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/accountverifications/account_verifications_client.rb +60 -0
  56. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/accountverifications.rb +4 -0
  57. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/dynamiccurrencyconversion/dynamic_currency_conversion_client.rb +60 -0
  58. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/dynamiccurrencyconversion.rb +4 -0
  59. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/merchant_client.rb +66 -0
  60. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/payments/get_payment_status_params.rb +34 -0
  61. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/payments/payments_client.rb +224 -0
  62. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/payments.rb +4 -0
  63. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/refunds/get_refund_params.rb +34 -0
  64. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/refunds/refunds_client.rb +157 -0
  65. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/refunds.rb +4 -0
  66. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/technicalreversals/technical_reversals_client.rb +64 -0
  67. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant/technicalreversals.rb +4 -0
  68. data/lib/worldline/acquiring/sdk/v1/acquirer/merchant.rb +4 -0
  69. data/lib/worldline/acquiring/sdk/v1/acquirer.rb +4 -0
  70. data/lib/worldline/acquiring/sdk/v1/api_exception.rb +63 -0
  71. data/lib/worldline/acquiring/sdk/v1/authorization_exception.rb +23 -0
  72. data/lib/worldline/acquiring/sdk/v1/domain/address_verification_data.rb +41 -0
  73. data/lib/worldline/acquiring/sdk/v1/domain/amount_data.rb +48 -0
  74. data/lib/worldline/acquiring/sdk/v1/domain/api_account_verification_request.rb +70 -0
  75. data/lib/worldline/acquiring/sdk/v1/domain/api_account_verification_response.rb +87 -0
  76. data/lib/worldline/acquiring/sdk/v1/domain/api_action_response.rb +71 -0
  77. data/lib/worldline/acquiring/sdk/v1/domain/api_action_response_for_refund.rb +71 -0
  78. data/lib/worldline/acquiring/sdk/v1/domain/api_capture_request.rb +75 -0
  79. data/lib/worldline/acquiring/sdk/v1/domain/api_capture_request_for_refund.rb +43 -0
  80. data/lib/worldline/acquiring/sdk/v1/domain/api_increment_request.rb +61 -0
  81. data/lib/worldline/acquiring/sdk/v1/domain/api_increment_response.rb +43 -0
  82. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_error_response.rb +62 -0
  83. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_refund_request.rb +77 -0
  84. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_request.rb +95 -0
  85. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_resource.rb +103 -0
  86. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_response.rb +126 -0
  87. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_reversal_request.rb +61 -0
  88. data/lib/worldline/acquiring/sdk/v1/domain/api_payment_summary_for_response.rb +66 -0
  89. data/lib/worldline/acquiring/sdk/v1/domain/api_references_for_responses.rb +48 -0
  90. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_request.rb +88 -0
  91. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_resource.rb +110 -0
  92. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_response.rb +133 -0
  93. data/lib/worldline/acquiring/sdk/v1/domain/api_refund_summary_for_response.rb +66 -0
  94. data/lib/worldline/acquiring/sdk/v1/domain/api_reversal_response.rb +36 -0
  95. data/lib/worldline/acquiring/sdk/v1/domain/api_technical_reversal_request.rb +50 -0
  96. data/lib/worldline/acquiring/sdk/v1/domain/api_technical_reversal_response.rb +62 -0
  97. data/lib/worldline/acquiring/sdk/v1/domain/card_data_for_dcc.rb +48 -0
  98. data/lib/worldline/acquiring/sdk/v1/domain/card_on_file_data.rb +52 -0
  99. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data.rb +114 -0
  100. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_refund.rb +82 -0
  101. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_resource.rb +43 -0
  102. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_response.rb +52 -0
  103. data/lib/worldline/acquiring/sdk/v1/domain/card_payment_data_for_verification.rb +91 -0
  104. data/lib/worldline/acquiring/sdk/v1/domain/dcc_data.rb +55 -0
  105. data/lib/worldline/acquiring/sdk/v1/domain/dcc_proposal.rb +60 -0
  106. data/lib/worldline/acquiring/sdk/v1/domain/e_commerce_data.rb +52 -0
  107. data/lib/worldline/acquiring/sdk/v1/domain/e_commerce_data_for_account_verification.rb +45 -0
  108. data/lib/worldline/acquiring/sdk/v1/domain/e_commerce_data_for_response.rb +41 -0
  109. data/lib/worldline/acquiring/sdk/v1/domain/get_dcc_rate_request.rb +75 -0
  110. data/lib/worldline/acquiring/sdk/v1/domain/get_dcc_rate_response.rb +57 -0
  111. data/lib/worldline/acquiring/sdk/v1/domain/initial_card_on_file_data.rb +41 -0
  112. data/lib/worldline/acquiring/sdk/v1/domain/merchant_data.rb +76 -0
  113. data/lib/worldline/acquiring/sdk/v1/domain/network_token_data.rb +41 -0
  114. data/lib/worldline/acquiring/sdk/v1/domain/payment_references.rb +48 -0
  115. data/lib/worldline/acquiring/sdk/v1/domain/plain_card_data.rb +48 -0
  116. data/lib/worldline/acquiring/sdk/v1/domain/point_of_sale_data.rb +34 -0
  117. data/lib/worldline/acquiring/sdk/v1/domain/point_of_sale_data_for_dcc.rb +41 -0
  118. data/lib/worldline/acquiring/sdk/v1/domain/rate_data.rb +64 -0
  119. data/lib/worldline/acquiring/sdk/v1/domain/sub_operation.rb +94 -0
  120. data/lib/worldline/acquiring/sdk/v1/domain/sub_operation_for_refund.rb +87 -0
  121. data/lib/worldline/acquiring/sdk/v1/domain/subsequent_card_on_file_data.rb +48 -0
  122. data/lib/worldline/acquiring/sdk/v1/domain/three_d_secure.rb +62 -0
  123. data/lib/worldline/acquiring/sdk/v1/domain/transaction_data_for_dcc.rb +52 -0
  124. data/lib/worldline/acquiring/sdk/v1/domain.rb +4 -0
  125. data/lib/worldline/acquiring/sdk/v1/exception_factory.rb +48 -0
  126. data/lib/worldline/acquiring/sdk/v1/ping/ping_client.rb +52 -0
  127. data/lib/worldline/acquiring/sdk/v1/ping.rb +4 -0
  128. data/lib/worldline/acquiring/sdk/v1/platform_exception.rb +23 -0
  129. data/lib/worldline/acquiring/sdk/v1/reference_exception.rb +23 -0
  130. data/lib/worldline/acquiring/sdk/v1/v1_client.rb +43 -0
  131. data/lib/worldline/acquiring/sdk/v1/validation_exception.rb +23 -0
  132. data/lib/worldline/acquiring/sdk/v1.rb +4 -0
  133. data/lib/worldline/acquiring/sdk.rb +1 -0
  134. data/spec/comparable_extension.rb +29 -0
  135. data/spec/fixtures/resources/authentication/oauth2AccessToken.expired.json +4 -0
  136. data/spec/fixtures/resources/authentication/oauth2AccessToken.invalidClient.json +4 -0
  137. data/spec/fixtures/resources/authentication/oauth2AccessToken.json +4 -0
  138. data/spec/fixtures/resources/communication/getWithQueryParams.json +3 -0
  139. data/spec/fixtures/resources/communication/getWithoutQueryParams.json +3 -0
  140. data/spec/fixtures/resources/communication/notFound.html +1 -0
  141. data/spec/fixtures/resources/communication/postWithBadRequestResponse.json +11 -0
  142. data/spec/fixtures/resources/communication/postWithCreatedResponse.json +6 -0
  143. data/spec/fixtures/resources/communication/unknownServerError.json +10 -0
  144. data/spec/fixtures/resources/logging/bodyNoObfuscation.json +7 -0
  145. data/spec/fixtures/resources/logging/bodyWithBinObfuscated.json +3 -0
  146. data/spec/fixtures/resources/logging/bodyWithBinOriginal.json +3 -0
  147. data/spec/fixtures/resources/logging/bodyWithCardCustomObfuscated.json +13 -0
  148. data/spec/fixtures/resources/logging/bodyWithCardObfuscated.json +13 -0
  149. data/spec/fixtures/resources/logging/bodyWithCardOriginal.json +13 -0
  150. data/spec/fixtures/resources/logging/bodyWithObjectObfuscated.json +5 -0
  151. data/spec/fixtures/resources/logging/bodyWithObjectOriginal.json +5 -0
  152. data/spec/fixtures/resources/properties.oauth2.yml +8 -0
  153. data/spec/fixtures/resources/properties.proxy.yml +14 -0
  154. data/spec/integration/connection_pooling_spec.rb +74 -0
  155. data/spec/integration/multipart_form_data_spec.rb +216 -0
  156. data/spec/integration/process_payment_spec.rb +43 -0
  157. data/spec/integration/request_dcc_rate_spec.rb +24 -0
  158. data/spec/integration/sdk_proxy_spec.rb +70 -0
  159. data/spec/integration_setup.rb +111 -0
  160. data/spec/lib/authentication/oauth2_authenticator_spec.rb +68 -0
  161. data/spec/lib/client_spec.rb +47 -0
  162. data/spec/lib/communication/default_connection_logger_spec.rb +484 -0
  163. data/spec/lib/communication/default_connection_spec.rb +352 -0
  164. data/spec/lib/communication/metadata_provider_spec.rb +93 -0
  165. data/spec/lib/communicator_configuration_spec.rb +181 -0
  166. data/spec/lib/communicator_spec.rb +34 -0
  167. data/spec/lib/factory_spec.rb +38 -0
  168. data/spec/lib/json/default_marshaller_spec.rb +39 -0
  169. data/spec/lib/logging/obfuscation/body_obfuscator_spec.rb +86 -0
  170. data/spec/lib/logging/obfuscation/header_obfuscator_spec.rb +100 -0
  171. data/spec/lib/logging/ruby_communicator_logger_spec.rb +92 -0
  172. data/spec/lib/logging/stdout_communicator_logger_spec.rb +64 -0
  173. data/spec/spec_helper.rb +32 -0
  174. metadata +375 -0
@@ -0,0 +1,197 @@
1
+ require 'worldline/acquiring/sdk/authentication/authorization_type'
2
+
3
+ module Worldline
4
+ module Acquiring
5
+ module SDK
6
+ # A CommunicatorConfiguration stores all data used to initialize an {Worldline::Acquiring::SDK::Communicator}.
7
+ #
8
+ # @attr [String] api_endpoint Base URL to the Worldline Acquiring platform
9
+ # @attr [String] authorization_id An id used for authorization. The meaning of this id is different for each authorization type.
10
+ # For instance, for OAuth2 this is the client id
11
+ # @attr [String] authorization_secret A secret used for authorization. The meaning of this secret is different for each authorization type.
12
+ # For instance, for OAuth2 this is the client secret
13
+ # @attr [String] oauth2_token_uri The OAuth2 token URI
14
+ # @attr [String] authorization_type String representing the authentication algorithm used
15
+ # @attr [Integer] connect_timeout The number of seconds before a connection attempt with the Worldline Acquiring platform times out.
16
+ # @attr [Integer] socket_timeout The number of seconds before a timeout occurs when transmitting data to or from the Worldline Acquiring platform.
17
+ # @attr [Integer] max_connections The number of connections with the Worldline Acquiring platform that are kept alive in the connection pool.
18
+ # These connections will be reused when possible.
19
+ # @attr [Worldline::Acquiring::SDK::ProxyConfiguration] proxy_configuration Proxy settings.
20
+ # @attr [String] integrator Name of the integrator
21
+ # @attr [Worldline::Acquiring::SDK::Domain::ShoppingCartExtension] shopping_cart_extension Shopping cart-related metadata.
22
+ class CommunicatorConfiguration
23
+ private
24
+
25
+ DEFAULT_MAX_CONNECTIONS = 10
26
+
27
+ public
28
+
29
+ # The default number of connections that are kept alive in the connection pool.
30
+ # Used if _maxConnections_ is not present in the properties.
31
+ # @return [Integer]
32
+ def self.default_max_connections
33
+ DEFAULT_MAX_CONNECTIONS
34
+ end
35
+
36
+ # Creates a new CommunicatorConfiguration instance.
37
+ #
38
+ # If a _properties_ object is given, it will be parsed like a hash in order to read these attributes.
39
+ # If a value is given in both the _properties_ hash and as a separate parameter,
40
+ # the separate parameter will take precedence over the value in the properties.
41
+ #
42
+ # @param properties [Hash, nil] hash that may contain any of the other parameters.
43
+ # @param api_endpoint [String, nil] the base URL to the Worldline Acquiring platform.
44
+ # @param authorization_id [String, nil] An id used for authorization. The meaning of this id is different for each authorization type.
45
+ # For instance, for OAuth2 this is the client id.
46
+ # @param authorization_secret [String, nil] A secret used for authorization. The meaning of this secret is different for each authorization type.
47
+ # For instance, for OAuth2 this is the client secret.
48
+ # @param oauth2_client_id [String, nil] The OAuth2 client id.
49
+ # This is an alias for _authorization_id_.
50
+ # @param oauth2_client_secret [String, nil] The OAuth2 client secret.
51
+ # This is an alias for _authorization_secret_.
52
+ # @param oauth2_token_uri [String, nil] The OAuth2 token URI.
53
+ # @param authorization_type [String, nil] string describing the authorization protocol to follow.
54
+ # @param connect_timeout [Integer, nil] the number of seconds before a connection attempt with the Worldline Acquiring platform times out.
55
+ # @param socket_timeout [Integer, nil] the number of seconds before a timeout occurs when transmitting data to or from the Worldline Acquiring platform.
56
+ # @param max_connections [Integer, nil] the number of connections with the Worldline Acquiring platform that are kept alive in the connection pool.
57
+ # These connections will be reused when possible.
58
+ # @param proxy_configuration [Worldline::Acquiring::SDK::ProxyConfiguration, nil] stores the URL to a proxy to be used in all communication,
59
+ # or _nil_ if no proxy should be used.
60
+ # @param integrator [String, nil] name of the integrator
61
+ # @param shopping_cart_extension [Worldline::Acquiring::SDK::Domain::ShoppingCartExtension, nil] stores shopping cart-related metadata.
62
+ def initialize(properties: nil, api_endpoint: nil,
63
+ authorization_id: nil, authorization_secret: nil,
64
+ oauth2_client_id: nil, oauth2_client_secret: nil, oauth2_token_uri: nil,
65
+ authorization_type: nil,
66
+ connect_timeout: nil, socket_timeout: nil,
67
+ max_connections: nil, proxy_configuration: nil,
68
+ integrator: nil, shopping_cart_extension: nil)
69
+ unless properties.nil?
70
+ @api_endpoint = get_endpoint(properties)
71
+ @authorization_type = Authentication::AuthorizationType.get_authorization(properties['acquiring.api.authorizationType'])
72
+ @oauth2_token_uri = properties['acquiring.api.oauth2.tokenUri']
73
+ @connect_timeout = properties['acquiring.api.connectTimeout']
74
+ @socket_timeout = properties['acquiring.api.socketTimeout']
75
+ @max_connections = get_property(properties, 'acquiring.api.maxConnections', DEFAULT_MAX_CONNECTIONS)
76
+
77
+ proxy_uri = properties['acquiring.api.proxy.uri']
78
+ proxy_user = properties['acquiring.api.proxy.username']
79
+ proxy_pass = properties['acquiring.api.proxy.password']
80
+ unless proxy_uri.nil?
81
+ @proxy_configuration = ProxyConfiguration.new(address: URI(proxy_uri),
82
+ username: proxy_user,
83
+ password: proxy_pass)
84
+ end
85
+ @integrator = properties['acquiring.api.integrator']
86
+ @shopping_cart_extension = get_shopping_cart_extension(properties)
87
+ end
88
+
89
+ if api_endpoint
90
+ @api_endpoint = api_endpoint
91
+ end
92
+ if authorization_id
93
+ @authorization_id = authorization_id
94
+ end
95
+ if authorization_secret
96
+ @authorization_secret = authorization_secret
97
+ end
98
+ if oauth2_client_id
99
+ @authorization_id = oauth2_client_id
100
+ end
101
+ if oauth2_client_secret
102
+ @authorization_secret = oauth2_client_secret
103
+ end
104
+ if oauth2_token_uri
105
+ @oauth2_token_uri = oauth2_token_uri
106
+ end
107
+ if authorization_type
108
+ @authorization_type = authorization_type
109
+ end
110
+ if connect_timeout
111
+ @connect_timeout = connect_timeout
112
+ end
113
+ if socket_timeout
114
+ @socket_timeout = socket_timeout
115
+ end
116
+ if max_connections
117
+ @max_connections = max_connections
118
+ end
119
+ if proxy_configuration
120
+ @proxy_configuration = proxy_configuration
121
+ end
122
+ if integrator
123
+ @integrator = integrator
124
+ end
125
+ if shopping_cart_extension
126
+ @shopping_cart_extension = shopping_cart_extension
127
+ end
128
+ end
129
+
130
+ attr_accessor :api_endpoint
131
+
132
+ attr_accessor :authorization_id
133
+ attr_accessor :authorization_secret
134
+ attr_accessor :oauth2_token_uri
135
+ attr_accessor :authorization_type
136
+
137
+ attr_accessor :connect_timeout
138
+ attr_accessor :socket_timeout
139
+ attr_accessor :max_connections
140
+
141
+ attr_accessor :proxy_configuration
142
+
143
+ attr_accessor :integrator
144
+ attr_accessor :shopping_cart_extension
145
+
146
+ alias :oauth2_client_id :authorization_id
147
+ alias :oauth2_client_id= :authorization_id=
148
+ alias :oauth2_client_secret :authorization_secret
149
+ alias :oauth2_client_secret= :authorization_secret=
150
+
151
+ private
152
+
153
+ def get_property(properties, key, default_value)
154
+ property_value = properties[key]
155
+ if property_value.nil?
156
+ default_value
157
+ else
158
+ property_value
159
+ end
160
+ end
161
+
162
+ def get_endpoint(properties)
163
+ host = properties['acquiring.api.endpoint.host']
164
+ scheme = properties['acquiring.api.endpoint.scheme']
165
+ port = properties['acquiring.api.endpoint.port']
166
+ if scheme.nil?
167
+ scheme = 'https'
168
+ end
169
+ if port.nil?
170
+ port = -1
171
+ end
172
+ create_uri(scheme, host, port)
173
+ end
174
+
175
+ def create_uri(scheme, host, port)
176
+ if port == -1
177
+ "#{scheme}://#{host}"
178
+ else
179
+ "#{scheme}://#{host}:#{port.to_s}"
180
+ end
181
+ end
182
+
183
+ def get_shopping_cart_extension(properties)
184
+ creator = properties['acquiring.api.shoppingCartExtension.creator']
185
+ name = properties['acquiring.api.shoppingCartExtension.name']
186
+ version = properties['acquiring.api.shoppingCartExtension.version']
187
+ extension_id = properties['acquiring.api.shoppingCartExtension.extensionId']
188
+ if creator.nil? && name.nil? && version.nil? && extension_id.nil?
189
+ nil
190
+ else
191
+ Domain::ShoppingCartExtension.new(creator, name, version, extension_id)
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,34 @@
1
+ module Worldline
2
+ module Acquiring
3
+ module SDK
4
+ module Domain
5
+ # Base class for all SDK data objects, supports marshalling and unmarshalling the data object to and from JSON.
6
+ class DataObject
7
+
8
+ # Returns a hash representation of the DataObject.
9
+ # The hash contains camelCase representations of the variables, and their values.
10
+ # Should be overridden to add all instance variables of the object.
11
+ #
12
+ # @return [Hash]
13
+ def to_h
14
+ {}
15
+ end
16
+
17
+ # Create a new instance of this object (DataObject or descendant)
18
+ # from a hash containing attribute values in camelCase.
19
+ # Note that the hash contains Strings as keys instead of more commonly used tokens.
20
+ def self.new_from_hash(hash)
21
+ obj = self.new
22
+ obj.from_hash(hash)
23
+ obj
24
+ end
25
+
26
+ # Set attributes from values in parameter hash.
27
+ # Should be overridden by descendants in order to properly restore their attributes from the hash.
28
+ # Note that the hash contains Strings as keys instead of more commonly used tokens.
29
+ def from_hash(hash) end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ require 'worldline/acquiring/sdk/domain/data_object'
2
+
3
+ module Worldline
4
+ module Acquiring
5
+ module SDK
6
+ module Domain
7
+ # Represents metadata part of shopping carts.
8
+ #
9
+ # @attr_reader [String] creator
10
+ # @attr_reader [String] name
11
+ # @attr_reader [String] version
12
+ # @attr_reader [String] extension_id
13
+ class ShoppingCartExtension < DataObject
14
+ def initialize(creator, name, version, extension_id=nil)
15
+ raise ArgumentError.new if creator.nil? or creator.strip.empty?
16
+ raise ArgumentError.new if name.nil? or name.strip.empty?
17
+ raise ArgumentError.new if version.nil? or version.to_s.strip.empty?
18
+
19
+ @creator = creator
20
+ @name = name
21
+ @version = version.to_s
22
+ @extension_id = extension_id
23
+ end
24
+
25
+ # Constructs a new ShoppingCartExtension from parameter hash
26
+ # the hash should contain a _creator_, _name_, _version_ and _extensionId_
27
+ #--
28
+ # Overridden so ShoppingCartExtension can retain mandatory default arguments
29
+ #++
30
+ def self.new_from_hash(hash)
31
+ creator = hash['creator'] if hash.has_key?('creator')
32
+ name = hash['name'] if hash.has_key?('name')
33
+ version = hash['version'] if hash.has_key?('version')
34
+ extension_id = hash['extensionId'] if hash.has_key?('extensionId')
35
+ self.new(creator, name, version, extension_id)
36
+ end
37
+
38
+ # Converts the shopping cart metadata to a hash
39
+ def to_h
40
+ hash = super
41
+ hash['creator'] = @creator unless @creator.nil?
42
+ hash['name'] = @name unless @name.nil?
43
+ hash['version'] = @version unless @version.nil?
44
+ hash['extensionId'] = @extension_id unless @extension_id.nil?
45
+ hash
46
+ end
47
+
48
+ # loads shopping cart metadata from a parameter hash
49
+ def from_hash(hash)
50
+ super
51
+ @creator = hash['creator'] if hash.has_key? 'creator'
52
+ @name = hash['name'] if hash.has_key? 'name'
53
+ @version = hash['version'] if hash.has_key? 'version'
54
+ @extension_id = hash['extensionId'] if hash.has_key? 'extensionId'
55
+ end
56
+
57
+ attr_reader :creator, :name, :version, :extension_id
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,35 @@
1
+ module Worldline
2
+ module Acquiring
3
+ module SDK
4
+ module Domain
5
+ # A file that can be uploaded
6
+ #
7
+ # The allowed forms of content are defined by the Connection implementation
8
+ # The default implementation supports file paths and IO objects.
9
+ #
10
+ # @attr_reader [String] file_name The name of the file.
11
+ # @attr_reader [String, IO] content The file's content.
12
+ # @attr_reader [String] content_type The file's content type.
13
+ # @attr_reader [Integer] content_length The file's content length, or -1 if not known.
14
+ class UploadableFile
15
+
16
+ def initialize(file_name, content, content_type, content_length = -1)
17
+ raise ArgumentError.new("file_name is required") if file_name.nil? or !file_name.strip
18
+ raise ArgumentError.new("content is required") if content.nil?
19
+ raise ArgumentError.new("content_type is required") if content_type.nil? or !content_type.strip
20
+
21
+ @file_name = file_name
22
+ @content = content
23
+ @content_type = content_type
24
+ @content_length = [content_length, -1].max
25
+ end
26
+
27
+ attr_reader :file_name
28
+ attr_reader :content
29
+ attr_reader :content_type
30
+ attr_reader :content_length
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(__dir__, 'domain', '*.rb')].each { |f| require f }
@@ -0,0 +1,183 @@
1
+ require 'yaml'
2
+ require 'worldline/acquiring/sdk/client'
3
+ require 'worldline/acquiring/sdk/communicator'
4
+ require 'worldline/acquiring/sdk/communicator_configuration'
5
+ require 'worldline/acquiring/sdk/authentication/authorization_type'
6
+ require 'worldline/acquiring/sdk/authentication/oauth2_authenticator'
7
+ require 'worldline/acquiring/sdk/communication/default_connection'
8
+ require 'worldline/acquiring/sdk/communication/metadata_provider'
9
+ require 'worldline/acquiring/sdk/json/default_marshaller'
10
+
11
+ module Worldline
12
+ module Acquiring
13
+ module SDK
14
+ # Convenience class that constructs instances of several other classes in the SDK.
15
+ # Provides methods to construct
16
+ # {Worldline::Acquiring::SDK::CommunicatorConfiguration}, {Worldline::Acquiring::SDK::Communicator} and {Worldline::Acquiring::SDK::Client} instances.
17
+ class Factory
18
+
19
+ # Creates and returns a {Worldline::Acquiring::SDK::CommunicatorConfiguration} based on the configuration in the file
20
+ # located at _configuration_file_name_.
21
+ #
22
+ # @param configuration_file_name [String] Path to the configuration file to use, should be in YAML format.
23
+ # @param authorization_id [String] Authorization id, e.g. the key id for the Worldline Acquiring platform.
24
+ # @param authorization_secret [String] Authorization secret, e.g. the secret key used for authentication to the Worldline Acquiring platform.
25
+ # @return [Worldline::Acquiring::SDK::CommunicatorConfiguration] The created communicator configuration
26
+ def self.create_configuration(configuration_file_name, authorization_id, authorization_secret)
27
+ properties = YAML::load_file(configuration_file_name)
28
+ CommunicatorConfiguration.new(properties: properties,
29
+ authorization_id: authorization_id,
30
+ authorization_secret: authorization_secret)
31
+ end
32
+
33
+ # Creates and returns a {Worldline::Acquiring::SDK::Communicator} from a {Worldline::Acquiring::SDK::CommunicatorConfiguration},
34
+ # a {Worldline::Acquiring::SDK::Communication::MetadataProvider}, a {Worldline::Acquiring::SDK::Communication::Connection},
35
+ # an {Worldline::Acquiring::SDK::Authentication::Authenticator} and a {Worldline::Acquiring::SDK::JSON::Marshaller}.
36
+ #
37
+ # @param configuration [Worldline::Acquiring::SDK::CommunicatorConfiguration] configuration settings to be used by the client.
38
+ # @param metadata_provider [Worldline::Acquiring::SDK::Communication::MetadataProvider] stores the metadata for the communicating client.
39
+ # @param connection [Worldline::Acquiring::SDK::Communication::Connection] connection that can be used to communicate with the Worldline Acquiring platform.
40
+ # @param authenticator [Worldline::Acquiring::SDK::Authentication::Authenticator] authenticator that can authenticate messages sent to the Worldline Acquiring platform.
41
+ # @param marshaller [Worldline::Acquiring::SDK::JSON::Marshaller] marshaller that can marshal and unmarshal objects to and from JSON.
42
+ # @return [Worldline::Acquiring::SDK::Communicator] The created communicator
43
+ def self.create_communicator_from_configuration(configuration, metadata_provider: nil,
44
+ connection: nil, authenticator: nil, marshaller: nil)
45
+ unless metadata_provider
46
+ metadata_provider = MetadataProvider.new(configuration.integrator,
47
+ shopping_cart_extension: configuration.shopping_cart_extension)
48
+ end
49
+ unless connection
50
+ connection = Communication::DefaultConnection.new({ connect_timeout: configuration.connect_timeout,
51
+ socket_timeout: configuration.socket_timeout,
52
+ max_connections: configuration.max_connections,
53
+ proxy_configuration: configuration.proxy_configuration })
54
+ end
55
+ unless authenticator
56
+ authenticator = get_authenticator(configuration)
57
+ end
58
+ unless marshaller
59
+ marshaller = DefaultMarshaller.instance
60
+ end
61
+ Communicator.new(configuration.api_endpoint, connection, authenticator, metadata_provider, marshaller)
62
+ end
63
+
64
+ # Creates and returns a {Worldline::Acquiring::SDK::Communicator} from a file containing the communicator configuration, authorization_id, authorization_secret,
65
+ # a {Worldline::Acquiring::SDK::Communication::MetadataProvider}, a {Worldline::Acquiring::SDK::Communication::Connection}.
66
+ # an {Worldline::Acquiring::SDK::Authentication::Authenticator} and a {Worldline::Acquiring::SDK::JSON::Marshaller}.
67
+ #
68
+ # @param configuration_file_name [String] Path to the configuration file to use, should be in YAML format.
69
+ # @param authorization_id [String] Authorization id, e.g. the key id for the Worldline Acquiring platform.
70
+ # @param authorization_secret [String] Authorization secret, e.g. the secret key used for authentication to the Worldline Acquiring platform.
71
+ # @param metadata_provider [Worldline::Acquiring::SDK::Communication::MetadataProvider] stores the metadata for the communicating client.
72
+ # @param connection [Worldline::Acquiring::SDK::Communication::Connection] connection that can be used to communicate with the Worldline Acquiring platform.
73
+ # @param authenticator [Worldline::Acquiring::SDK::Authentication::Authenticator] authenticator that can authenticate messages sent to the Worldline Acquiring platform.
74
+ # @param marshaller [Worldline::Acquiring::SDK::JSON::Marshaller] marshaller that can marshal and unmarshal objects to and from JSON.
75
+ # @return [Worldline::Acquiring::SDK::Communicator] The created communicator
76
+ def self.create_communicator_from_file(configuration_file_name, authorization_id, authorization_secret,
77
+ metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil)
78
+ configuration = create_configuration(configuration_file_name, authorization_id, authorization_secret)
79
+ create_communicator_from_configuration(configuration, metadata_provider: metadata_provider, connection: connection,
80
+ authenticator: authenticator, marshaller: marshaller)
81
+ end
82
+
83
+ # Creates and returns an {Worldline::Acquiring::SDK::Client} that provides the a high-level interface with the Worldline Acquiring platform.
84
+ # If a code block is given, the created client is returned to the code block and closed afterwards.
85
+ #
86
+ # @example Providing a code block
87
+ # Factory.create_client_from_configuration(configuration) do |client|
88
+ # # use client as needed
89
+ # end
90
+ # # client is closed here
91
+ #
92
+ # @param configuration [Worldline::Acquiring::SDK::CommunicatorConfiguration] contains configuration settings to be used by the client.
93
+ # @param metadata_provider [Worldline::Acquiring::SDK::Communication::MetadataProvider] stores the metadata for the communicating client.
94
+ # @param connection [Worldline::Acquiring::SDK::Communication::Connection] connection that can be used to communicate with the Worldline Acquiring platform.
95
+ # @param authenticator [Worldline::Acquiring::SDK::Authentication::Authenticator] authenticator that can authenticate messages sent to the Worldline Acquiring platform.
96
+ # @param marshaller [Worldline::Acquiring::SDK::JSON::Marshaller] marshaller that can marshal and unmarshal objects to and from JSON.
97
+ # @return [Worldline::Acquiring::SDK::Client] The created client
98
+ def self.create_client_from_configuration(configuration, metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil)
99
+ communicator = create_communicator_from_configuration(configuration, metadata_provider: metadata_provider, connection: connection,
100
+ authenticator: authenticator, marshaller: marshaller)
101
+ client = Client.new(communicator)
102
+ if block_given?
103
+ begin
104
+ yield client
105
+ ensure
106
+ client.close
107
+ end
108
+ else
109
+ return client
110
+ end
111
+ end
112
+
113
+ # Creates and returns an {Worldline::Acquiring::SDK::Client} that provides the a high-level interface with the Worldline Acquiring platform.
114
+ # If a code block is given, the created client is returned to the code block and closed afterwards.
115
+ #
116
+ # @example Providing a code block
117
+ # Factory.create_client_from_communicator(communicator) do |client|
118
+ # # use client as needed
119
+ # end
120
+ # # client is closed here
121
+ #
122
+ # @param communicator [Worldline::Acquiring::SDK::Communicator] provides network communication service for the Client
123
+ # @return [Worldline::Acquiring::SDK::Client] The created client
124
+ def self.create_client_from_communicator(communicator)
125
+ client = Client.new(communicator)
126
+ if block_given?
127
+ begin
128
+ yield client
129
+ ensure
130
+ client.close
131
+ end
132
+ else
133
+ return client
134
+ end
135
+ end
136
+
137
+ # Creates and returns an {Worldline::Acquiring::SDK::Client} that provides the a high-level interface with the Worldline Acquiring platform.
138
+ # If a code block is given, the created client is returned to the code block and closed afterwards.
139
+ #
140
+ # @example Providing a code block
141
+ # Factory.create_client_from_file(configuration_file_name, authorization_id, authorization_secret) do |client|
142
+ # # use client as needed
143
+ # end
144
+ # # client is closed here
145
+ #
146
+ # @param configuration_file_name [String] Path to the configuration file to use, should be in YAML format.
147
+ # @param authorization_id [String] Authorization id, e.g. the key id for the Worldline Acquiring platform.
148
+ # @param authorization_secret [String] Authorization secret, e.g. the secret key used for authentication to the Worldline Acquiring platform.
149
+ # @param metadata_provider [Worldline::Acquiring::SDK::Communication::MetadataProvider] stores the metadata for the communicating client.
150
+ # @param connection [Worldline::Acquiring::SDK::Communication::Connection] connection that can be used to communicate with the Worldline Acquiring platform.
151
+ # @param authenticator [Worldline::Acquiring::SDK::Authentication::Authenticator] authenticator that can authenticate messages sent to the Worldline Acquiring platform.
152
+ # @param marshaller [Worldline::Acquiring::SDK::JSON::Marshaller] marshaller that can marshal and unmarshal objects to and from JSON.
153
+ # @return [Worldline::Acquiring::SDK::Client] The created client
154
+ def self.create_client_from_file(configuration_file_name, authorization_id, authorization_secret,
155
+ metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil)
156
+ communicator = create_communicator_from_file(configuration_file_name, authorization_id, authorization_secret,
157
+ metadata_provider: metadata_provider, connection: connection,
158
+ authenticator: authenticator, marshaller: marshaller)
159
+ client = Client.new(communicator)
160
+ if block_given?
161
+ begin
162
+ yield client
163
+ ensure
164
+ client.close
165
+ end
166
+ else
167
+ return client
168
+ end
169
+ end
170
+
171
+ private
172
+
173
+ # @param configuration [Worldline::Acquiring::SDK::CommunicatorConfiguration]
174
+ def self.get_authenticator(configuration)
175
+ if configuration.authorization_type == Authentication::AuthorizationType::OAUTH2
176
+ return Authentication::OAuth2Authenticator.new(configuration)
177
+ end
178
+ raise RuntimeError.new("Unknown authorizationType #{configuration.authorization_type}")
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+ require 'singleton'
3
+ require 'worldline/acquiring/sdk/json/marshaller'
4
+
5
+ module Worldline
6
+ module Acquiring
7
+ module SDK
8
+ module JSON
9
+ # Marshals objects to and from JSON format.
10
+ # Currently supports marshalling and unmarshalling of classes that support class.new_from_hash and class#to_h
11
+ class DefaultMarshaller < Marshaller
12
+ include Singleton
13
+
14
+ # Marshals the _request_object_ to a JSON string using request_object#to_h
15
+ def marshal(request_object)
16
+ ::JSON.pretty_generate(request_object.to_h)
17
+ end
18
+
19
+ # Unmarshals a JSON string into an object of type _klass_ using klass.new_from_hash
20
+ def unmarshal(json_string, klass)
21
+ if json_string.nil?
22
+ return nil
23
+ elsif json_string.length == 0
24
+ return ''
25
+ end
26
+ if klass.respond_to?(:new_from_hash)
27
+ klass.new_from_hash(::JSON.load(json_string))
28
+ else
29
+ raise NotImplementedError
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ module Worldline
2
+ module Acquiring
3
+ module SDK
4
+ module JSON
5
+ # Class responsible for marshalling and unmarshalling objects to and from JSON
6
+ class Marshaller
7
+
8
+ # Marshals _request_object_ to JSON format by calling #to_h on it.
9
+ #
10
+ # @param request_object [Worldline::Acquiring::SDK::Domain::DataObject] the object to format
11
+ # @return [String] _request_object_ converted to JSON
12
+ def marshal(request_object)
13
+ raise NotImplementedError
14
+ end
15
+
16
+ # Unmarshals a JSON string into an object of type _type_.
17
+ # The new object is initialized by calling .new_from_hash with contents of the JSON as a Hash object.
18
+ #
19
+ # @param response_json [String] The JSON to unmarshal
20
+ # @param type [Type] The class of the object that will be instantiated using _type.new_from_hash_
21
+ # @return The JSON unmarshalled to the given type
22
+ def unmarshal(response_json, type)
23
+ raise NotImplementedError
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Worldline
2
+ module Acquiring
3
+ module SDK
4
+ module JSON
5
+ # Raised when an error occurred while marshalling/unmarshalling data to/from JSON
6
+ class MarshallerSyntaxException < RuntimeError
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(__dir__, 'json', '*.rb')].each { |f| require f }
@@ -0,0 +1,26 @@
1
+ module Worldline
2
+ module Acquiring
3
+ module SDK
4
+ module Logging
5
+ # Base logger class used in this SDK. This class is an interface and cannot be instantiated.
6
+ class CommunicatorLogger
7
+
8
+ # Interface, no instantiation
9
+ # @see Worldline::Acquiring::SDK::Logging::StdoutCommunicatorLogger
10
+ # @see Worldline::Acquiring::SDK::Logging::RubyCommunicatorLogger
11
+ def initialize
12
+ raise NotImplementedError.new("#{self.class.name} is not implemented.")
13
+ end
14
+
15
+ # Logs a message with or without exception
16
+ #
17
+ # @param message [String] the message to log
18
+ # @param thrown [Exception, nil] the exception to log, or nil to log no exception
19
+ def log(message, thrown = nil)
20
+ raise NotImplementedError.new("#{self.class.name}#log() is not implemented.")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end