onlinepayments-sdk-ruby 4.23.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (408) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -0
  3. data/LICENSE.txt +0 -0
  4. data/README.md +5 -6
  5. data/Rakefile +0 -0
  6. data/lib/onlinepayments/sdk/api_exception.rb +47 -35
  7. data/lib/onlinepayments/sdk/api_resource.rb +49 -97
  8. data/lib/onlinepayments/sdk/authentication/authenticator.rb +19 -0
  9. data/lib/onlinepayments/sdk/authentication/authorization_type.rb +15 -0
  10. data/lib/onlinepayments/sdk/authentication/v1hmac_authenticator.rb +109 -0
  11. data/lib/onlinepayments/sdk/authentication.rb +1 -0
  12. data/lib/onlinepayments/sdk/authorization_exception.rb +14 -8
  13. data/lib/onlinepayments/sdk/call_context.rb +30 -21
  14. data/lib/onlinepayments/sdk/client.rb +36 -18
  15. data/lib/onlinepayments/sdk/communication/communication_exception.rb +19 -0
  16. data/lib/onlinepayments/sdk/communication/connection.rb +48 -0
  17. data/lib/onlinepayments/sdk/communication/default_connection.rb +427 -0
  18. data/lib/onlinepayments/sdk/communication/metadata_provider.rb +160 -0
  19. data/lib/onlinepayments/sdk/communication/multipart_form_data_object.rb +52 -0
  20. data/lib/onlinepayments/sdk/communication/multipart_form_data_request.rb +13 -0
  21. data/lib/onlinepayments/sdk/communication/not_found_exception.rb +19 -0
  22. data/lib/onlinepayments/sdk/communication/param_request.rb +14 -0
  23. data/lib/onlinepayments/sdk/communication/pooled_connection.rb +26 -0
  24. data/lib/onlinepayments/sdk/communication/request_header.rb +62 -0
  25. data/lib/onlinepayments/sdk/communication/request_param.rb +28 -0
  26. data/lib/onlinepayments/sdk/communication/response_exception.rb +56 -0
  27. data/lib/onlinepayments/sdk/communication/response_header.rb +78 -0
  28. data/lib/onlinepayments/sdk/communication.rb +1 -0
  29. data/lib/onlinepayments/sdk/communicator.rb +475 -268
  30. data/lib/onlinepayments/sdk/communicator_configuration.rb +162 -53
  31. data/lib/onlinepayments/sdk/declined_payment_exception.rb +28 -21
  32. data/lib/onlinepayments/sdk/declined_payout_exception.rb +28 -23
  33. data/lib/onlinepayments/sdk/declined_refund_exception.rb +28 -23
  34. data/lib/onlinepayments/sdk/declined_transaction_exception.rb +16 -10
  35. data/lib/onlinepayments/sdk/domain/account_on_file.rb +44 -35
  36. data/lib/onlinepayments/sdk/domain/account_on_file_attribute.rb +42 -28
  37. data/lib/onlinepayments/sdk/domain/account_on_file_display_hints.rb +29 -24
  38. data/lib/onlinepayments/sdk/domain/acquirer_information.rb +27 -22
  39. data/lib/onlinepayments/sdk/domain/acquirer_selection_information.rb +34 -24
  40. data/lib/onlinepayments/sdk/domain/additional_order_input.rb +43 -38
  41. data/lib/onlinepayments/sdk/domain/address.rb +65 -43
  42. data/lib/onlinepayments/sdk/domain/address_personal.rb +78 -52
  43. data/lib/onlinepayments/sdk/domain/airline_data.rb +204 -123
  44. data/lib/onlinepayments/sdk/domain/airline_flight_leg.rb +158 -95
  45. data/lib/onlinepayments/sdk/domain/airline_passenger.rb +59 -39
  46. data/lib/onlinepayments/sdk/domain/amount_breakdown.rb +27 -20
  47. data/lib/onlinepayments/sdk/domain/amount_of_money.rb +27 -20
  48. data/lib/onlinepayments/sdk/domain/api_error.rb +73 -47
  49. data/lib/onlinepayments/sdk/domain/apple_pay_line_item.rb +72 -0
  50. data/lib/onlinepayments/sdk/domain/apple_pay_recurring_payment_request.rb +61 -0
  51. data/lib/onlinepayments/sdk/domain/bank_account_iban.rb +20 -16
  52. data/lib/onlinepayments/sdk/domain/browser_data.rb +51 -35
  53. data/lib/onlinepayments/sdk/domain/calculate_surcharge_request.rb +27 -24
  54. data/lib/onlinepayments/sdk/domain/calculate_surcharge_response.rb +22 -20
  55. data/lib/onlinepayments/sdk/domain/cancel_payment_request.rb +27 -22
  56. data/lib/onlinepayments/sdk/domain/cancel_payment_response.rb +20 -18
  57. data/lib/onlinepayments/sdk/domain/capture.rb +41 -32
  58. data/lib/onlinepayments/sdk/domain/capture_output.rb +106 -78
  59. data/lib/onlinepayments/sdk/domain/capture_payment_request.rb +43 -26
  60. data/lib/onlinepayments/sdk/domain/capture_response.rb +41 -32
  61. data/lib/onlinepayments/sdk/domain/capture_status_output.rb +20 -16
  62. data/lib/onlinepayments/sdk/domain/captures_response.rb +22 -20
  63. data/lib/onlinepayments/sdk/domain/card.rb +41 -28
  64. data/lib/onlinepayments/sdk/domain/card_essentials.rb +41 -28
  65. data/lib/onlinepayments/sdk/domain/card_fraud_results.rb +34 -24
  66. data/lib/onlinepayments/sdk/domain/card_info.rb +27 -20
  67. data/lib/onlinepayments/sdk/domain/card_payment_method_specific_input.rb +199 -128
  68. data/lib/onlinepayments/sdk/domain/card_payment_method_specific_input_base.rb +149 -104
  69. data/lib/onlinepayments/sdk/domain/card_payment_method_specific_input_for_hosted_checkout.rb +36 -28
  70. data/lib/onlinepayments/sdk/domain/card_payment_method_specific_output.rb +133 -100
  71. data/lib/onlinepayments/sdk/domain/card_payout_method_specific_input.rb +41 -30
  72. data/lib/onlinepayments/sdk/domain/card_recurrence_details.rb +20 -16
  73. data/lib/onlinepayments/sdk/domain/card_source.rb +41 -30
  74. data/lib/onlinepayments/sdk/domain/card_without_cvv.rb +34 -24
  75. data/lib/onlinepayments/sdk/domain/company_information.rb +20 -16
  76. data/lib/onlinepayments/sdk/domain/complete_payment_card_payment_method_specific_input.rb +20 -18
  77. data/lib/onlinepayments/sdk/domain/complete_payment_request.rb +27 -24
  78. data/lib/onlinepayments/sdk/domain/complete_payment_response.rb +35 -31
  79. data/lib/onlinepayments/sdk/domain/contact_details.rb +51 -35
  80. data/lib/onlinepayments/sdk/domain/create_hosted_checkout_request.rb +76 -59
  81. data/lib/onlinepayments/sdk/domain/create_hosted_checkout_response.rb +60 -43
  82. data/lib/onlinepayments/sdk/domain/create_hosted_tokenization_request.rb +57 -42
  83. data/lib/onlinepayments/sdk/domain/create_hosted_tokenization_response.rb +57 -44
  84. data/lib/onlinepayments/sdk/domain/create_mandate_request.rb +71 -48
  85. data/lib/onlinepayments/sdk/domain/create_mandate_response.rb +27 -24
  86. data/lib/onlinepayments/sdk/domain/create_mandate_with_return_url.rb +71 -48
  87. data/lib/onlinepayments/sdk/domain/create_payment_link_request.rb +120 -87
  88. data/lib/onlinepayments/sdk/domain/create_payment_request.rb +82 -60
  89. data/lib/onlinepayments/sdk/domain/create_payment_response.rb +35 -31
  90. data/lib/onlinepayments/sdk/domain/create_payout_request.rb +61 -40
  91. data/lib/onlinepayments/sdk/domain/create_token_request.rb +27 -22
  92. data/lib/onlinepayments/sdk/domain/created_payment_output.rb +27 -22
  93. data/lib/onlinepayments/sdk/domain/created_token_response.rb +50 -38
  94. data/lib/onlinepayments/sdk/domain/credit_card_specific_input_hosted_tokenization.rb +29 -26
  95. data/lib/onlinepayments/sdk/domain/credit_card_validation_rules_hosted_tokenization.rb +27 -20
  96. data/lib/onlinepayments/sdk/domain/currency_conversion.rb +27 -22
  97. data/lib/onlinepayments/sdk/domain/currency_conversion_input.rb +27 -20
  98. data/lib/onlinepayments/sdk/domain/currency_conversion_request.rb +27 -24
  99. data/lib/onlinepayments/sdk/domain/currency_conversion_response.rb +34 -28
  100. data/lib/onlinepayments/sdk/domain/currency_conversion_result.rb +27 -20
  101. data/lib/onlinepayments/sdk/domain/currency_conversion_specific_input.rb +20 -16
  102. data/lib/onlinepayments/sdk/domain/customer.rb +87 -68
  103. data/lib/onlinepayments/sdk/domain/customer_account.rb +77 -55
  104. data/lib/onlinepayments/sdk/domain/customer_account_authentication.rb +34 -20
  105. data/lib/onlinepayments/sdk/domain/customer_bank_account.rb +34 -24
  106. data/lib/onlinepayments/sdk/domain/customer_device.rb +64 -44
  107. data/lib/onlinepayments/sdk/domain/customer_device_output.rb +20 -16
  108. data/lib/onlinepayments/sdk/domain/customer_output.rb +20 -18
  109. data/lib/onlinepayments/sdk/domain/customer_payment_activity.rb +34 -24
  110. data/lib/onlinepayments/sdk/domain/customer_token.rb +35 -31
  111. data/lib/onlinepayments/sdk/domain/data_object.rb +32 -0
  112. data/lib/onlinepayments/sdk/domain/dcc_card_source.rb +41 -30
  113. data/lib/onlinepayments/sdk/domain/dcc_proposal.rb +51 -41
  114. data/lib/onlinepayments/sdk/domain/decrypted_payment_data.rb +51 -35
  115. data/lib/onlinepayments/sdk/domain/directory_entry.rb +34 -24
  116. data/lib/onlinepayments/sdk/domain/discount.rb +20 -16
  117. data/lib/onlinepayments/sdk/domain/empty_validator.rb +7 -6
  118. data/lib/onlinepayments/sdk/domain/error_response.rb +29 -24
  119. data/lib/onlinepayments/sdk/domain/external_cardholder_authentication_data.rb +86 -55
  120. data/lib/onlinepayments/sdk/domain/external_token_linked.rb +35 -24
  121. data/lib/onlinepayments/sdk/domain/feedbacks.rb +30 -0
  122. data/lib/onlinepayments/sdk/domain/fixed_list_validator.rb +22 -20
  123. data/lib/onlinepayments/sdk/domain/fraud_fields.rb +37 -28
  124. data/lib/onlinepayments/sdk/domain/fraud_results.rb +20 -16
  125. data/lib/onlinepayments/sdk/domain/g_pay_three_d_secure.rb +50 -36
  126. data/lib/onlinepayments/sdk/domain/get_hosted_checkout_response.rb +27 -22
  127. data/lib/onlinepayments/sdk/domain/get_hosted_tokenization_response.rb +27 -22
  128. data/lib/onlinepayments/sdk/domain/get_iin_details_request.rb +27 -22
  129. data/lib/onlinepayments/sdk/domain/get_iin_details_response.rb +52 -38
  130. data/lib/onlinepayments/sdk/domain/get_mandate_response.rb +20 -18
  131. data/lib/onlinepayments/sdk/domain/get_payment_product_groups_response.rb +22 -20
  132. data/lib/onlinepayments/sdk/domain/get_payment_products_response.rb +22 -20
  133. data/lib/onlinepayments/sdk/domain/get_privacy_policy_response.rb +20 -16
  134. data/lib/onlinepayments/sdk/domain/gift_card_purchase.rb +27 -22
  135. data/lib/onlinepayments/sdk/domain/hosted_checkout_specific_input.rb +83 -56
  136. data/lib/onlinepayments/sdk/domain/hosted_checkout_specific_output.rb +27 -20
  137. data/lib/onlinepayments/sdk/domain/iin_detail.rb +34 -24
  138. data/lib/onlinepayments/sdk/domain/label_template_element.rb +27 -20
  139. data/lib/onlinepayments/sdk/domain/length_validator.rb +27 -20
  140. data/lib/onlinepayments/sdk/domain/line_item.rb +44 -31
  141. data/lib/onlinepayments/sdk/domain/line_item_invoice_data.rb +20 -16
  142. data/lib/onlinepayments/sdk/domain/loan_recipient.rb +51 -35
  143. data/lib/onlinepayments/sdk/domain/lodging_data.rb +20 -16
  144. data/lib/onlinepayments/sdk/domain/mandate_address.rb +51 -35
  145. data/lib/onlinepayments/sdk/domain/mandate_address_response.rb +51 -35
  146. data/lib/onlinepayments/sdk/domain/mandate_contact_details.rb +20 -16
  147. data/lib/onlinepayments/sdk/domain/mandate_customer.rb +52 -44
  148. data/lib/onlinepayments/sdk/domain/mandate_customer_response.rb +52 -44
  149. data/lib/onlinepayments/sdk/domain/mandate_merchant_action.rb +27 -22
  150. data/lib/onlinepayments/sdk/domain/mandate_personal_information.rb +27 -22
  151. data/lib/onlinepayments/sdk/domain/mandate_personal_information_response.rb +27 -22
  152. data/lib/onlinepayments/sdk/domain/mandate_personal_name.rb +27 -20
  153. data/lib/onlinepayments/sdk/domain/mandate_personal_name_response.rb +27 -20
  154. data/lib/onlinepayments/sdk/domain/mandate_redirect_data.rb +27 -20
  155. data/lib/onlinepayments/sdk/domain/mandate_response.rb +64 -44
  156. data/lib/onlinepayments/sdk/domain/merchant_action.rb +43 -28
  157. data/lib/onlinepayments/sdk/domain/mobile_payment_data.rb +27 -20
  158. data/lib/onlinepayments/sdk/domain/mobile_payment_method_hosted_checkout_specific_input.rb +43 -26
  159. data/lib/onlinepayments/sdk/domain/mobile_payment_method_specific_input.rb +71 -50
  160. data/lib/onlinepayments/sdk/domain/mobile_payment_method_specific_output.rb +58 -45
  161. data/lib/onlinepayments/sdk/domain/mobile_payment_product302_specific_input.rb +32 -0
  162. data/lib/onlinepayments/sdk/domain/mobile_payment_product320_specific_input.rb +20 -18
  163. data/lib/onlinepayments/sdk/domain/mobile_three_d_secure_challenge_parameters.rb +51 -0
  164. data/lib/onlinepayments/sdk/domain/multiple_payment_information.rb +27 -20
  165. data/lib/onlinepayments/sdk/domain/omnichannel_payout_specific_input.rb +20 -16
  166. data/lib/onlinepayments/sdk/domain/operation_output.rb +67 -45
  167. data/lib/onlinepayments/sdk/domain/operation_payment_references.rb +30 -0
  168. data/lib/onlinepayments/sdk/domain/order.rb +75 -66
  169. data/lib/onlinepayments/sdk/domain/order_line_details.rb +79 -47
  170. data/lib/onlinepayments/sdk/domain/order_references.rb +34 -24
  171. data/lib/onlinepayments/sdk/domain/order_status_output.rb +52 -38
  172. data/lib/onlinepayments/sdk/domain/order_type_information.rb +27 -20
  173. data/lib/onlinepayments/sdk/domain/other_details.rb +37 -0
  174. data/lib/onlinepayments/sdk/domain/payment_account_on_file.rb +27 -20
  175. data/lib/onlinepayments/sdk/domain/payment_context.rb +34 -26
  176. data/lib/onlinepayments/sdk/domain/payment_creation_output.rb +41 -28
  177. data/lib/onlinepayments/sdk/domain/payment_details_response.rb +60 -49
  178. data/lib/onlinepayments/sdk/domain/payment_error_response.rb +37 -31
  179. data/lib/onlinepayments/sdk/domain/payment_link_event.rb +34 -24
  180. data/lib/onlinepayments/sdk/domain/payment_link_order_input.rb +34 -28
  181. data/lib/onlinepayments/sdk/domain/payment_link_order_output.rb +34 -28
  182. data/lib/onlinepayments/sdk/domain/payment_link_response.rb +74 -51
  183. data/lib/onlinepayments/sdk/domain/payment_link_specific_input.rb +36 -24
  184. data/lib/onlinepayments/sdk/domain/payment_output.rb +115 -94
  185. data/lib/onlinepayments/sdk/domain/payment_product.rb +117 -85
  186. data/lib/onlinepayments/sdk/domain/payment_product130_specific_input.rb +20 -18
  187. data/lib/onlinepayments/sdk/domain/payment_product130_specific_three_d_secure.rb +41 -28
  188. data/lib/onlinepayments/sdk/domain/payment_product3012.rb +27 -20
  189. data/lib/onlinepayments/sdk/domain/payment_product3012_specific_input.rb +51 -0
  190. data/lib/onlinepayments/sdk/domain/payment_product302_specific_data.rb +22 -20
  191. data/lib/onlinepayments/sdk/domain/payment_product3203_specific_output.rb +27 -24
  192. data/lib/onlinepayments/sdk/domain/payment_product3208_specific_input.rb +20 -16
  193. data/lib/onlinepayments/sdk/domain/payment_product3208_specific_output.rb +20 -16
  194. data/lib/onlinepayments/sdk/domain/payment_product3209_specific_input.rb +20 -16
  195. data/lib/onlinepayments/sdk/domain/payment_product3209_specific_output.rb +20 -16
  196. data/lib/onlinepayments/sdk/domain/payment_product320_specific_data.rb +29 -24
  197. data/lib/onlinepayments/sdk/domain/payment_product5001_specific_output.rb +48 -16
  198. data/lib/onlinepayments/sdk/domain/payment_product5100_specific_input.rb +20 -16
  199. data/lib/onlinepayments/sdk/domain/payment_product5402_specific_output.rb +20 -16
  200. data/lib/onlinepayments/sdk/domain/payment_product5404.rb +27 -20
  201. data/lib/onlinepayments/sdk/domain/payment_product5407.rb +27 -20
  202. data/lib/onlinepayments/sdk/domain/payment_product5500_specific_output.rb +41 -24
  203. data/lib/onlinepayments/sdk/domain/payment_product771_specific_output.rb +20 -16
  204. data/lib/onlinepayments/sdk/domain/payment_product840_customer_account.rb +72 -47
  205. data/lib/onlinepayments/sdk/domain/payment_product840_specific_output.rb +43 -38
  206. data/lib/onlinepayments/sdk/domain/payment_product_display_hints.rb +34 -24
  207. data/lib/onlinepayments/sdk/domain/payment_product_field.rb +41 -32
  208. data/lib/onlinepayments/sdk/domain/payment_product_field_data_restrictions.rb +27 -22
  209. data/lib/onlinepayments/sdk/domain/payment_product_field_display_element.rb +41 -28
  210. data/lib/onlinepayments/sdk/domain/payment_product_field_display_hints.rb +84 -56
  211. data/lib/onlinepayments/sdk/domain/payment_product_field_form_element.rb +30 -24
  212. data/lib/onlinepayments/sdk/domain/payment_product_field_tooltip.rb +28 -20
  213. data/lib/onlinepayments/sdk/domain/payment_product_field_validators.rb +83 -73
  214. data/lib/onlinepayments/sdk/domain/payment_product_filter.rb +32 -29
  215. data/lib/onlinepayments/sdk/domain/payment_product_filter_hosted_tokenization.rb +22 -20
  216. data/lib/onlinepayments/sdk/domain/payment_product_filters_hosted_checkout.rb +27 -24
  217. data/lib/onlinepayments/sdk/domain/payment_product_filters_hosted_tokenization.rb +27 -24
  218. data/lib/onlinepayments/sdk/domain/payment_product_group.rb +44 -37
  219. data/lib/onlinepayments/sdk/domain/payment_product_networks_response.rb +22 -20
  220. data/lib/onlinepayments/sdk/domain/payment_references.rb +27 -20
  221. data/lib/onlinepayments/sdk/domain/payment_response.rb +51 -41
  222. data/lib/onlinepayments/sdk/domain/payment_status_output.rb +66 -46
  223. data/lib/onlinepayments/sdk/domain/payout_error_response.rb +37 -31
  224. data/lib/onlinepayments/sdk/domain/payout_output.rb +27 -22
  225. data/lib/onlinepayments/sdk/domain/payout_response.rb +41 -32
  226. data/lib/onlinepayments/sdk/domain/payout_result.rb +41 -32
  227. data/lib/onlinepayments/sdk/domain/payout_status_output.rb +34 -24
  228. data/lib/onlinepayments/sdk/domain/personal_information.rb +34 -26
  229. data/lib/onlinepayments/sdk/domain/personal_information_token.rb +20 -18
  230. data/lib/onlinepayments/sdk/domain/personal_name.rb +34 -24
  231. data/lib/onlinepayments/sdk/domain/personal_name_token.rb +27 -20
  232. data/lib/onlinepayments/sdk/domain/product_directory.rb +22 -20
  233. data/lib/onlinepayments/sdk/domain/protection_eligibility.rb +27 -20
  234. data/lib/onlinepayments/sdk/domain/range_validator.rb +27 -20
  235. data/lib/onlinepayments/sdk/domain/rate_details.rb +51 -35
  236. data/lib/onlinepayments/sdk/domain/redirect_data.rb +27 -20
  237. data/lib/onlinepayments/sdk/domain/redirect_payment_method_specific_input.rb +139 -88
  238. data/lib/onlinepayments/sdk/domain/redirect_payment_method_specific_output.rb +95 -75
  239. data/lib/onlinepayments/sdk/domain/redirect_payment_product3203_specific_input.rb +20 -16
  240. data/lib/onlinepayments/sdk/domain/redirect_payment_product3302_specific_input.rb +44 -0
  241. data/lib/onlinepayments/sdk/domain/redirect_payment_product3306_specific_input.rb +20 -16
  242. data/lib/onlinepayments/sdk/domain/redirect_payment_product5001_specific_input.rb +20 -16
  243. data/lib/onlinepayments/sdk/domain/redirect_payment_product5300_specific_input.rb +74 -0
  244. data/lib/onlinepayments/sdk/domain/redirect_payment_product5406_specific_input.rb +20 -18
  245. data/lib/onlinepayments/sdk/domain/redirect_payment_product5408_specific_input.rb +27 -22
  246. data/lib/onlinepayments/sdk/domain/redirect_payment_product5410_specific_input.rb +32 -0
  247. data/lib/onlinepayments/sdk/domain/redirect_payment_product809_specific_input.rb +20 -16
  248. data/lib/onlinepayments/sdk/domain/redirect_payment_product840_specific_input.rb +41 -20
  249. data/lib/onlinepayments/sdk/domain/redirection_data.rb +20 -16
  250. data/lib/onlinepayments/sdk/domain/refund_card_method_specific_output.rb +34 -26
  251. data/lib/onlinepayments/sdk/domain/refund_e_wallet_method_specific_output.rb +34 -26
  252. data/lib/onlinepayments/sdk/domain/refund_error_response.rb +37 -31
  253. data/lib/onlinepayments/sdk/domain/refund_mobile_method_specific_output.rb +34 -24
  254. data/lib/onlinepayments/sdk/domain/refund_output.rb +89 -64
  255. data/lib/onlinepayments/sdk/domain/refund_payment_product840_customer_account.rb +34 -24
  256. data/lib/onlinepayments/sdk/domain/refund_payment_product840_specific_output.rb +20 -18
  257. data/lib/onlinepayments/sdk/domain/refund_redirect_method_specific_output.rb +27 -20
  258. data/lib/onlinepayments/sdk/domain/refund_request.rb +43 -24
  259. data/lib/onlinepayments/sdk/domain/refund_response.rb +41 -32
  260. data/lib/onlinepayments/sdk/domain/refunds_response.rb +22 -20
  261. data/lib/onlinepayments/sdk/domain/regular_expression_validator.rb +20 -16
  262. data/lib/onlinepayments/sdk/domain/send_test_request.rb +30 -0
  263. data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_input.rb +27 -22
  264. data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_input_base.rb +27 -22
  265. data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_output.rb +34 -28
  266. data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_product771_specific_input.rb +27 -22
  267. data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_product771_specific_input_base.rb +27 -22
  268. data/lib/onlinepayments/sdk/domain/session_request.rb +22 -20
  269. data/lib/onlinepayments/sdk/domain/session_response.rb +53 -39
  270. data/lib/onlinepayments/sdk/domain/shipping.rb +76 -52
  271. data/lib/onlinepayments/sdk/domain/shipping_method.rb +41 -28
  272. data/lib/onlinepayments/sdk/domain/shopping_cart.rb +62 -48
  273. data/lib/onlinepayments/sdk/domain/shopping_cart_extension.rb +51 -43
  274. data/lib/onlinepayments/sdk/domain/show_form_data.rb +35 -31
  275. data/lib/onlinepayments/sdk/domain/subsequent_card_payment_method_specific_input.rb +60 -39
  276. data/lib/onlinepayments/sdk/domain/subsequent_payment_product5001_specific_input.rb +20 -16
  277. data/lib/onlinepayments/sdk/domain/subsequent_payment_request.rb +35 -31
  278. data/lib/onlinepayments/sdk/domain/subsequent_payment_response.rb +20 -18
  279. data/lib/onlinepayments/sdk/domain/surcharge.rb +59 -48
  280. data/lib/onlinepayments/sdk/domain/surcharge_calculation_card.rb +27 -20
  281. data/lib/onlinepayments/sdk/domain/surcharge_for_payment_link.rb +20 -16
  282. data/lib/onlinepayments/sdk/domain/surcharge_rate.rb +41 -28
  283. data/lib/onlinepayments/sdk/domain/surcharge_specific_input.rb +27 -22
  284. data/lib/onlinepayments/sdk/domain/surcharge_specific_output.rb +34 -28
  285. data/lib/onlinepayments/sdk/domain/test_connection.rb +20 -16
  286. data/lib/onlinepayments/sdk/domain/three_d_secure.rb +98 -63
  287. data/lib/onlinepayments/sdk/domain/three_d_secure_base.rb +78 -52
  288. data/lib/onlinepayments/sdk/domain/three_d_secure_data.rb +34 -24
  289. data/lib/onlinepayments/sdk/domain/three_d_secure_results.rb +107 -67
  290. data/lib/onlinepayments/sdk/domain/token_card.rb +27 -22
  291. data/lib/onlinepayments/sdk/domain/token_card_data.rb +27 -18
  292. data/lib/onlinepayments/sdk/domain/token_card_specific_input.rb +20 -18
  293. data/lib/onlinepayments/sdk/domain/token_data.rb +27 -18
  294. data/lib/onlinepayments/sdk/domain/token_e_wallet.rb +28 -22
  295. data/lib/onlinepayments/sdk/domain/token_response.rb +58 -45
  296. data/lib/onlinepayments/sdk/domain/transaction.rb +20 -18
  297. data/lib/onlinepayments/sdk/domain/uploadable_file.rb +33 -0
  298. data/lib/onlinepayments/sdk/domain/validate_credentials_request.rb +37 -0
  299. data/lib/onlinepayments/sdk/domain/validate_credentials_response.rb +30 -0
  300. data/lib/onlinepayments/sdk/domain/value_mapping_element.rb +29 -24
  301. data/lib/onlinepayments/sdk/domain.rb +4 -0
  302. data/lib/onlinepayments/sdk/exception_factory.rb +76 -0
  303. data/lib/onlinepayments/sdk/factory.rb +163 -118
  304. data/lib/onlinepayments/sdk/idempotence_exception.rb +23 -19
  305. data/lib/onlinepayments/sdk/json/default_marshaller.rb +34 -0
  306. data/lib/onlinepayments/sdk/json/marshaller.rb +27 -0
  307. data/lib/onlinepayments/sdk/json/marshaller_syntax_exception.rb +9 -0
  308. data/lib/onlinepayments/sdk/json.rb +1 -0
  309. data/lib/onlinepayments/sdk/logging/communicator_logger.rb +18 -16
  310. data/lib/onlinepayments/sdk/logging/log_message_builder.rb +80 -47
  311. data/lib/onlinepayments/sdk/logging/logging_capable.rb +1 -1
  312. data/lib/onlinepayments/sdk/logging/obfuscation/body_obfuscator.rb +113 -0
  313. data/lib/onlinepayments/sdk/logging/obfuscation/header_obfuscator.rb +54 -0
  314. data/lib/onlinepayments/sdk/logging/obfuscation/obfuscation_capable.rb +21 -0
  315. data/lib/onlinepayments/sdk/logging/obfuscation/obfuscation_rule.rb +47 -0
  316. data/lib/onlinepayments/sdk/logging/obfuscation.rb +1 -0
  317. data/lib/onlinepayments/sdk/logging/request_log_message_builder.rb +40 -29
  318. data/lib/onlinepayments/sdk/logging/response_log_message_builder.rb +30 -23
  319. data/lib/onlinepayments/sdk/logging/ruby_communicator_logger.rb +49 -45
  320. data/lib/onlinepayments/sdk/logging/stdout_communicator_logger.rb +20 -23
  321. data/lib/onlinepayments/sdk/logging.rb +1 -10
  322. data/lib/onlinepayments/sdk/merchant/captures/captures_client.rb +57 -0
  323. data/lib/onlinepayments/sdk/merchant/captures.rb +4 -0
  324. data/lib/onlinepayments/sdk/merchant/complete/complete_client.rb +60 -0
  325. data/lib/onlinepayments/sdk/merchant/complete.rb +4 -0
  326. data/lib/onlinepayments/sdk/merchant/hostedcheckout/hosted_checkout_client.rb +72 -71
  327. data/lib/onlinepayments/sdk/merchant/hostedcheckout.rb +4 -0
  328. data/lib/onlinepayments/sdk/merchant/hostedtokenization/hosted_tokenization_client.rb +72 -71
  329. data/lib/onlinepayments/sdk/merchant/hostedtokenization.rb +4 -0
  330. data/lib/onlinepayments/sdk/merchant/mandates/mandates_client.rb +165 -164
  331. data/lib/onlinepayments/sdk/merchant/mandates.rb +4 -0
  332. data/lib/onlinepayments/sdk/merchant/merchant_client.rb +116 -64
  333. data/lib/onlinepayments/sdk/merchant/paymentlinks/payment_links_client.rb +102 -101
  334. data/lib/onlinepayments/sdk/merchant/paymentlinks.rb +4 -0
  335. data/lib/onlinepayments/sdk/merchant/payments/payments_client.rb +233 -332
  336. data/lib/onlinepayments/sdk/merchant/payments.rb +4 -0
  337. data/lib/onlinepayments/sdk/merchant/payouts/payouts_client.rb +73 -71
  338. data/lib/onlinepayments/sdk/merchant/payouts.rb +4 -0
  339. data/lib/onlinepayments/sdk/merchant/privacypolicy/get_privacy_policy_params.rb +32 -0
  340. data/lib/onlinepayments/sdk/merchant/privacypolicy/privacy_policy_client.rb +54 -0
  341. data/lib/onlinepayments/sdk/merchant/privacypolicy.rb +4 -0
  342. data/lib/onlinepayments/sdk/merchant/productgroups/get_product_group_params.rb +50 -47
  343. data/lib/onlinepayments/sdk/merchant/productgroups/get_product_groups_params.rb +50 -47
  344. data/lib/onlinepayments/sdk/merchant/productgroups/product_groups_client.rb +72 -72
  345. data/lib/onlinepayments/sdk/merchant/productgroups.rb +4 -0
  346. data/lib/onlinepayments/sdk/merchant/products/get_payment_product_networks_params.rb +27 -25
  347. data/lib/onlinepayments/sdk/merchant/products/get_payment_product_params.rb +50 -47
  348. data/lib/onlinepayments/sdk/merchant/products/get_payment_products_params.rb +50 -47
  349. data/lib/onlinepayments/sdk/merchant/products/get_product_directory_params.rb +21 -19
  350. data/lib/onlinepayments/sdk/merchant/products/products_client.rb +134 -136
  351. data/lib/onlinepayments/sdk/merchant/products.rb +4 -0
  352. data/lib/onlinepayments/sdk/merchant/refunds/refunds_client.rb +57 -0
  353. data/lib/onlinepayments/sdk/merchant/refunds.rb +4 -0
  354. data/lib/onlinepayments/sdk/merchant/services/services_client.rb +124 -155
  355. data/lib/onlinepayments/sdk/merchant/services.rb +4 -0
  356. data/lib/onlinepayments/sdk/merchant/sessions/sessions_client.rb +42 -41
  357. data/lib/onlinepayments/sdk/merchant/sessions.rb +4 -0
  358. data/lib/onlinepayments/sdk/merchant/tokens/tokens_client.rb +101 -100
  359. data/lib/onlinepayments/sdk/merchant/tokens.rb +4 -0
  360. data/lib/onlinepayments/sdk/merchant/webhooks/webhooks_client.rb +83 -0
  361. data/lib/onlinepayments/sdk/merchant/webhooks.rb +4 -0
  362. data/lib/onlinepayments/sdk/merchant.rb +4 -0
  363. data/lib/onlinepayments/sdk/platform_exception.rb +19 -0
  364. data/lib/onlinepayments/sdk/proxy_configuration.rb +60 -60
  365. data/lib/onlinepayments/sdk/reference_exception.rb +14 -9
  366. data/lib/onlinepayments/sdk/validation_exception.rb +14 -9
  367. data/lib/onlinepayments/sdk/webhooks/api_version_mismatch_exception.rb +17 -15
  368. data/lib/onlinepayments/sdk/webhooks/in_memory_secret_key_store.rb +46 -43
  369. data/lib/onlinepayments/sdk/webhooks/secret_key_not_available_exception.rb +16 -12
  370. data/lib/onlinepayments/sdk/webhooks/secret_key_store.rb +13 -11
  371. data/lib/onlinepayments/sdk/webhooks/signature_validation_exception.rb +15 -14
  372. data/lib/onlinepayments/sdk/webhooks/signature_validator.rb +81 -0
  373. data/lib/onlinepayments/sdk/webhooks/webhooks_event.rb +84 -53
  374. data/lib/onlinepayments/sdk/webhooks/webhooks_helper.rb +28 -90
  375. data/lib/onlinepayments/sdk/webhooks.rb +1 -11
  376. data/lib/onlinepayments/sdk.rb +4 -26
  377. data/onlinepayments-sdk-ruby.gemspec +3 -2
  378. metadata +89 -35
  379. data/lib/onlinepayments/sdk/authenticator.rb +0 -16
  380. data/lib/onlinepayments/sdk/communication_exception.rb +0 -16
  381. data/lib/onlinepayments/sdk/connection.rb +0 -41
  382. data/lib/onlinepayments/sdk/data_object.rb +0 -31
  383. data/lib/onlinepayments/sdk/defaultimpl/authorization_type.rb +0 -24
  384. data/lib/onlinepayments/sdk/defaultimpl/default_authenticator.rb +0 -108
  385. data/lib/onlinepayments/sdk/defaultimpl/default_connection.rb +0 -365
  386. data/lib/onlinepayments/sdk/defaultimpl/default_marshaller.rb +0 -32
  387. data/lib/onlinepayments/sdk/defaultimpl.rb +0 -6
  388. data/lib/onlinepayments/sdk/endpoint_configuration.rb +0 -127
  389. data/lib/onlinepayments/sdk/exceptions.rb +0 -8
  390. data/lib/onlinepayments/sdk/logging/logging_util.rb +0 -286
  391. data/lib/onlinepayments/sdk/marshaller.rb +0 -24
  392. data/lib/onlinepayments/sdk/marshaller_syntax_exception.rb +0 -6
  393. data/lib/onlinepayments/sdk/merchant/services/get_privacy_policy_params.rb +0 -30
  394. data/lib/onlinepayments/sdk/meta_data_provider.rb +0 -150
  395. data/lib/onlinepayments/sdk/modules.rb +0 -62
  396. data/lib/onlinepayments/sdk/multipart_form_data_object.rb +0 -44
  397. data/lib/onlinepayments/sdk/multipart_form_data_request.rb +0 -9
  398. data/lib/onlinepayments/sdk/not_found_exception.rb +0 -16
  399. data/lib/onlinepayments/sdk/param_request.rb +0 -11
  400. data/lib/onlinepayments/sdk/payment_platform_exception.rb +0 -15
  401. data/lib/onlinepayments/sdk/pooled_connection.rb +0 -21
  402. data/lib/onlinepayments/sdk/request_header.rb +0 -50
  403. data/lib/onlinepayments/sdk/request_param.rb +0 -23
  404. data/lib/onlinepayments/sdk/response_exception.rb +0 -47
  405. data/lib/onlinepayments/sdk/response_header.rb +0 -42
  406. data/lib/onlinepayments/sdk/uploadable_file.rb +0 -30
  407. data/lib/onlinepayments/sdk/webhooks/webhooks.rb +0 -22
  408. data/lib/onlinepayments/sdk/webhooks/webhooks_helper_builder.rb +0 -25
