connect-sdk-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (377) 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/connect-sdk-ruby.gemspec +28 -0
  7. data/examples/merchant/example_configuration.yml +6 -0
  8. data/examples/merchant/hostedcheckouts/create_hosted_checkout_example.rb +53 -0
  9. data/examples/merchant/hostedcheckouts/get_hosted_checkout_example.rb +22 -0
  10. data/examples/merchant/payments/approve_payment_example.rb +42 -0
  11. data/examples/merchant/payments/cancel_approval_payment_example.rb +22 -0
  12. data/examples/merchant/payments/cancel_payment_example.rb +22 -0
  13. data/examples/merchant/payments/create_payment_example.rb +177 -0
  14. data/examples/merchant/payments/get_payment_example.rb +22 -0
  15. data/examples/merchant/payments/process_challenged_payment_example.rb +22 -0
  16. data/examples/merchant/payments/refund_payment_example.rb +85 -0
  17. data/examples/merchant/payments/tokenize_payment_example.rb +27 -0
  18. data/examples/merchant/payouts/approve_payout_example.rb +27 -0
  19. data/examples/merchant/payouts/cancel_approval_payout_example.rb +22 -0
  20. data/examples/merchant/payouts/cancel_payout_example.rb +22 -0
  21. data/examples/merchant/payouts/create_payout_example.rb +96 -0
  22. data/examples/merchant/payouts/get_payout_example.rb +22 -0
  23. data/examples/merchant/productgroups/get_payment_product_group_example.rb +32 -0
  24. data/examples/merchant/productgroups/get_payment_product_groups_example.rb +32 -0
  25. data/examples/merchant/products/get_directory_example.rb +28 -0
  26. data/examples/merchant/products/get_payment_product_example.rb +32 -0
  27. data/examples/merchant/products/get_payment_products_example.rb +32 -0
  28. data/examples/merchant/refunds/approve_refund_example.rb +27 -0
  29. data/examples/merchant/refunds/cancel_approval_refund_example.rb +22 -0
  30. data/examples/merchant/refunds/cancel_refund_example.rb +22 -0
  31. data/examples/merchant/refunds/get_refund_example.rb +22 -0
  32. data/examples/merchant/riskassessments/risk_assessment_bank_account_example.rb +54 -0
  33. data/examples/merchant/riskassessments/risk_assessment_cards_example.rb +114 -0
  34. data/examples/merchant/services/convert_amount_example.rb +29 -0
  35. data/examples/merchant/services/convert_bank_account_example.rb +34 -0
  36. data/examples/merchant/services/iin_details_example.rb +27 -0
  37. data/examples/merchant/services/test_connection_example.rb +22 -0
  38. data/examples/merchant/sessions/create_session_example.rb +34 -0
  39. data/examples/merchant/tokens/approve_sepa_direct_debit_token_example.rb +29 -0
  40. data/examples/merchant/tokens/create_token_example.rb +82 -0
  41. data/examples/merchant/tokens/delete_token_example.rb +27 -0
  42. data/examples/merchant/tokens/get_token_example.rb +22 -0
  43. data/examples/merchant/tokens/update_token_example.rb +76 -0
  44. data/lib/ingenico/connect/sdk.rb +27 -0
  45. data/lib/ingenico/connect/sdk/api_exception.rb +52 -0
  46. data/lib/ingenico/connect/sdk/api_resource.rb +126 -0
  47. data/lib/ingenico/connect/sdk/authenticator.rb +15 -0
  48. data/lib/ingenico/connect/sdk/authorization_exception.rb +13 -0
  49. data/lib/ingenico/connect/sdk/call_context.rb +26 -0
  50. data/lib/ingenico/connect/sdk/client.rb +92 -0
  51. data/lib/ingenico/connect/sdk/communication_exception.rb +15 -0
  52. data/lib/ingenico/connect/sdk/communicator.rb +277 -0
  53. data/lib/ingenico/connect/sdk/communicator_configuration.rb +98 -0
  54. data/lib/ingenico/connect/sdk/connection.rb +31 -0
  55. data/lib/ingenico/connect/sdk/data_object.rb +43 -0
  56. data/lib/ingenico/connect/sdk/declined_payment_exception.rb +44 -0
  57. data/lib/ingenico/connect/sdk/declined_payout_exception.rb +44 -0
  58. data/lib/ingenico/connect/sdk/declined_refund_exception.rb +46 -0
  59. data/lib/ingenico/connect/sdk/declined_transaction_exception.rb +16 -0
  60. data/lib/ingenico/connect/sdk/defaultimpl.rb +6 -0
  61. data/lib/ingenico/connect/sdk/defaultimpl/authorization_type.rb +18 -0
  62. data/lib/ingenico/connect/sdk/defaultimpl/default_authenticator.rb +106 -0
  63. data/lib/ingenico/connect/sdk/defaultimpl/default_connection.rb +242 -0
  64. data/lib/ingenico/connect/sdk/defaultimpl/default_marshaller.rb +35 -0
  65. data/lib/ingenico/connect/sdk/domain/definitions/abstract_order_status.rb +32 -0
  66. data/lib/ingenico/connect/sdk/domain/definitions/abstract_payment_method_specific_input.rb +32 -0
  67. data/lib/ingenico/connect/sdk/domain/definitions/additional_order_input_airline_data.rb +36 -0
  68. data/lib/ingenico/connect/sdk/domain/definitions/address.rb +81 -0
  69. data/lib/ingenico/connect/sdk/domain/definitions/airline_data.rb +165 -0
  70. data/lib/ingenico/connect/sdk/domain/definitions/airline_flight_leg.rb +102 -0
  71. data/lib/ingenico/connect/sdk/domain/definitions/amount_of_money.rb +39 -0
  72. data/lib/ingenico/connect/sdk/domain/definitions/bank_account.rb +32 -0
  73. data/lib/ingenico/connect/sdk/domain/definitions/bank_account_bban.rb +67 -0
  74. data/lib/ingenico/connect/sdk/domain/definitions/bank_account_iban.rb +32 -0
  75. data/lib/ingenico/connect/sdk/domain/definitions/card.rb +32 -0
  76. data/lib/ingenico/connect/sdk/domain/definitions/card_essentials.rb +39 -0
  77. data/lib/ingenico/connect/sdk/domain/definitions/card_fraud_results.rb +50 -0
  78. data/lib/ingenico/connect/sdk/domain/definitions/card_without_cvv.rb +39 -0
  79. data/lib/ingenico/connect/sdk/domain/definitions/company_information.rb +32 -0
  80. data/lib/ingenico/connect/sdk/domain/definitions/contact_details_base.rb +39 -0
  81. data/lib/ingenico/connect/sdk/domain/definitions/customer_base.rb +50 -0
  82. data/lib/ingenico/connect/sdk/domain/definitions/fraud_fields.rb +115 -0
  83. data/lib/ingenico/connect/sdk/domain/definitions/fraud_results.rb +32 -0
  84. data/lib/ingenico/connect/sdk/domain/definitions/fraud_results_retail_decisions.rb +46 -0
  85. data/lib/ingenico/connect/sdk/domain/definitions/key_value_pair.rb +39 -0
  86. data/lib/ingenico/connect/sdk/domain/definitions/order_status_output.rb +67 -0
  87. data/lib/ingenico/connect/sdk/domain/definitions/payment_product_filter.rb +51 -0
  88. data/lib/ingenico/connect/sdk/domain/definitions/personal_name_base.rb +46 -0
  89. data/lib/ingenico/connect/sdk/domain/definitions/result_do_risk_assessment.rb +61 -0
  90. data/lib/ingenico/connect/sdk/domain/definitions/retail_decisions_cc_fraud_check_output.rb +46 -0
  91. data/lib/ingenico/connect/sdk/domain/definitions/validation_bank_account_check.rb +46 -0
  92. data/lib/ingenico/connect/sdk/domain/definitions/validation_bank_account_output.rb +67 -0
  93. data/lib/ingenico/connect/sdk/domain/errors/api_error.rb +60 -0
  94. data/lib/ingenico/connect/sdk/domain/errors/error_response.rb +46 -0
  95. data/lib/ingenico/connect/sdk/domain/hostedcheckout/create_hosted_checkout_request.rb +102 -0
  96. data/lib/ingenico/connect/sdk/domain/hostedcheckout/create_hosted_checkout_response.rb +59 -0
  97. data/lib/ingenico/connect/sdk/domain/hostedcheckout/created_payment_output.rb +72 -0
  98. data/lib/ingenico/connect/sdk/domain/hostedcheckout/displayed_data.rb +53 -0
  99. data/lib/ingenico/connect/sdk/domain/hostedcheckout/get_hosted_checkout_response.rb +43 -0
  100. data/lib/ingenico/connect/sdk/domain/hostedcheckout/hosted_checkout_specific_input.rb +78 -0
  101. data/lib/ingenico/connect/sdk/domain/hostedcheckout/payment_product_filters_hosted_checkout.rb +53 -0
  102. data/lib/ingenico/connect/sdk/domain/metadata/shopping_cart_extension.rb +48 -0
  103. data/lib/ingenico/connect/sdk/domain/payment/abstract_payment_method_specific_output.rb +32 -0
  104. data/lib/ingenico/connect/sdk/domain/payment/additional_order_input.rb +72 -0
  105. data/lib/ingenico/connect/sdk/domain/payment/address_personal.rb +36 -0
  106. data/lib/ingenico/connect/sdk/domain/payment/approve_payment_card_payment_method_specific_output.rb +32 -0
  107. data/lib/ingenico/connect/sdk/domain/payment/approve_payment_non_sepa_direct_debit_payment_method_specific_input.rb +16 -0
  108. data/lib/ingenico/connect/sdk/domain/payment/approve_payment_payment_method_specific_input.rb +39 -0
  109. data/lib/ingenico/connect/sdk/domain/payment/approve_payment_request.rb +65 -0
  110. data/lib/ingenico/connect/sdk/domain/payment/approve_payment_sepa_direct_debit_payment_method_specific_input.rb +16 -0
  111. data/lib/ingenico/connect/sdk/domain/payment/bank_transfer_payment_method_specific_input.rb +16 -0
  112. data/lib/ingenico/connect/sdk/domain/payment/bank_transfer_payment_method_specific_input_base.rb +32 -0
  113. data/lib/ingenico/connect/sdk/domain/payment/bank_transfer_payment_method_specific_output.rb +16 -0
  114. data/lib/ingenico/connect/sdk/domain/payment/cancel_approval_payment_response.rb +36 -0
  115. data/lib/ingenico/connect/sdk/domain/payment/cancel_payment_card_payment_method_specific_output.rb +32 -0
  116. data/lib/ingenico/connect/sdk/domain/payment/cancel_payment_response.rb +47 -0
  117. data/lib/ingenico/connect/sdk/domain/payment/card_payment_method_specific_input.rb +61 -0
  118. data/lib/ingenico/connect/sdk/domain/payment/card_payment_method_specific_input_base.rb +60 -0
  119. data/lib/ingenico/connect/sdk/domain/payment/card_payment_method_specific_output.rb +65 -0
  120. data/lib/ingenico/connect/sdk/domain/payment/cash_payment_method_specific_input.rb +47 -0
  121. data/lib/ingenico/connect/sdk/domain/payment/cash_payment_method_specific_input_base.rb +16 -0
  122. data/lib/ingenico/connect/sdk/domain/payment/cash_payment_method_specific_output.rb +16 -0
  123. data/lib/ingenico/connect/sdk/domain/payment/cash_payment_product1503_specific_input.rb +32 -0
  124. data/lib/ingenico/connect/sdk/domain/payment/cash_payment_product1504_specific_input.rb +32 -0
  125. data/lib/ingenico/connect/sdk/domain/payment/contact_details.rb +39 -0
  126. data/lib/ingenico/connect/sdk/domain/payment/create_payment_request.rb +131 -0
  127. data/lib/ingenico/connect/sdk/domain/payment/create_payment_response.rb +16 -0
  128. data/lib/ingenico/connect/sdk/domain/payment/create_payment_result.rb +58 -0
  129. data/lib/ingenico/connect/sdk/domain/payment/customer.rb +83 -0
  130. data/lib/ingenico/connect/sdk/domain/payment/external_cardholder_authentication_data.rb +60 -0
  131. data/lib/ingenico/connect/sdk/domain/payment/invoice_payment_method_specific_input.rb +32 -0
  132. data/lib/ingenico/connect/sdk/domain/payment/invoice_payment_method_specific_output.rb +16 -0
  133. data/lib/ingenico/connect/sdk/domain/payment/level3_summary_data.rb +46 -0
  134. data/lib/ingenico/connect/sdk/domain/payment/line_item.rb +58 -0
  135. data/lib/ingenico/connect/sdk/domain/payment/line_item_invoice_data.rb +60 -0
  136. data/lib/ingenico/connect/sdk/domain/payment/line_item_level3_interchange_information.rb +81 -0
  137. data/lib/ingenico/connect/sdk/domain/payment/merchant_action.rb +64 -0
  138. data/lib/ingenico/connect/sdk/domain/payment/non_sepa_direct_debit_payment_method_specific_input.rb +71 -0
  139. data/lib/ingenico/connect/sdk/domain/payment/non_sepa_direct_debit_payment_method_specific_output.rb +36 -0
  140. data/lib/ingenico/connect/sdk/domain/payment/non_sepa_direct_debit_payment_product705_specific_input.rb +50 -0
  141. data/lib/ingenico/connect/sdk/domain/payment/order.rb +83 -0
  142. data/lib/ingenico/connect/sdk/domain/payment/order_approve_payment.rb +47 -0
  143. data/lib/ingenico/connect/sdk/domain/payment/order_invoice_data.rb +59 -0
  144. data/lib/ingenico/connect/sdk/domain/payment/order_output.rb +47 -0
  145. data/lib/ingenico/connect/sdk/domain/payment/order_references.rb +57 -0
  146. data/lib/ingenico/connect/sdk/domain/payment/order_references_approve_payment.rb +32 -0
  147. data/lib/ingenico/connect/sdk/domain/payment/order_type_information.rb +39 -0
  148. data/lib/ingenico/connect/sdk/domain/payment/payment.rb +54 -0
  149. data/lib/ingenico/connect/sdk/domain/payment/payment_approval_response.rb +47 -0
  150. data/lib/ingenico/connect/sdk/domain/payment/payment_creation_output.rb +39 -0
  151. data/lib/ingenico/connect/sdk/domain/payment/payment_creation_references.rb +39 -0
  152. data/lib/ingenico/connect/sdk/domain/payment/payment_error_response.rb +57 -0
  153. data/lib/ingenico/connect/sdk/domain/payment/payment_output.rb +116 -0
  154. data/lib/ingenico/connect/sdk/domain/payment/payment_product836_specific_output.rb +32 -0
  155. data/lib/ingenico/connect/sdk/domain/payment/payment_product840_customer_account.rb +88 -0
  156. data/lib/ingenico/connect/sdk/domain/payment/payment_product840_specific_output.rb +47 -0
  157. data/lib/ingenico/connect/sdk/domain/payment/payment_references.rb +67 -0
  158. data/lib/ingenico/connect/sdk/domain/payment/payment_response.rb +16 -0
  159. data/lib/ingenico/connect/sdk/domain/payment/payment_status_output.rb +39 -0
  160. data/lib/ingenico/connect/sdk/domain/payment/personal_information.rb +50 -0
  161. data/lib/ingenico/connect/sdk/domain/payment/personal_name.rb +32 -0
  162. data/lib/ingenico/connect/sdk/domain/payment/redirect_data.rb +39 -0
  163. data/lib/ingenico/connect/sdk/domain/payment/redirect_payment_method_specific_input.rb +72 -0
  164. data/lib/ingenico/connect/sdk/domain/payment/redirect_payment_method_specific_input_base.rb +39 -0
  165. data/lib/ingenico/connect/sdk/domain/payment/redirect_payment_method_specific_output.rb +58 -0
  166. data/lib/ingenico/connect/sdk/domain/payment/redirect_payment_product809_specific_input.rb +39 -0
  167. data/lib/ingenico/connect/sdk/domain/payment/redirect_payment_product816_specific_input.rb +36 -0
  168. data/lib/ingenico/connect/sdk/domain/payment/redirect_payment_product882_specific_input.rb +32 -0
  169. data/lib/ingenico/connect/sdk/domain/payment/refund_bank_method_specific_output.rb +16 -0
  170. data/lib/ingenico/connect/sdk/domain/payment/refund_card_method_specific_output.rb +16 -0
  171. data/lib/ingenico/connect/sdk/domain/payment/refund_e_wallet_method_specific_output.rb +36 -0
  172. data/lib/ingenico/connect/sdk/domain/payment/refund_method_specific_output.rb +39 -0
  173. data/lib/ingenico/connect/sdk/domain/payment/refund_output.rb +72 -0
  174. data/lib/ingenico/connect/sdk/domain/payment/refund_payment_product840_customer_account.rb +46 -0
  175. data/lib/ingenico/connect/sdk/domain/payment/refund_payment_product840_specific_output.rb +36 -0
  176. data/lib/ingenico/connect/sdk/domain/payment/sepa_direct_debit_payment_method_specific_input.rb +60 -0
  177. data/lib/ingenico/connect/sdk/domain/payment/sepa_direct_debit_payment_method_specific_output.rb +36 -0
  178. data/lib/ingenico/connect/sdk/domain/payment/three_d_secure_results.rb +46 -0
  179. data/lib/ingenico/connect/sdk/domain/payment/tokenize_payment_request.rb +32 -0
  180. data/lib/ingenico/connect/sdk/domain/payout/approve_payout_request.rb +32 -0
  181. data/lib/ingenico/connect/sdk/domain/payout/create_payout_request.rb +101 -0
  182. data/lib/ingenico/connect/sdk/domain/payout/payout_customer.rb +76 -0
  183. data/lib/ingenico/connect/sdk/domain/payout/payout_error_response.rb +57 -0
  184. data/lib/ingenico/connect/sdk/domain/payout/payout_references.rb +46 -0
  185. data/lib/ingenico/connect/sdk/domain/payout/payout_response.rb +16 -0
  186. data/lib/ingenico/connect/sdk/domain/payout/payout_result.rb +54 -0
  187. data/lib/ingenico/connect/sdk/domain/product/account_on_file.rb +64 -0
  188. data/lib/ingenico/connect/sdk/domain/product/account_on_file_attribute.rb +39 -0
  189. data/lib/ingenico/connect/sdk/domain/product/account_on_file_display_hints.rb +46 -0
  190. data/lib/ingenico/connect/sdk/domain/product/directory.rb +39 -0
  191. data/lib/ingenico/connect/sdk/domain/product/directory_entry.rb +59 -0
  192. data/lib/ingenico/connect/sdk/domain/product/empty_validator.rb +16 -0
  193. data/lib/ingenico/connect/sdk/domain/product/fixed_list_validator.rb +38 -0
  194. data/lib/ingenico/connect/sdk/domain/product/label_template_element.rb +39 -0
  195. data/lib/ingenico/connect/sdk/domain/product/length_validator.rb +39 -0
  196. data/lib/ingenico/connect/sdk/domain/product/payment_product.rb +134 -0
  197. data/lib/ingenico/connect/sdk/domain/product/payment_product_display_hints.rb +46 -0
  198. data/lib/ingenico/connect/sdk/domain/product/payment_product_field.rb +61 -0
  199. data/lib/ingenico/connect/sdk/domain/product/payment_product_field_data_restrictions.rb +43 -0
  200. data/lib/ingenico/connect/sdk/domain/product/payment_product_field_display_hints.rb +96 -0
  201. data/lib/ingenico/connect/sdk/domain/product/payment_product_field_form_element.rb +46 -0
  202. data/lib/ingenico/connect/sdk/domain/product/payment_product_field_tooltip.rb +39 -0
  203. data/lib/ingenico/connect/sdk/domain/product/payment_product_field_validators.rb +100 -0
  204. data/lib/ingenico/connect/sdk/domain/product/payment_product_group.rb +71 -0
  205. data/lib/ingenico/connect/sdk/domain/product/payment_product_group_response.rb +16 -0
  206. data/lib/ingenico/connect/sdk/domain/product/payment_product_groups.rb +39 -0
  207. data/lib/ingenico/connect/sdk/domain/product/payment_product_response.rb +16 -0
  208. data/lib/ingenico/connect/sdk/domain/product/payment_products.rb +39 -0
  209. data/lib/ingenico/connect/sdk/domain/product/range_validator.rb +39 -0
  210. data/lib/ingenico/connect/sdk/domain/product/regular_expression_validator.rb +32 -0
  211. data/lib/ingenico/connect/sdk/domain/product/value_mapping_element.rb +39 -0
  212. data/lib/ingenico/connect/sdk/domain/refund/approve_refund_request.rb +32 -0
  213. data/lib/ingenico/connect/sdk/domain/refund/bank_account_bban_refund.rb +39 -0
  214. data/lib/ingenico/connect/sdk/domain/refund/bank_refund_method_specific_input.rb +54 -0
  215. data/lib/ingenico/connect/sdk/domain/refund/refund_customer.rb +58 -0
  216. data/lib/ingenico/connect/sdk/domain/refund/refund_error_response.rb +57 -0
  217. data/lib/ingenico/connect/sdk/domain/refund/refund_references.rb +32 -0
  218. data/lib/ingenico/connect/sdk/domain/refund/refund_request.rb +76 -0
  219. data/lib/ingenico/connect/sdk/domain/refund/refund_response.rb +16 -0
  220. data/lib/ingenico/connect/sdk/domain/refund/refund_result.rb +54 -0
  221. data/lib/ingenico/connect/sdk/domain/riskassessments/customer_risk_assessment.rb +65 -0
  222. data/lib/ingenico/connect/sdk/domain/riskassessments/order_risk_assessment.rb +58 -0
  223. data/lib/ingenico/connect/sdk/domain/riskassessments/personal_information_risk_assessment.rb +36 -0
  224. data/lib/ingenico/connect/sdk/domain/riskassessments/personal_name_risk_assessment.rb +16 -0
  225. data/lib/ingenico/connect/sdk/domain/riskassessments/risk_assessment.rb +54 -0
  226. data/lib/ingenico/connect/sdk/domain/riskassessments/risk_assessment_bank_account.rb +47 -0
  227. data/lib/ingenico/connect/sdk/domain/riskassessments/risk_assessment_card.rb +36 -0
  228. data/lib/ingenico/connect/sdk/domain/riskassessments/risk_assessment_response.rb +39 -0
  229. data/lib/ingenico/connect/sdk/domain/services/bank_data.rb +53 -0
  230. data/lib/ingenico/connect/sdk/domain/services/bank_details.rb +47 -0
  231. data/lib/ingenico/connect/sdk/domain/services/bank_details_request.rb +16 -0
  232. data/lib/ingenico/connect/sdk/domain/services/bank_details_response.rb +69 -0
  233. data/lib/ingenico/connect/sdk/domain/services/convert_amount.rb +32 -0
  234. data/lib/ingenico/connect/sdk/domain/services/get_iin_details_request.rb +43 -0
  235. data/lib/ingenico/connect/sdk/domain/services/get_iin_details_response.rb +60 -0
  236. data/lib/ingenico/connect/sdk/domain/services/iin_detail.rb +39 -0
  237. data/lib/ingenico/connect/sdk/domain/services/payment_context.rb +50 -0
  238. data/lib/ingenico/connect/sdk/domain/services/swift.rb +95 -0
  239. data/lib/ingenico/connect/sdk/domain/services/test_connection.rb +32 -0
  240. data/lib/ingenico/connect/sdk/domain/sessions/payment_product_filters_client_session.rb +46 -0
  241. data/lib/ingenico/connect/sdk/domain/sessions/session_request.rb +49 -0
  242. data/lib/ingenico/connect/sdk/domain/sessions/session_response.rb +59 -0
  243. data/lib/ingenico/connect/sdk/domain/token/abstract_token.rb +32 -0
  244. data/lib/ingenico/connect/sdk/domain/token/approve_token_request.rb +16 -0
  245. data/lib/ingenico/connect/sdk/domain/token/contact_details_token.rb +16 -0
  246. data/lib/ingenico/connect/sdk/domain/token/create_token_request.rb +76 -0
  247. data/lib/ingenico/connect/sdk/domain/token/create_token_response.rb +39 -0
  248. data/lib/ingenico/connect/sdk/domain/token/creditor.rb +102 -0
  249. data/lib/ingenico/connect/sdk/domain/token/customer_token.rb +47 -0
  250. data/lib/ingenico/connect/sdk/domain/token/customer_token_with_contact_details.rb +36 -0
  251. data/lib/ingenico/connect/sdk/domain/token/debtor.rb +102 -0
  252. data/lib/ingenico/connect/sdk/domain/token/mandate_approval.rb +46 -0
  253. data/lib/ingenico/connect/sdk/domain/token/mandate_non_sepa_direct_debit.rb +36 -0
  254. data/lib/ingenico/connect/sdk/domain/token/mandate_sepa_direct_debit.rb +36 -0
  255. data/lib/ingenico/connect/sdk/domain/token/mandate_sepa_direct_debit_with_mandate_id.rb +32 -0
  256. data/lib/ingenico/connect/sdk/domain/token/mandate_sepa_direct_debit_without_creditor.rb +79 -0
  257. data/lib/ingenico/connect/sdk/domain/token/personal_information_token.rb +36 -0
  258. data/lib/ingenico/connect/sdk/domain/token/personal_name_token.rb +16 -0
  259. data/lib/ingenico/connect/sdk/domain/token/token_card.rb +47 -0
  260. data/lib/ingenico/connect/sdk/domain/token/token_card_data.rb +50 -0
  261. data/lib/ingenico/connect/sdk/domain/token/token_e_wallet.rb +47 -0
  262. data/lib/ingenico/connect/sdk/domain/token/token_e_wallet_data.rb +32 -0
  263. data/lib/ingenico/connect/sdk/domain/token/token_non_sepa_direct_debit.rb +47 -0
  264. data/lib/ingenico/connect/sdk/domain/token/token_non_sepa_direct_debit_payment_product705_specific_data.rb +43 -0
  265. data/lib/ingenico/connect/sdk/domain/token/token_response.rb +83 -0
  266. data/lib/ingenico/connect/sdk/domain/token/token_sepa_direct_debit.rb +47 -0
  267. data/lib/ingenico/connect/sdk/domain/token/token_sepa_direct_debit_without_creditor.rb +47 -0
  268. data/lib/ingenico/connect/sdk/domain/token/update_token_request.rb +76 -0
  269. data/lib/ingenico/connect/sdk/endpoint_configuration.rb +139 -0
  270. data/lib/ingenico/connect/sdk/exceptions.rb +8 -0
  271. data/lib/ingenico/connect/sdk/factory.rb +200 -0
  272. data/lib/ingenico/connect/sdk/global_collect_exception.rb +15 -0
  273. data/lib/ingenico/connect/sdk/idempotence_exception.rb +24 -0
  274. data/lib/ingenico/connect/sdk/logging.rb +10 -0
  275. data/lib/ingenico/connect/sdk/logging/communicator_logger.rb +19 -0
  276. data/lib/ingenico/connect/sdk/logging/log_message_builder.rb +61 -0
  277. data/lib/ingenico/connect/sdk/logging/logging_capable.rb +19 -0
  278. data/lib/ingenico/connect/sdk/logging/logging_util.rb +298 -0
  279. data/lib/ingenico/connect/sdk/logging/request_log_message_builder.rb +42 -0
  280. data/lib/ingenico/connect/sdk/logging/response_log_message_builder.rb +34 -0
  281. data/lib/ingenico/connect/sdk/logging/ruby_communicator_logger.rb +58 -0
  282. data/lib/ingenico/connect/sdk/logging/stdout_communicator_logger.rb +36 -0
  283. data/lib/ingenico/connect/sdk/marshaller.rb +19 -0
  284. data/lib/ingenico/connect/sdk/marshaller_syntax_exception.rb +6 -0
  285. data/lib/ingenico/connect/sdk/merchant/hostedcheckouts/hostedcheckouts_client.rb +88 -0
  286. data/lib/ingenico/connect/sdk/merchant/merchant_client.rb +110 -0
  287. data/lib/ingenico/connect/sdk/merchant/payments/payments_client.rb +319 -0
  288. data/lib/ingenico/connect/sdk/merchant/payouts/payouts_client.rb +197 -0
  289. data/lib/ingenico/connect/sdk/merchant/productgroups/find_productgroups_params.rb +55 -0
  290. data/lib/ingenico/connect/sdk/merchant/productgroups/get_productgroup_params.rb +55 -0
  291. data/lib/ingenico/connect/sdk/merchant/productgroups/productgroups_client.rb +90 -0
  292. data/lib/ingenico/connect/sdk/merchant/products/directory_params.rb +31 -0
  293. data/lib/ingenico/connect/sdk/merchant/products/find_products_params.rb +55 -0
  294. data/lib/ingenico/connect/sdk/merchant/products/get_product_params.rb +55 -0
  295. data/lib/ingenico/connect/sdk/merchant/products/products_client.rb +124 -0
  296. data/lib/ingenico/connect/sdk/merchant/refunds/refunds_client.rb +154 -0
  297. data/lib/ingenico/connect/sdk/merchant/riskassessments/riskassessments_client.rb +85 -0
  298. data/lib/ingenico/connect/sdk/merchant/services/convert_amount_params.rb +35 -0
  299. data/lib/ingenico/connect/sdk/merchant/services/services_client.rb +149 -0
  300. data/lib/ingenico/connect/sdk/merchant/sessions/sessions_client.rb +55 -0
  301. data/lib/ingenico/connect/sdk/merchant/tokens/delete_token_params.rb +27 -0
  302. data/lib/ingenico/connect/sdk/merchant/tokens/tokens_client.rb +192 -0
  303. data/lib/ingenico/connect/sdk/meta_data_provider.rb +152 -0
  304. data/lib/ingenico/connect/sdk/modules.rb +130 -0
  305. data/lib/ingenico/connect/sdk/not_found_exception.rb +19 -0
  306. data/lib/ingenico/connect/sdk/param_request.rb +33 -0
  307. data/lib/ingenico/connect/sdk/pooled_connection.rb +21 -0
  308. data/lib/ingenico/connect/sdk/proxy_configuration.rb +75 -0
  309. data/lib/ingenico/connect/sdk/reference_exception.rb +14 -0
  310. data/lib/ingenico/connect/sdk/request_header.rb +25 -0
  311. data/lib/ingenico/connect/sdk/request_param.rb +24 -0
  312. data/lib/ingenico/connect/sdk/response.rb +62 -0
  313. data/lib/ingenico/connect/sdk/response_exception.rb +54 -0
  314. data/lib/ingenico/connect/sdk/response_header.rb +25 -0
  315. data/lib/ingenico/connect/sdk/session.rb +39 -0
  316. data/lib/ingenico/connect/sdk/validation_exception.rb +14 -0
  317. data/spec/comparable_extension.rb +29 -0
  318. data/spec/fixtures/resources/defaultimpl/convertAmount.json +3 -0
  319. data/spec/fixtures/resources/defaultimpl/createPayment.failure.invalidCardNumber.json +11 -0
  320. data/spec/fixtures/resources/defaultimpl/createPayment.failure.rejected.json +48 -0
  321. data/spec/fixtures/resources/defaultimpl/createPayment.json +40 -0
  322. data/spec/fixtures/resources/defaultimpl/idempotence_duplicate_failure.json +8 -0
  323. data/spec/fixtures/resources/defaultimpl/idempotence_rejected.json +46 -0
  324. data/spec/fixtures/resources/defaultimpl/idempotence_success.json +39 -0
  325. data/spec/fixtures/resources/defaultimpl/notFound.html +1 -0
  326. data/spec/fixtures/resources/defaultimpl/testConnection.json +3 -0
  327. data/spec/fixtures/resources/defaultimpl/unknownServerError.json +10 -0
  328. data/spec/fixtures/resources/logging/bodyNoObfuscation.json +17 -0
  329. data/spec/fixtures/resources/logging/bodyWithBinObfuscated.json +3 -0
  330. data/spec/fixtures/resources/logging/bodyWithBinOriginal.json +3 -0
  331. data/spec/fixtures/resources/logging/bodyWithCardObfuscated.json +21 -0
  332. data/spec/fixtures/resources/logging/bodyWithCardOriginal.json +21 -0
  333. data/spec/fixtures/resources/logging/bodyWithIbanObfuscated.json +19 -0
  334. data/spec/fixtures/resources/logging/bodyWithIbanOriginal.json +19 -0
  335. data/spec/fixtures/resources/payment/duplicate_request.json +8 -0
  336. data/spec/fixtures/resources/payment/invalid_authorization.json +9 -0
  337. data/spec/fixtures/resources/payment/invalid_request.json +11 -0
  338. data/spec/fixtures/resources/payment/method_not_allowed.html +1 -0
  339. data/spec/fixtures/resources/payment/not_found.html +1 -0
  340. data/spec/fixtures/resources/payment/pending_approval.json +39 -0
  341. data/spec/fixtures/resources/payment/rejected.json +46 -0
  342. data/spec/fixtures/resources/properties.proxy.yml +13 -0
  343. data/spec/fixtures/resources/properties.yml +7 -0
  344. data/spec/integration/connection_pooling_spec.rb +78 -0
  345. data/spec/integration/convert_amount_spec.rb +25 -0
  346. data/spec/integration/idempotence_spec.rb +59 -0
  347. data/spec/integration/multiline_header_spec.rb +30 -0
  348. data/spec/integration/payment_product_groups_spec.rb +23 -0
  349. data/spec/integration/payment_products_spec.rb +22 -0
  350. data/spec/integration/risk_assessments_spec.rb +37 -0
  351. data/spec/integration/sdk_proxy_spec.rb +89 -0
  352. data/spec/integration/token_spec.rb +42 -0
  353. data/spec/integration_setup.rb +50 -0
  354. data/spec/lib/client_spec.rb +69 -0
  355. data/spec/lib/communicator_configuration_spec.rb +179 -0
  356. data/spec/lib/communicator_spec.rb +31 -0
  357. data/spec/lib/defaultimpl/default_authenticator_spec.rb +74 -0
  358. data/spec/lib/defaultimpl/default_connection_idempotence_spec.rb +142 -0
  359. data/spec/lib/defaultimpl/default_connection_logger_spec.rb +526 -0
  360. data/spec/lib/defaultimpl/default_connection_spec.rb +334 -0
  361. data/spec/lib/defaultimpl/default_marshaller_spec.rb +36 -0
  362. data/spec/lib/factory_spec.rb +41 -0
  363. data/spec/lib/logging/header_obfuscator_spec.rb +51 -0
  364. data/spec/lib/logging/logging_util_spec.rb +143 -0
  365. data/spec/lib/logging/obfuscator_spec.rb +52 -0
  366. data/spec/lib/logging/ruby_communicator_logger_spec.rb +84 -0
  367. data/spec/lib/logging/stdout_communicator_logger_spec.rb +64 -0
  368. data/spec/lib/logging/value_obfuscator_spec.rb +95 -0
  369. data/spec/lib/meta_data_provider_spec.rb +71 -0
  370. data/spec/lib/payments_client_spec.rb +157 -0
  371. data/spec/lib/requestparams/delete_params_spec.rb +21 -0
  372. data/spec/lib/requestparams/directory_params_spec.rb +27 -0
  373. data/spec/lib/requestparams/find_params_spec.rb +58 -0
  374. data/spec/lib/requestparams/get_params_spec.rb +59 -0
  375. data/spec/lib/requestparams/param_request_spec.rb +57 -0
  376. data/spec/spec_helper.rb +23 -0
  377. metadata +565 -0