@@ -1,310 +1,517 @@
1
+ require 'date'
1
2
  require 'uri'
2
- require 'onlinepayments/sdk/multipart_form_data_object'
3
- require 'onlinepayments/sdk/multipart_form_data_request'
4
-
5
- module OnlinePayments::SDK
6
- # Class responsible for facilitating communication with the Online Payments platform.
7
- # It combines the following classes to provide communication functionality:
8
- #
9
- # api_endpoint:: The base URI ({URI::HTTP}) to the Online Payments platform
10
- # connection:: {OnlinePayments::SDK::Connection} used to communicate with the Online Payments platform
11
- # authenticator:: {OnlinePayments::SDK::Authenticator} used for authenticating messages sent
12
- # meta_data_provider:: {OnlinePayments::SDK::MetaDataProvider} object containing information relevant for sending requests
13
- # marshaller:: {OnlinePayments::SDK::Marshaller} that is used to marshal and unmarshal data to and from JSON format
14
- #
15
- # @attr_reader [OnlinePayments::SDK::Marshaller] marshaller A Marshaller instance used by the communicator for serializing/deserializing to/from JSON
16
- #
17
- class Communicator
18
- include Logging::LoggingCapable
19
-
20
- # Creates a new Communicator based on the given arguments.
3
+ require 'onlinepayments/sdk/communication/communication_exception'
4
+ require 'onlinepayments/sdk/communication/multipart_form_data_object'
5
+ require 'onlinepayments/sdk/communication/multipart_form_data_request'
6
+ require 'onlinepayments/sdk/communication/not_found_exception'
7
+ require 'onlinepayments/sdk/communication/pooled_connection'
8
+ require 'onlinepayments/sdk/communication/request_header'
9
+ require 'onlinepayments/sdk/communication/response_exception'
10
+ require 'onlinepayments/sdk/communication/response_header'
11
+ require 'onlinepayments/sdk/logging/logging_capable'
12
+ require 'onlinepayments/sdk/logging/obfuscation/obfuscation_capable'
13
+
14
+ module OnlinePayments
15
+ module SDK
16
+ # Class responsible for facilitating communication with the Online Payments platform.
17
+ # It combines the following classes to provide communication functionality:
21
18
  #
22
- # @param api_endpoint [String] the base URL to the Online Payments platform
23
- # @param connection [OnlinePayments::SDK::Connection] used to communicate with the Online Payments platform
24
- # @param authenticator [OnlinePayments::SDK::Authenticator] used for authenticating messages sent
25
- # @param meta_data_provider [OnlinePayments::SDK::MetaDataProvider] object containing information relevant for sending requests
26
- # @param marshaller [OnlinePayments::SDK::Marshaller] used to marshal and unmarshal data to and from JSON format
19
+ # api_endpoint:: the base URL to the Online Payments platform
20
+ # connection:: {OnlinePayments::SDK::Communication::Connection} used to communicate with the Online Payments platform
21
+ # authenticator:: {OnlinePayments::SDK::Authentication::Authenticator} used for authenticating messages sent
22
+ # metadata_provider:: {OnlinePayments::SDK::Communication::MetadataProvider} object containing information relevant for sending requests
23
+ # marshaller:: {OnlinePayments::SDK::JSON::Marshaller} that is used to marshal and unmarshal data to and from JSON format
27
24
  #
28
- def initialize(api_endpoint, connection, authenticator, meta_data_provider, marshaller)
29
- raise ArgumentError, 'api_endpoint is required' unless api_endpoint
30
- raise ArgumentError, 'connection is required' unless connection
31
- raise ArgumentError, 'authenticator is required' unless authenticator
32
- raise ArgumentError, 'meta_data_provider is required' unless meta_data_provider
33
- raise ArgumentError('marshaller is required') unless marshaller
34
-
35
- @api_endpoint = URI(api_endpoint)
36
- if @api_endpoint.path.length.positive? || @api_endpoint.query || @api_endpoint.fragment
37
- raise ArgumentError, "Base URL should not contain a path, query or fragment #{@api_endpoint}"
25
+ # @attr_reader [OnlinePayments::SDK::JSON::Marshaller] marshaller A Marshaller instance used by the communicator for serializing/deserializing to/from JSON
26
+ #
27
+ class Communicator
28
+ include Logging::LoggingCapable
29
+ include Logging::Obfuscation::ObfuscationCapable
30
+
31
+ # Creates a new Communicator.
32
+ #
33
+ # @param api_endpoint [String] the base URL to the Online Payments platform
34
+ # @param connection [OnlinePayments::SDK::Communication::Connection] used to communicate with the Online Payments platform
35
+ # @param authenticator [OnlinePayments::SDK::Authentication::Authenticator] used for authenticating messages sent
36
+ # @param metadata_provider [OnlinePayments::SDK::Communication::MetadataProvider] object containing information relevant for sending requests
37
+ # @param marshaller [OnlinePayments::SDK::JSON::Marshaller] used to marshal and unmarshal data to and from JSON format
38
+ #
39
+ def initialize(api_endpoint, connection, authenticator, metadata_provider, marshaller)
40
+ raise ArgumentError.new('api_endpoint is required') unless api_endpoint
41
+ raise ArgumentError.new('connection is required') unless connection
42
+ raise ArgumentError.new('authenticator is required') unless authenticator
43
+ raise ArgumentError.new('metadata_provider is required') unless metadata_provider
44
+ raise ArgumentError('marshaller is required') if marshaller.nil?
45
+
46
+ uri = URI(api_endpoint)
47
+ raise RuntimeError('api_endpoint should not contain a path') unless uri.path.nil? || uri.path.empty?
48
+ unless uri.userinfo.nil? && uri.query.nil? && uri.fragment.nil?
49
+ raise RuntimeError('api_endpoint should not contain user info, query or fragment')
50
+ end
51
+ @api_endpoint = uri
52
+ @connection = connection
53
+ @authenticator = authenticator
54
+ @metadata_provider = metadata_provider
55
+ @marshaller = marshaller
38
56
  end