@@ -0,0 +1,15 @@
1
+ module Ingenico::Connect::SDK
2
+
3
+ # Abstract class that is responsible for authenticating requests sent to the GlobalCollect platform.
4
+ class Authenticator
5
+
6
+ # Creates a signature to authenticate a request.
7
+ # Uses the following parameters:
8
+ # http_method:: 'GET', 'PUT', 'POST' or 'DELETE' indicating which HTTP method will be used with the request
9
+ # resource_uri:: URI object that includes #path and #query of the url that will be used, #query may be *nil*
10
+ # request_headers:: {Ingenico::Connect::SDK::RequestHeader} list that contains all headers used by the request
11
+ def create_simple_authentication_signature(http_method, resource_uri, request_headers)
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Ingenico::Connect::SDK
2
+
3
+ # This exception is thrown when a request sent to the GlobalCollect platform is not correctly authenticated.
4
+ # Corresponds to a HTTP status code of 403.
5
+ # @see ApiException#initialize
6
+ class AuthorizationException < ApiException
7
+
8
+ def initialize(status_code, response_body, error_id, errors,
9
+ message='the GlobalCollect platform returned an authorization error response')
10
+ super(status_code, response_body, error_id, errors, message)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Ingenico::Connect::SDK
2
+
3
+ # A CallContext is used to identify requests and manage idempotent requests.
4
+ # A CallContext contains the following:
5
+ #
6
+ # idempotence_key:: A randomly generated key used to identify requests
7
+ # idempotence_request_timestamp:: If a previous request arrived with the same idempotence key,
8
+ # this value will be set to a timestamp of that request.
9
+ class CallContext
10
+ @idempotence_request_timestamp = nil
11
+ @idempotence_key = nil
12
+
13
+ def initialize(idempotence_key=nil)
14
+ @idempotence_key = idempotence_key
15
+ end
16
+
17
+ # The idempotence key used to identify this request.
18
+ # If two requests share the same _idempotence_key_, they are considered to be the same request
19
+ # and only the first request will be processed.
20
+ attr_reader :idempotence_key
21
+
22
+ # If two or more requests arrive at the GlobalCollect platform with the same _idempotence_key_,
23
+ # the _idempotence_request_timestamp_ will be set to the arrival time of the first of these requests.
24
+ attr_accessor :idempotence_request_timestamp
25
+ end
26
+ end
@@ -0,0 +1,92 @@
1
+ #
2
+ # This class was auto-generated from the API references found at
3
+ # https://developer.globalcollect.com/documentation/api/server/
4
+ #
5
+ require 'ingenico/connect/sdk/api_resource'
6
+ require 'ingenico/connect/sdk/data_object'
7
+ require 'ingenico/connect/sdk/logging/logging_capable'
8
+ require 'ingenico/connect/sdk/merchant/merchant_client'
9
+ require 'base64'
10
+
11
+ module Ingenico
12
+ module Connect
13
+ module SDK
14
+
15
+ # GlobalCollect platform client.
16
+ #
17
+ # This client and all its child clients are bound to one specific value for the X-GCS-ClientMetaInfo header.
18
+ #
19
+ # To get a new client with a different header value, use with_client_meta_info.
20
+ #
21
+ # Thread safe.
22
+ class Client < ApiResource
23
+ include Logging::LoggingCapable
24
+
25
+ def self.API_VERSION
26
+ 'v1'
27
+ end
28
+
29
+ # communicator:: Ingenico::Connect::SDK::Communicator
30
+ # client_meta_info:: String
31
+ def initialize(communicator, client_meta_info=nil)
32
+ super(communicator, {'apiVersion' => Client.API_VERSION}, client_meta_info)
33
+ end
34
+
35
+ # client_meta_info:: JSON string containing the meta data for the client
36
+ # Returns:: A Client which uses the passed meta data for the X-GCS-ClientMetaInfo header.
37
+ # Raises:: Ingenico::Connect::SDK::MarshallerSyntaxException if the given clientMetaInfo is not a valid JSON string
38
+ def with_client_meta_info(client_meta_info)
39
+ if @client_meta_info.nil? && client_meta_info.nil?
40
+ self
41
+ elsif client_meta_info.nil?
42
+ return Client.new(@communicator, nil)
43
+ else
44
+ # Checking to see if this is valid JSON (no JSON parse exceptions)
45
+ @communicator.marshaller.unmarshal(client_meta_info, DataObject)
46
+ client_meta_info = Base64.strict_encode64(client_meta_info)
47
+ if @client_meta_info == client_meta_info
48
+ self
49
+ else
50
+ return Client.new(@communicator, client_meta_info)
51
+ end
52
+ end
53
+ end
54
+
55
+ # Utility method that delegates the call to this client's communicator.
56
+ def close_idle_connections(idle_time)
57
+ @communicator.close_idle_connections(idle_time)
58
+ end
59
+
60
+ # Utility method that delegates the call to this client's communicator.
61
+ def close_expired_connections
62
+ @communicator.close_expired_connections
63
+ end
64
+
65
+ # Turns on logging using the given communicator logger.
66
+ # communicator_logger:: Ingenico::Connect::SDK::Logging::CommunicatorLogger
67
+ def enable_logging(communicator_logger)
68
+ @communicator.enable_logging(communicator_logger)
69
+ end
70
+
71
+ # Turns off logging.
72
+ def disable_logging
73
+ @communicator.disable_logging
74
+ end
75
+
76
+ # Releases any system resources associated with this object.
77
+ def close
78
+ @communicator.close
79
+ end
80
+
81
+ # Resource /{{merchantId}}
82
+ # merchant_id:: String
83
+ # Returns:: {Ingenico::Connect::SDK::Merchant::MerchantClient}
84
+ def merchant(merchant_id)
85
+ Ingenico::Connect::SDK::Merchant::MerchantClient.new(self, {
86
+ 'merchantId' => merchant_id,
87
+ })
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,15 @@
1
+ module Ingenico::Connect::SDK
2
+
3
+ # This exception is used when an error occurs during network communication with the GlobalCollect platform.
4
+ # A common cause is a timeout while connecting or when receiving or sending data.
5
+ class CommunicationException < RuntimeError
6
+
7
+ def initialize(cause)
8
+ super()
9
+ @cause = cause
10
+ end
11
+
12
+ # The error that is the cause of this error.
13
+ attr_accessor :cause
14
+ end
15
+ end
@@ -0,0 +1,277 @@
1
+ require 'uri'
2
+
3
+ module Ingenico::Connect::SDK
4
+
5
+ # Class responsible for facilitating communication with the GlobalCollect platform.
6
+ # It combines the following classes to provide communication functionality:
7
+ #
8
+ # session:: {Ingenico::Connect::SDK::Session} that stores data for network communication and facilitates network communication
9
+ # marshaller:: {Ingenico::Connect::SDK::Marshaller} that is used to marshal and unmarshal data to and from JSON format
10
+ #
11
+ class Communicator
12
+ include Logging::LoggingCapable
13
+
14
+ # Creates a new Communicator based on a session and marshaller.
15
+ #
16
+ # session:: {Ingenico::Connect::SDK::Session} that stores data for network communication and facilitates network communication
17
+ # marshaller:: {Ingenico::Connect::SDK::Marshaller} that is used to marshal and unmarshal data to and from JSON format
18
+ #
19
+ def initialize(session, marshaller)
20
+ if session.nil?
21
+ raise ArgumentError('session is required')
22
+ end
23
+ if marshaller.nil?
24
+ raise ArgumentError('marshaller is required')
25
+ end
26
+ @session = session
27
+ @marshaller = marshaller
28
+ end
29
+
30
+ # Performs a GET request to the GlobalCollect platform and returns the response as a {Ingenico::Connect::SDK::Response} object.
31
+ #
32
+ # Throws:
33
+ # ResponseException:: Thrown if the request could not be fulfilled successfully.
34
+ # This occurs for example if the request is not authenticated correctly
35
+ # NotFoundException:: Thrown if the requested resource is not found
36
+ # CommunicationException:: Thrown if there is an error in communicating with the GlobalCollect platform.
37
+ # This occurs for example if a timeout occurs.
38
+ def get(relative_path, request_headers, request_parameters, response_type, context)
39
+ connection = @session.connection
40
+ if request_parameters.nil?
41
+ request_parameter_list = nil
42
+ else
43
+ request_parameter_list = request_parameters.to_request_parameters
44
+ end
45
+ uri = to_absolute_uri(relative_path, request_parameter_list)
46
+ if request_headers.nil?
47
+ request_headers = []
48
+ end
49
+ add_generic_headers('GET', uri, request_headers, context)
50
+ response = connection.get(uri, request_headers)
51
+ process_response(response, response_type, relative_path, context)
52
+ end
53
+
54
+ # Performs a DELETE request to the GlobalCollect platform and returns the response as a {Ingenico::Connect::SDK::Response} object.
55
+ #
56
+ # Throws:
57
+ # ResponseException:: Thrown if the request could not be fulfilled successfully.
58
+ # This occurs for example if the request is not authenticated correctly.
59
+ # NotFoundException:: Thrown if the referred resource is not found.
60
+ # CommunicationException:: Thrown if there is an error in communicating with the GlobalCollect platform.
61
+ # This occurs for example if a timeout occurs.
62
+ def delete(relative_path, request_headers, request_parameters, response_type, context)
63
+ connection = @session.connection
64
+ if request_parameters.nil?
65
+ request_parameter_list = nil
66
+ else
67
+ request_parameter_list = request_parameters.to_request_parameters
68
+ end
69
+ uri = to_absolute_uri(relative_path, request_parameter_list)
70
+ if request_headers.nil?
71
+ request_headers = []
72
+ end
73
+ add_generic_headers('DELETE', uri, request_headers, context)
74
+ response = connection.delete(uri, request_headers)
75
+ process_response(response, response_type, relative_path, context)
76
+ end
77
+
78
+ # Performs a POST request to the GlobalCollect platform and returns the response as a {Ingenico::Connect::SDK::Response} object.
79
+ #
80
+ # Throws:
81
+ # ResponseException:: Thrown if the request could not be fulfilled successfully.
82
+ # This occurs for example if the request is not authenticated correctly.
83
+ # NotFoundException:: Thrown if the referred resource is not found.
84
+ # CommunicationException:: Thrown if there is an error in communicating with the GlobalCollect platform.
85
+ # This occurs for example if a timeout occurs.
86
+ def post(relative_path, request_headers, request_parameters, request_body,
87
+ response_type, context)
88
+ connection = @session.connection
89
+ if request_parameters.nil?
90
+ request_parameter_list = nil
91
+ else
92
+ request_parameter_list = request_parameters.to_request_parameters
93
+ end
94
+ uri = to_absolute_uri(relative_path, request_parameter_list)
95
+ if request_headers.nil?
96
+ request_headers = []
97
+ end
98
+ request_json = nil
99
+ unless request_body.nil?
100
+ request_headers.push(RequestHeader.new('Content-Type', 'application/json'))
101
+ request_json = @marshaller.marshal(request_body)
102
+ end
103
+ add_generic_headers('POST', uri, request_headers, context)
104
+ response = connection.post(uri, request_headers, request_json)
105
+ process_response(response, response_type, relative_path, context)
106
+ end
107
+
108
+ # Performs a PUT request to the GlobalCollect platform and returns the response as a {Ingenico::Connect::SDK::Response} object.
109
+ #
110
+ # Throws:
111
+ # ResponseException:: Thrown if the request could not be fulfilled successfully.
112
+ # This occurs for example if the request is not authenticated correctly.
113
+ # NotFoundException:: Thrown if the referred resource is not found.
114
+ # CommunicationException:: Thrown if there is an error in communicating with the GlobalCollect platform.
115
+ # This occurs for example if a timeout occurs.
116
+ def put(relative_path, request_headers, request_parameters, request_body,
117
+ response_type, context)
118
+ connection = @session.connection
119
+ if request_parameters.nil?
120
+ request_parameter_list = nil
121
+ else
122
+ request_parameter_list = request_parameters.to_request_parameters
123
+ end
124
+ uri = to_absolute_uri(relative_path, request_parameter_list)
125
+ if request_headers.nil?
126
+ request_headers = []
127
+ end
128
+ request_json = nil
129
+ unless request_body.nil?
130
+ request_headers.push(RequestHeader.new('Content-Type', 'application/json'))
131
+ request_json = @marshaller.marshal(request_body)
132
+ end
133
+ add_generic_headers('PUT', uri, request_headers, context)
134
+ response = connection.put(uri, request_headers, request_json)
135
+ process_response(response, response_type, relative_path, context)
136
+ end
137
+
138
+ # Closes any connections idle for more than _idle_time_ seconds.
139
+ # Will not have any effect if the connection is not a pooled connection (an instance of {Ingenico::Connect::SDK::PooledConnection}).
140
+ def close_idle_connections(idle_time)
141
+ connection = @session.connection
142
+ if connection.is_a? PooledConnection
143
+ connection.close_idle_connections(idle_time)
144
+ end
145
+ end
146
+
147
+ # Closes any connections that have expired.
148
+ # Will not have any effect if the connection is not a pooled connection (an instance of {Ingenico::Connect::SDK::PooledConnection}).
149
+ def close_expired_connections
150
+ connection = @session.connection
151
+ if connection.is_a? PooledConnection
152
+ connection.close_expired_connections
153
+ end
154
+ end
155
+
156
+ # Enables logging outgoing requests and incoming responses by registering the _communicator_logger_.
157
+ # Note that only one logger can be registered at a time and calling _enable_logging_
158
+ # a second time will override the old logger instance with the new one.
159
+ #
160
+ # communicator_logger:: The {Ingenico::Connect::SDK::Logging::CommunicatorLogger} the requests and responses are logged to
161
+ #
162
+ def enable_logging(communicator_logger)
163
+ @session.connection.enable_logging(communicator_logger)
164
+ end
165
+
166
+ # Disables logging by unregistering any previous logger that might be registered.
167
+ def disable_logging
168
+ @session.connection.disable_logging
169
+ end
170
+
171
+ # Frees networking resources by closing the underlying network connections.
172
+ # After calling _close_, any use of the _get_, _delete_, _post_ and _put_ methods will not function
173
+ # and likely result in an error.
174
+ def close
175
+ @session.connection.close
176
+ end
177
+
178
+ # A {Ingenico::Connect::SDK::Marshaller} instance used by the communicator for serializing/deserializing to/from JSON
179
+ attr_reader :marshaller
180
+
181
+ protected
182
+
183
+ # Constructs a full url using the base url stored in the {Ingenico::Connect::SDK::Session} and the given relative path and request_parameters.
184
+ # The returned url is a *URI* object.
185
+ #
186
+ # relative_path:: The relative path of the url in string form.
187
+ # request_parameters:: A list of request parameters that each have #name and #value
188
+ # which represent the parameter name and value respectively.
189
+ def to_absolute_uri(relative_path, request_parameters)
190
+ api_endpoint = @session.api_endpoint
191
+ unless api_endpoint.path.nil? || api_endpoint.path.empty?
192
+ raise RuntimeError('api_endpoint should not contain a path')
193
+ end
194
+ unless api_endpoint.userinfo.nil? && api_endpoint.query.nil? && api_endpoint.fragment.nil?
195
+ raise RuntimeError('api_endpoint should not contain user info, query or fragment')
196
+ end
197
+ absolute_path = relative_path.start_with?('/')? relative_path : '/'+relative_path
198
+ uri = URI::HTTP.new(api_endpoint.scheme, nil, api_endpoint.host,
199
+ api_endpoint.port, nil, absolute_path, nil, nil, nil)
200
+ unless request_parameters.nil?
201
+ for nvp in request_parameters
202
+ parameters = URI.decode_www_form(uri.query || '') << [nvp.name, nvp.value]
203
+ uri.query = URI.encode_www_form(parameters)
204
+ end
205
+ end
206
+ uri
207
+ end
208
+
209
+ # Adds several standard headers to the http headers.
210
+ #
211
+ # http_method:: 'GET', 'DELETE', 'POST' or 'PUT' depending on the HTTP method being used
212
+ # uri:: The full URI as a URI object to the GlobalCollect platform,
213
+ # including the relative path and request parameters.
214
+ # request_headers:: List of {Ingenico::Connect::SDK::RequestHeader} in which which new headers will be added
215
+ # context:: {Ingenico::Connect::SDK::CallContext} object that will be used to produce
216
+ # an Idempotence header to prevent accidental request duplication.
217
+ #
218
+ # This method will add the 'Date' and 'Authorization' header;
219
+ # the 'X-GCS-Idempotence-Key' header will also be added if an idempotence context is given
220
+ def add_generic_headers(http_method, uri, request_headers, context = nil)
221
+ request_headers.concat(@session.meta_data_provider.meta_data_headers)
222
+ request_headers.push(RequestHeader.new('Date', get_header_date_string))
223
+ if !context.nil? && !context.idempotence_key.nil?
224
+ request_headers.push(RequestHeader.new('X-GCS-Idempotence-Key', context.idempotence_key))
225
+ end
226
+ authenticator = @session.authenticator
227
+ authentication_signature = authenticator.create_simple_authentication_signature(http_method, uri, request_headers)
228
+ request_headers.push(RequestHeader.new('Authorization', authentication_signature))
229
+ end
230
+
231
+ def get_header_date_string
232
+ Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
233
+ end
234
+
235
+ def process_response(response, response_type, request_path, context)
236
+ update_context(response, context) unless context.nil?
237
+
238
+ throw_exception_if_necessary(response, request_path)
239
+ @marshaller.unmarshal(response.body, response_type)
240
+ end
241
+
242
+ def update_context(response, context)
243
+ idempotence_request_timestamp_value = response.get_header_value('X-GCS-Idempotence-Request-Timestamp')
244
+ if idempotence_request_timestamp_value.nil?
245
+ context.idempotence_request_timestamp = nil
246
+ else
247
+ context.idempotence_request_timestamp = idempotence_request_timestamp_value
248
+ end
249
+ end
250
+
251
+ def throw_exception_if_necessary(response, request_path)
252
+ status_code = response.status_code
253
+ if status_code < 200 || status_code >= 300
254
+ body = response.body
255
+ if !body.nil? && !is_json(response)
256
+ cause = ResponseException.new(response)
257
+ if status_code == 404
258
+ raise NotFoundException.new(cause, 'The requested resource was not found; invalid path: ' +
259
+ request_path)
260
+ else
261
+ raise CommunicationException.new(cause)
262
+ end
263
+ else
264
+ raise ResponseException.new(response)
265
+ end
266
+ end
267
+ end
268
+
269
+ private
270
+
271
+ def is_json(response)
272
+ content_type = response.get_header_value('Content-Type')
273
+ content_type.nil? || 'application/json'.casecmp(content_type) == 0 ||
274
+ content_type.downcase.start_with?('application/json')
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,98 @@
1
+ module Ingenico::Connect::SDK
2
+
3
+ # A CommunicatorConfiguration stores all data used to initialize an {Ingenico::Connect::SDK::Communicator}. It stores the following:
4
+ #
5
+ # api_endpoint:: The base url to the GlobalCollect platform.
6
+ # api_key_id:: The identifier of the _secret_api_key_ used to authenticate requests.
7
+ # secret_api_key:: The key used to authenticate requests sent to the GlobalCollect platform.
8
+ # authorization_type:: String describing the authorization protocol to follow.
9
+ # connect_timeout:: The number of seconds before a connection attempt with the GlobalCollect platform times out.
10
+ # socket_timeout:: The number of seconds before a timeout occurs
11
+ # when transmitting data to or from the GlobalCollect platform.
12
+ # max_connections:: The number of connections with the GlobalCollect platform
13
+ # that are kept alive in the connection pool. These connections will be reused when possible.
14
+ # proxy_configuration:: {Ingenico::Connect::SDK::ProxyConfiguration} instance that stores the url to a proxy to be used in all communication,
15
+ # or nil if no proxy should be used.
16
+ # integrator:: String
17
+ # shopping_cart_extension:: {Ingenico::Connect::SDK::Domain::Metadata::ShoppingCartExtension} that stores shopping cart-related metadata.
18
+ class CommunicatorConfiguration < EndpointConfiguration
19
+
20
+ # Creates a new CommunicatorConfiguration instance, it accepts the following arguments:
21
+ #
22
+ # properties:: A hash that may contain any of the other parameters.
23
+ # If a parameter is given in both the _properties_ and separately,
24
+ # the separate value takes precedence.
25
+ # api_endpoint:: The base url to the GlobalCollect platform.
26
+ # api_key_id:: The identifier of the _secret_api_key_ used to authenticate requests.
27
+ # secret_api_key:: The key used to authenticate requests sent to the GlobalCollect platform.
28
+ # authorization_type:: String describing the authorization protocol to follow.
29
+ # connect_timeout:: The number of seconds before a connection attempt with the GlobalCollect platform times out.
30
+ # socket_timeout:: The number of seconds before a timeout occurs
31
+ # when transmitting data to or from the GlobalCollect platform.
32
+ # max_connections:: The number of connections with the GlobalCollect platform
33
+ # that are kept alive in the connection pool. These connections will be reused when possible.
34
+ # proxy_configuration:: {Ingenico::Connect::SDK::ProxyConfiguration} instance that stores the url to a proxy to be used in all communication,
35
+ # or nil if no proxy should be used.
36
+ # integrator:: String
37
+ # shopping_cart_extension:: {Ingenico::Connect::SDK::Domain::Metadata::ShoppingCartExtension} that stores shopping cart-related metadata.
38
+ #
39
+ # If a _properties_ object is given, it will be parsed like a hash in order to read these attributes.
40
+ # If a value is given in both the _properties_ hash and as a separate parameter,
41
+ # the separate parameter will take precedence over the value in the properties.
42
+ def initialize(properties: nil, api_endpoint: nil, api_key_id: nil,
43
+ secret_api_key: nil, authorization_type: nil,
44
+ connect_timeout: nil, socket_timeout: nil,
45
+ max_connections: nil, proxy_configuration: nil,
46
+ integrator: nil, shopping_cart_extension: nil)
47
+ if properties
48
+ super(properties, 'connect.api')
49
+ unless properties.nil?
50
+ @authorization_type = DefaultImpl::AuthorizationType.get_authorization(
51
+ properties['connect.api.authorizationType'])
52
+ end
53
+ end
54
+ if api_endpoint
55
+ @api_endpoint = api_endpoint
56
+ end
57
+ if api_key_id
58
+ @api_key_id = api_key_id
59
+ end
60
+ if secret_api_key
61
+ @secret_api_key = secret_api_key
62
+ end
63
+ if authorization_type
64
+ @authorization_type = authorization_type
65
+ end
66
+ if connect_timeout
67
+ @connect_timeout = connect_timeout
68
+ end
69
+ if socket_timeout
70
+ @socket_timeout = socket_timeout
71
+ end
72
+ if max_connections
73
+ @max_connections = max_connections
74
+ end
75
+ if proxy_configuration
76
+ @proxy_configuration = proxy_configuration
77
+ end
78
+ if integrator
79
+ @integrator = integrator
80
+ end
81
+ if shopping_cart_extension
82
+ @shopping_cart_extension = shopping_cart_extension
83
+ end
84
+ end
85
+
86
+ # Base URL to the GlobalCollect platform
87
+ attr_accessor :api_endpoint
88
+
89
+ # Identifier of the _secret_api_key_ used in authentication.
90
+ attr_accessor :api_key_id
91
+
92
+ # Secret key used in authentication
93
+ attr_accessor :secret_api_key
94
+
95
+ # String representing the authentication algorithm used
96
+ attr_accessor :authorization_type
97
+ end
98
+ end