39
- @connection = connection
40
- @authenticator = authenticator
41
- @meta_data_provider = meta_data_provider
42
- @marshaller = marshaller
43
- end
44
57
 
45
- # Performs a GET request to the Online Payments platform and returns the response as the given response type.
46
- #
47
- # @param relative_path [String] path relative to the API endpoint
48
- # @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] optional array of request headers
49
- # @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] optional request parameters
50
- # @param response_type [Type] the response type.
51
- # @param context [OnlinePayments::SDK::CallContext, nil] optional call context.
52
- # @return the response of the GET request as the given response type
53
- # @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
54
- # This occurs for example if the request is not authenticated correctly
55
- # @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
56
- # @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
57
- # This occurs for example if a timeout occurs.
58
- def get(relative_path, request_headers, request_parameters, response_type, context)
59
- connection = @connection
60
- request_parameter_list = request_parameters&.to_request_parameters
61
- uri = to_absolute_uri(relative_path, request_parameter_list)
62
-
63
- request_headers ||= []
64
- add_generic_headers('GET', uri, request_headers, context)
65
-
66
- response_status_code, response_headers, response_body = nil
67
- connection.get(uri, request_headers) do |status_code, headers, content|
68
- response_status_code = status_code
69
- response_headers = headers
70
- response_body = content.read.force_encoding('UTF-8')
58
+ # Performs a GET request to the Online Payments platform and returns the response as the given response type.
59
+ #
60
+ # @param relative_path [String] path relative to the API endpoint
61
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] optional array of request headers
62
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] optional request parameters
63
+ # @param response_type [Type] the response type.
64
+ # @param context [OnlinePayments::SDK::CallContext, nil] optional call context.
65
+ # @return the response of the GET request as the given response type
66
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
67
+ # This occurs for example if the request is not authenticated correctly
68
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
69
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
70
+ # This occurs for example if a timeout occurs.
71
+ def get(relative_path, request_headers, request_parameters, response_type, context)
72
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
73
+ uri = to_absolute_uri(relative_path, request_parameter_list)
74
+
75
+ request_headers = [] if request_headers.nil?
76
+ add_generic_headers('GET', uri, request_headers, context)
77
+
78
+ response_status_code, response_headers, response_body = nil
79
+ @connection.get(uri, request_headers) do |status_code, headers, content|
80
+ response_status_code = status_code
81
+ response_headers = headers
82
+ response_body = content.read.force_encoding('UTF-8')
83
+ end
84
+ process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
71
85
  end
72
- process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
73
- end
74
86
 
75
- # Performs a DELETE request to the Online Payments platform and returns the response as the given response type.
76
- #
77
- # @param relative_path [String] Path relative to the API endpoint
78
- # @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] Optional array of request headers
79
- # @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] Optional request parameters
80
- # @param response_type [Type] The response type.
81
- # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
82
- # @return The response of the DELETE request as the given response type
83
- # @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
84
- # This occurs for example if the request is not authenticated correctly
85
- # @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
86
- # @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
87
- # This occurs for example if a timeout occurs.
88
- def delete(relative_path, request_headers, request_parameters, response_type, context)
89
- connection = @connection
90
- request_parameter_list = request_parameters&.to_request_parameters
91
- uri = to_absolute_uri(relative_path, request_parameter_list)
92
- request_headers ||= []
93
- add_generic_headers('DELETE', uri, request_headers, context)
94
-
95
- response_status_code, response_headers, response_body = nil
96
- connection.delete(uri, request_headers) do |status_code, headers, content|
97
- response_status_code = status_code
98
- response_headers = headers
99
- response_body = content.read.force_encoding('UTF-8')
87
+ # Performs a GET request to the Online Payments platform and yields the response as the headers and body.
88
+ #
89
+ # @param relative_path [String] Path relative to the API endpoint
90
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] Optional array of request headers
91
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] Optional request parameters
92
+ # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
93
+ # @yield [Array<OnlinePayments::SDK::Communication::ResponseHeader>, IO] The response headers and body.
94
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
95
+ # This occurs for example if the request is not authenticated correctly
96
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
97
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
98
+ # This occurs for example if a timeout occurs.
99
+ def get_with_binary_response(relative_path, request_headers, request_parameters, context)
100
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
101
+ uri = to_absolute_uri(relative_path, request_parameter_list)
102
+
103
+ request_headers = [] if request_headers.nil?
104
+ add_generic_headers('GET', uri, request_headers, context)
105
+
106
+ response_status_code, response_headers, response_body = nil
107
+ @connection.get(uri, request_headers) do |status_code, headers, content|
108
+ response_status_code = status_code
109
+ response_headers = headers
110
+ response_body = process_binary_response(status_code, content, headers, context) do |h, c|
111
+ yield h, c
112
+ end
113
+ end
114
+ throw_exception_if_necessary(response_body, response_status_code, response_headers, relative_path)
100
115
  end
101
- process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
102
- end
103
116
 
104
- # Performs a POST request to the Online Payments platform and returns the response as the given response type.
105
- #
106
- # @param relative_path [String] Path relative to the API endpoint
107
- # @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] Optional array of request headers
108
- # @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] Optional request parameters
109
- # @param request_body [OnlinePayments::SDK::DataObject, OnlinePayments::SDK::MultipartFormDataObject, OnlinePayments::SDK::MultipartFormDataRequest]
110
- # The optional request body
111
- # @param response_type [Type] The response type.
112
- # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
113
- # @return The response of the POST request as the given response type
114
- # @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
115
- # This occurs for example if the request is not authenticated correctly
116
- # @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
117
- # @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
118
- # This occurs for example if a timeout occurs.
119
- def post(relative_path, request_headers, request_parameters, request_body, response_type, context)
120
- request_parameter_list = request_parameters&.to_request_parameters
121
- uri = to_absolute_uri(relative_path, request_parameter_list)
122
- request_headers ||= []
123
-
124
- body = nil
125
- if request_body.is_a? MultipartFormDataObject
126
- request_headers.push(RequestHeader.new('Content-Type', request_body.content_type))
127
- body = request_body
128
- elsif request_body.is_a? MultipartFormDataRequest
129
- multipart = request_body.to_multipart_form_data_object
130
- request_headers.push(RequestHeader.new('Content-Type', multipart.content_type))
131
- body = multipart
132
- elsif request_body
133
- request_headers.push(RequestHeader.new('Content-Type', 'application/json'))
134
- body = @marshaller.marshal(request_body)
135
- else
136
- # Set the content-type, even though there is no body, to prevent the httpClient from
137
- # adding a content-type header after authentication has been generated.
138
- request_headers.push(RequestHeader.new('Content-Type', 'text/plain'))
117
+ # Performs a DELETE request to the Online Payments platform and returns the response as the given response type.
118
+ #
119
+ # @param relative_path [String] Path relative to the API endpoint
120
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] Optional array of request headers
121
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] Optional request parameters
122
+ # @param response_type [Type] The response type.
123
+ # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
124
+ # @return The response of the DELETE request as the given response type
125
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
126
+ # This occurs for example if the request is not authenticated correctly
127
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
128
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
129
+ # This occurs for example if a timeout occurs.
130
+ def delete(relative_path, request_headers, request_parameters, response_type, context)
131
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
132
+ uri = to_absolute_uri(relative_path, request_parameter_list)
133
+ request_headers = [] if request_headers.nil?
134
+ add_generic_headers('DELETE', uri, request_headers, context)
135
+
136
+ response_status_code, response_headers, response_body = nil
137
+ @connection.delete(uri, request_headers) do |status_code, headers, content|
138
+ response_status_code = status_code
139
+ response_headers = headers
140
+ response_body = content.read.force_encoding('UTF-8')
141
+ end
142
+ process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
139
143
  end
140
144
 
141
- add_generic_headers('POST', uri, request_headers, context)
145
+ # Performs a DELETE request to the Online Payments platform and yields the response as the headers and body.
146
+ #
147
+ # @param relative_path [String] Path relative to the API endpoint
148
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] Optional array of request headers
149
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] Optional request parameters
150
+ # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
151
+ # @yield [Array<OnlinePayments::SDK::Communication::ResponseHeader>, IO] The response headers and body.
152
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
153
+ # This occurs for example if the request is not authenticated correctly
154
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
155
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
156
+ # This occurs for example if a timeout occurs.
157
+ def delete_with_binary_response(relative_path, request_headers, request_parameters, context)
158
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
159
+ uri = to_absolute_uri(relative_path, request_parameter_list)
160
+ request_headers = [] if request_headers.nil?
161
+ add_generic_headers('DELETE', uri, request_headers, context)
162
+
163
+ response_status_code, response_headers, response_body = nil
164
+ @connection.delete(uri, request_headers) do |status_code, headers, content|
165
+ response_status_code = status_code
166
+ response_headers = headers
167
+ response_body = process_binary_response(status_code, content, headers, context) do |h, c|
168
+ yield h, c
169
+ end
170
+ end
171
+ throw_exception_if_necessary(response_body, response_status_code, response_headers, relative_path)
172
+ end
142
173
 
143
- response_status_code, response_headers, response_body = nil
144
- @connection.post(uri, request_headers, body) do |status_code, headers, content|
145
- response_status_code = status_code
146
- response_headers = headers
147
- response_body = content.read.force_encoding('UTF-8')
174
+ # Performs a POST request to the Online Payments platform and returns the response as the given response type.
175
+ #
176
+ # @param relative_path [String] Path relative to the API endpoint
177
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] Optional array of request headers
178
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] Optional request parameters
179
+ # @param request_body [OnlinePayments::SDK::Domain::DataObject, OnlinePayments::SDK::Communication::MultipartFormDataObject, OnlinePayments::SDK::Communication::MultipartFormDataRequest, nil]
180
+ # The optional request body
181
+ # @param response_type [Type] The response type.
182
+ # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
183
+ # @return The response of the POST request as the given response type
184
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
185
+ # This occurs for example if the request is not authenticated correctly
186
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
187
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
188
+ # This occurs for example if a timeout occurs.
189
+ def post(relative_path, request_headers, request_parameters, request_body, response_type, context)
190
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
191
+ uri = to_absolute_uri(relative_path, request_parameter_list)
192
+ request_headers = [] if request_headers.nil?
193
+
194
+ body = nil
195
+ if request_body.is_a? Communication::MultipartFormDataObject
196
+ request_headers.push(Communication::RequestHeader.new('Content-Type', request_body.content_type))
197
+ body = request_body
198
+ elsif request_body.is_a? Communication::MultipartFormDataRequest
199
+ multipart = request_body.to_multipart_form_data_object
200
+ request_headers.push(Communication::RequestHeader.new('Content-Type', multipart.content_type))
201
+ body = multipart
202
+ elsif !request_body.nil?
203
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'application/json'))
204
+ body = @marshaller.marshal(request_body)
205
+ else
206
+ # Set the content-type, even though there is no body, to prevent the httpClient from
207
+ # adding a content-type header after authentication has been generated.
208
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'text/plain'))
209
+ end
210
+
211
+ add_generic_headers('POST', uri, request_headers, context)
212
+
213
+ response_status_code, response_headers, response_body = nil
214
+ @connection.post(uri, request_headers, body) do |status_code, headers, content|
215
+ response_status_code = status_code
216
+ response_headers = headers
217
+ response_body = content.read.force_encoding('UTF-8')
218
+ end
219
+ process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
148
220
  end
149
- process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
150
- end
151
221
 
152
- # Performs a PUT request to the Online Payments platform and returns the response as the given response type.
153
- #
154
- # @param relative_path [String] Path relative to the API endpoint
155
- # @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] Optional array of request headers
156
- # @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] Optional request parameters
157
- # @param request_body [OnlinePayments::SDK::DataObject]
158
- # The optional request body
159
- # @param response_type [Type] The response type.
160
- # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
161
- # @return The response of the PUT request as the given response type
162
- # @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
163
- # This occurs for example if the request is not authenticated correctly
164
- # @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
165
- # @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
166
- # This occurs for example if a timeout occurs.
167
- def put(relative_path, request_headers, request_parameters, request_body, response_type, context)
168
- request_parameter_list = request_parameters&.to_request_parameters
169
- uri = to_absolute_uri(relative_path, request_parameter_list)
170
- request_headers ||= []
171
-
172
- body = nil
173
- if request_body
174
- request_headers.push(RequestHeader.new('Content-Type', 'application/json'))
175
- body = @marshaller.marshal(request_body)
176
- else
177
- # Set the content-type, even though there is no body, to prevent the httpClient from
178
- # adding a content-type header after authentication has been generated.
179
- request_headers.push(RequestHeader.new('Content-Type', 'text/plain'))
222
+ # Performs a POST request to the Online Payments platform and yields the response as the headers and body.
223
+ #
224
+ # @param relative_path [String] Path relative to the API endpoint
225
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] Optional array of request headers
226
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] Optional request parameters
227
+ # @param request_body [OnlinePayments::SDK::Domain::DataObject, OnlinePayments::SDK::Communication::MultipartFormDataObject, OnlinePayments::SDK::Communication::MultipartFormDataRequest, nil]
228
+ # The optional request body
229
+ # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
230
+ # @yield [Array<OnlinePayments::SDK::Communication::ResponseHeader>, IO] The response headers and body.
231
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
232
+ # This occurs for example if the request is not authenticated correctly
233
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
234
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
235
+ # This occurs for example if a timeout occurs.
236
+ def post_with_binary_response(relative_path, request_headers, request_parameters, request_body, context)
237
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
238
+ uri = to_absolute_uri(relative_path, request_parameter_list)
239
+ request_headers = [] if request_headers.nil?
240
+
241
+ body = nil
242
+ if request_body.is_a? Communication::MultipartFormDataObject
243
+ request_headers.push(Communication::RequestHeader.new('Content-Type', request_body.content_type))
244
+ body = request_body
245
+ elsif request_body.is_a? Communication::MultipartFormDataRequest
246
+ multipart = request_body.to_multipart_form_data_object
247
+ request_headers.push(Communication::RequestHeader.new('Content-Type', multipart.content_type))
248
+ body = multipart
249
+ elsif !request_body.nil?
250
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'application/json'))
251
+ body = @marshaller.marshal(request_body)
252
+ else
253
+ # Set the content-type, even though there is no body, to prevent the httpClient from
254
+ # adding a content-type header after authentication has been generated.
255
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'text/plain'))
256
+ end
257
+ add_generic_headers('POST', uri, request_headers, context)
258
+
259
+ response_status_code, response_headers, response_body = nil
260
+ @connection.post(uri, request_headers, body) do |status_code, headers, content|
261
+ response_status_code = status_code
262
+ response_headers = headers
263
+ response_body = process_binary_response(status_code, content, headers, context) do |h, c|
264
+ yield h, c
265
+ end
266
+ end
267
+ throw_exception_if_necessary(response_body, response_status_code, response_headers, relative_path)
180
268
  end
181
- add_generic_headers('PUT', uri, request_headers, context)
182
269
 
183
- response_status_code, response_headers, response_body = nil
184
- @connection.put(uri, request_headers, body) do |status_code, headers, content|
185
- response_status_code = status_code
186
- response_headers = headers
187
- response_body = content.read.force_encoding('UTF-8')
270
+ # Performs a PUT request to the Online Payments platform and returns the response as the given response type.
271
+ #
272
+ # @param relative_path [String] Path relative to the API endpoint
273
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] Optional array of request headers
274
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] Optional request parameters
275
+ # @param request_body [OnlinePayments::SDK::Domain::DataObject, OnlinePayments::SDK::Communication::MultipartFormDataObject, OnlinePayments::SDK::Communication::MultipartFormDataRequest, nil]
276
+ # The optional request body
277
+ # @param response_type [Type] The response type.
278
+ # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
279
+ # @return The response of the PUT request as the given response type
280
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
281
+ # This occurs for example if the request is not authenticated correctly
282
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
283
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
284
+ # This occurs for example if a timeout occurs.
285
+ def put(relative_path, request_headers, request_parameters, request_body, response_type, context)
286
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
287
+ uri = to_absolute_uri(relative_path, request_parameter_list)
288
+ request_headers = [] if request_headers.nil?
289
+
290
+ body = nil
291
+ if request_body.is_a? Communication::MultipartFormDataObject
292
+ request_headers.push(Communication::RequestHeader.new('Content-Type', request_body.content_type))
293
+ body = request_body
294
+ elsif request_body.is_a? Communication::MultipartFormDataRequest
295
+ multipart = request_body.to_multipart_form_data_object
296
+ request_headers.push(Communication::RequestHeader.new('Content-Type', multipart.content_type))
297
+ body = multipart
298
+ elsif !request_body.nil?
299
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'application/json'))
300
+ body = @marshaller.marshal(request_body)
301
+ else
302
+ # Set the content-type, even though there is no body, to prevent the httpClient from
303
+ # adding a content-type header after authentication has been generated.
304
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'text/plain'))
305
+ end
306
+ add_generic_headers('PUT', uri, request_headers, context)
307
+
308
+ response_status_code, response_headers, response_body = nil
309
+ @connection.put(uri, request_headers, body) do |status_code, headers, content|
310
+ response_status_code = status_code
311
+ response_headers = headers
312
+ response_body = content.read.force_encoding('UTF-8')
313
+ end
314
+ process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
188
315
  end
189
- process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
190
- end
191
316
 
192
- # Closes any connections idle for more than _idle_time_ seconds.
193
- # Will not have any effect if the connection is not a pooled connection (an instance of {OnlinePayments::SDK::PooledConnection}).
194
- def close_idle_connections(idle_time)
195
- @connection.close_idle_connections(idle_time) if connection.is_a? PooledConnection
196
- end
317
+ # Performs a PUT request to the Online Payments platform and yields the response as the headers and body.
318
+ #
319
+ # @param relative_path [String] Path relative to the API endpoint
320
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>, nil] Optional array of request headers
321
+ # @param request_parameters [OnlinePayments::SDK::Communication::ParamRequest, nil] Optional request parameters
322
+ # @param request_body [OnlinePayments::SDK::Domain::DataObject, OnlinePayments::SDK::Communication::MultipartFormDataObject, OnlinePayments::SDK::Communication::MultipartFormDataRequest, nil]
323
+ # The optional request body
324
+ # @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
325
+ # @yield [Array<OnlinePayments::SDK::Communication::ResponseHeader>, IO] The response headers and body.
326
+ # @raise [OnlinePayments::SDK::Communication::ResponseException] if the request could not be fulfilled successfully.
327
+ # This occurs for example if the request is not authenticated correctly
328
+ # @raise [OnlinePayments::SDK::Communication::NotFoundException] if the requested resource is not found
329
+ # @raise [OnlinePayments::SDK::Communication::CommunicationException] if there is an error in communicating with the Online Payments platform.
330
+ # This occurs for example if a timeout occurs.
331
+ def put_with_binary_response(relative_path, request_headers, request_parameters, request_body, context)
332
+ request_parameter_list = request_parameters && request_parameters.to_request_parameters
333
+ uri = to_absolute_uri(relative_path, request_parameter_list)
334
+ request_headers = [] if request_headers.nil?
335
+
336
+ body = nil
337
+ if request_body.is_a? Communication::MultipartFormDataObject
338
+ request_headers.push(Communication::RequestHeader.new('Content-Type', request_body.content_type))
339
+ body = request_body
340
+ elsif request_body.is_a? Communication::MultipartFormDataRequest
341
+ multipart = request_body.to_multipart_form_data_object
342
+ request_headers.push(Communication::RequestHeader.new('Content-Type', multipart.content_type))
343
+ body = multipart
344
+ elsif !request_body.nil?
345
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'application/json'))
346
+ body = @marshaller.marshal(request_body)
347
+ else
348
+ # Set the content-type, even though there is no body, to prevent the httpClient from
349
+ # adding a content-type header after authentication has been generated.
350
+ request_headers.push(Communication::RequestHeader.new('Content-Type', 'text/plain'))
351
+ end
352
+ add_generic_headers('PUT', uri, request_headers, context)
353
+
354
+ response_status_code, response_headers, response_body = nil
355
+ @connection.put(uri, request_headers, body) do |status_code, headers, content|
356
+ response_status_code = status_code
357
+ response_headers = headers
358
+ response_body = process_binary_response(status_code, content, headers, context) do |h, c|
359
+ yield h, c
360
+ end
361
+ end
362
+ throw_exception_if_necessary(response_body, response_status_code, response_headers, relative_path)
363
+ end
197
364
 
198
- # Closes any connections that have expired.
199
- # Will not have any effect if the connection is not a pooled connection (an instance of {OnlinePayments::SDK::PooledConnection}).
200
- def close_expired_connections
201
- @connection.close_expired_connections if connection.is_a? PooledConnection
202
- end
365
+ # Closes any connections idle for more than _idle_time_ seconds.
366
+ # Will not have any effect if the connection is not a pooled connection (an instance of {OnlinePayments::SDK::Communication::PooledConnection}).
367
+ def close_idle_connections(idle_time)
368
+ @connection.close_idle_connections(idle_time) if @connection.is_a? PooledConnection
369
+ end
203
370
 
204
- # Enables logging outgoing requests and incoming responses by registering the _communicator_logger_.
205
- # Note that only one logger can be registered at a time and calling _enable_logging_
206
- # a second time will override the old logger instance with the new one.
207
- #
208
- # @param communicator_logger [OnlinePayments::SDK::Logging::CommunicatorLogger] The communicator logger the requests and responses are logged to
209
- def enable_logging(communicator_logger)
210
- @connection.enable_logging(communicator_logger)
211
- end
371
+ # Closes any connections that have expired.
372
+ # Will not have any effect if the connection is not a pooled connection (an instance of {OnlinePayments::SDK::Communication::PooledConnection}).
373
+ def close_expired_connections
374
+ @connection.close_expired_connections if @connection.is_a? PooledConnection
375
+ end
212
376
 
213
- # Disables logging by unregistering any previous logger that might be registered.
214
- def disable_logging
215
- @connection.disable_logging
216
- end
377
+ # Sets the current body obfuscator to use.
378
+ # @param body_obfuscator [OnlinePayments::SDK::Logging::Obfuscation::BodyObfuscator]
379
+ def set_body_obfuscator(body_obfuscator)
380
+ @connection.set_body_obfuscator(body_obfuscator)
381
+ end
217
382
 
218
- # Frees networking resources by closing the underlying network connections.
219
- # After calling _close_, any use of the _get_, _delete_, _post_ and _put_ methods will not function
220
- # and likely result in an error.
221
- def close
222
- @connection.close
223
- end
383
+ # Sets the current header obfuscator to use.
384
+ # @param header_obfuscator [OnlinePayments::SDK::Logging::Obfuscation::HeaderObfuscator]
385
+ def set_header_obfuscator(header_obfuscator)
386
+ @connection.set_header_obfuscator(header_obfuscator)
387
+ end
224
388
 
225
- attr_reader :api_endpoint
226
- attr_reader :connection
227
- attr_reader :authenticator
228
- attr_reader :meta_data_provider
229
- attr_reader :marshaller
389
+ # Enables logging outgoing requests and incoming responses by registering the _communicator_logger_.
390
+ # Note that only one logger can be registered at a time and calling _enable_logging_
391
+ # a second time will override the old logger instance with the new one.
392
+ #
393
+ # @param communicator_logger [OnlinePayments::SDK::Logging::CommunicatorLogger] The communicator logger the requests and responses are logged to
394
+ def enable_logging(communicator_logger)
395
+ @connection.enable_logging(communicator_logger)
396
+ end
230
397
 
231
- protected
398
+ # Disables logging by unregistering any previous logger that might be registered.
399
+ def disable_logging
400
+ @connection.disable_logging
401
+ end
232
402
 
233
- # Constructs a full URL using the base URL and the given relative path and request_parameters.
234
- # The returned URL is a *URI* object.
235
- #
236
- # @param relative_path [String] The relative path of the URL.
237
- # @param request_parameters [Array<OnlinePayments::SDK::RequestParam>, nil] A list of request parameters that each have #name and #value
238
- # which represent the parameter name and value respectively.
239
- def to_absolute_uri(relative_path, request_parameters)
240
- raise RuntimeError('api_endpoint should not contain a path') unless @api_endpoint.path.nil? || @api_endpoint.path.empty?
241
-
242
- if @api_endpoint.userinfo || @api_endpoint.query || @api_endpoint.fragment
243
- raise RuntimeError, 'api_endpoint should not contain user info, query or fragment'
403
+ # Frees networking resources by closing the underlying network connections.
404
+ # After calling _close_, any use of the _get_, _delete_, _post_ and _put_ methods will not function
405
+ # and likely result in an error.
406
+ def close
407
+ @connection.close
244
408
  end
245
- absolute_path = relative_path.start_with?('/') ? relative_path : "/#{relative_path}"
246
- uri = URI::HTTP.new(@api_endpoint.scheme, nil, @api_endpoint.host,
247
- @api_endpoint.port, nil, absolute_path, nil, nil, nil)
248
- request_parameters&.each do |nvp|
249
- parameters = URI.decode_www_form(uri.query || '') << [nvp.name, nvp.value]
250
- uri.query = URI.encode_www_form(parameters)
409
+
410
+ attr_reader :marshaller
411
+
412
+ protected
413
+
414
+ # Constructs a full URL using the base URL and the given relative path and request_parameters.
415
+ # The returned URL is a *URI* object.
416
+ #
417
+ # @param relative_path [String] The relative path of the URL.
418
+ # @param request_parameters [Array<OnlinePayments::SDK::Communication::RequestParam>] A list of request parameters that each have #name and #value
419
+ # which represent the parameter name and value respectively.
420
+ def to_absolute_uri(relative_path, request_parameters)
421
+ absolute_path = relative_path.start_with?('/') ? relative_path : '/' + relative_path
422
+ uri = URI::HTTP.new(@api_endpoint.scheme, nil, @api_endpoint.host,
423
+ @api_endpoint.port, nil, absolute_path, nil, nil, nil)
424
+ unless request_parameters.nil?
425
+ request_parameters.each do |nvp|
426
+ parameters = URI.decode_www_form(uri.query || '') << [nvp.name, nvp.value]
427
+ uri.query = URI.encode_www_form(parameters)
428
+ end
429
+ end
430
+ uri
251
431
  end
252
- uri
253
- end
254
432
 
255
- # Adds several standard headers to the http headers.
256
- # This method will add the 'Date' and 'Authorization' header;
257
- # the 'X-GCS-Idempotence-Key' header will also be added if an idempotence context is given
258
- #
259
- # @param http_method [String] 'GET', 'DELETE', 'POST' or 'PUT' depending on the HTTP method being used
260
- # @param uri [URI::HTTP] The full URI to the Online Payments platform,
261
- # including the relative path and request parameters.
262
- # @param request_headers [Array<OnlinePayments::SDK::RequestHeader>] List of request headers in which which new headers will be added
263
- # @param context [OnlinePayments::SDK::CallContext, nil] object that will be used to produce
264
- # an Idempotence header to prevent accidental request duplication.
265
- def add_generic_headers(http_method, uri, request_headers, context = nil)
266
- request_headers.concat(meta_data_provider.meta_data_headers)
267
- request_headers.push(RequestHeader.new('Date', get_header_date_string))
268
- if context&.idempotence_key
269
- request_headers.push(RequestHeader.new('X-GCS-Idempotence-Key', context.idempotence_key))
433
+ # Adds several standard headers to the http headers.
434
+ # This method will add the 'Date' and 'Authorization' header;
435
+ # the 'X-GCS-Idempotence-Key' header will also be added if an idempotence context is given
436
+ #
437
+ # @param http_method [String] 'GET', 'DELETE', 'POST' or 'PUT' depending on the HTTP method being used
438
+ # @param uri [URI::HTTP] The full URI to the Online Payments platform,
439
+ # including the relative path and request parameters.
440
+ # @param request_headers [Array<OnlinePayments::SDK::Communication::RequestHeader>] List of request headers in which which new headers will be added
441
+ # @param context [OnlinePayments::SDK::CallContext, nil] optional call context.
442
+ def add_generic_headers(http_method, uri, request_headers, context = nil)
443
+ request_headers.concat(@metadata_provider.metadata_headers)
444
+ request_headers.push(Communication::RequestHeader.new('Date', get_header_date_string))
445
+ if !context.nil? && !context.idempotence_key.nil?
446
+ request_headers.push(Communication::RequestHeader.new('X-GCS-Idempotence-Key', context.idempotence_key))
447
+ end
448
+ authorization = @authenticator.get_authorization(http_method, uri, request_headers)
449
+ request_headers.push(Communication::RequestHeader.new('Authorization', authorization))
270
450
  end
271
- authentication_signature = @authenticator.create_simple_authentication_signature(http_method, uri, request_headers)
272
- request_headers.push(RequestHeader.new('Authorization', authentication_signature))
273
- end
274
451
 
275
- def get_header_date_string
276
- Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
277
- end
452
+ def get_header_date_string
453
+ Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
454
+ end
278
455
 
279
- def process_response(body, status, headers, response_type, request_path, context)
280
- update_context(headers, context) if context
456
+ def process_response(body, status, headers, response_type, request_path, context)
457
+ update_context(headers, context) unless context.nil?
281
458
 
282
- throw_exception_if_necessary(body, status, headers, request_path)
283
- @marshaller.unmarshal(body, response_type)
284
- end
459
+ throw_exception_if_necessary(body, status, headers, request_path)
460
+ @marshaller.unmarshal(body, response_type)
461
+ end
285
462
 
286
- def update_context(headers, context)
287
- context.idempotence_request_timestamp = ResponseHeader.get_header_value(headers, 'X-GCS-Idempotence-Request-Timestamp')
288
- end
463
+ def process_binary_response(status, body, headers, context)
464
+ update_context(response.headers, context) unless context.nil?
289
465
 
290
- def throw_exception_if_necessary(body, status_code, headers, request_path)
291
- return if status_code >= 200 && status_code < 300
292
- raise ResponseException.new status_code, headers, body unless body && !is_json(headers)
466
+ if status < 400
467
+ yield headers, body
468
+ ''
469
+ else
470
+ body.read.force_encoding('UTF-8')
471
+ end
472
+ end
293
473
 
294
- cause = ResponseException.new(status_code, headers, body)
295
- if status_code == 404
296
- raise NotFoundException, cause, "The requested resource was not found; invalid path: #{request_path}"
474
+ def update_context(headers, context)
475
+ idempotence_request_timestamp_value = Communication::ResponseHeader.get_header_value(headers, 'X-GCS-Idempotence-Request-Timestamp')
476
+ if idempotence_request_timestamp_value.nil?
477
+ context.idempotence_request_timestamp = nil
478
+ else
479
+ context.idempotence_request_timestamp = idempotence_request_timestamp_value
480
+ end
481
+ idempotence_response_date_time_value = Communication::ResponseHeader.get_header_value(headers, 'IdempotencyResponseDatetime')
482
+ if idempotence_response_date_time_value.nil?
483
+ context.idempotence_response_date_time = nil
484
+ else
485
+ context.idempotence_response_date_time = DateTime.parse(idempotence_response_date_time_value)
486
+ end
297
487
  end
298
488
 
299
- raise CommunicationException, cause
300
- end
489
+ def throw_exception_if_necessary(body, status_code, headers, request_path)
490
+ if status_code < 200 || status_code >= 300
491
+ if !body.nil? && !is_json(headers)
492
+ cause = Communication::ResponseException.new(status_code, headers, body)
493
+ if status_code == 404
494
+ raise Communication::NotFoundException.new(cause, 'The requested resource was not found; invalid path: ' +
495
+ request_path)
496
+ else
497
+ raise Communication::CommunicationException, cause
498
+ end
499
+ else
500
+ raise Communication::ResponseException.new(status_code, headers, body)
501
+ end
502
+ end
503
+ end
301
504
 
302
- private
505
+ private
303
506
 
304
- def is_json(headers)
305
- content_type = ResponseHeader.get_header_value(headers, 'Content-Type')
306
- content_type.nil? || 'application/json'.casecmp(content_type).zero? ||
307
- content_type.downcase.start_with?('application/json')
507
+ def is_json(headers)
508
+ content_type = Communication::ResponseHeader.get_header_value(headers, 'Content-Type')
509
+ if content_type.nil? || 'application/json'.casecmp(content_type) == 0 || 'application/problem+json'.casecmp(content_type) == 0
510
+ return true
511
+ end
512
+ content_type = content_type.downcase
513
+ content_type.start_with?('application/json') || content_type.start_with?('application/problem+json')
514
+ end
308
515
  end
309
516
  end
310
517
  end