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,142 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+
4
+ Payments ||= Ingenico::Connect::SDK::Domain::Payment
5
+ Definitions ||= Ingenico::Connect::SDK::Domain::Definitions
6
+
7
+
8
+ describe 'DefaultConnectionIdempotence' do
9
+
10
+ CallContext = Ingenico::Connect::SDK::CallContext
11
+ base_headers = {'dummy' => 'none'}
12
+ resource_prefix = 'spec/fixtures/resources/defaultimpl/'
13
+
14
+ it 'should be able to send a request with idempotence key' do
15
+ response_body = IO.read(resource_prefix + 'idempotence_success.json')
16
+ idempotence_key = SecureRandom.uuid
17
+ call_context = CallContext.new(idempotence_key)
18
+ request = create_payment_request
19
+
20
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/20000/payments')
21
+ .with(headers: {'X-GCS-Idempotence-Key' => idempotence_key})
22
+ .to_return(status: 201, body: response_body,
23
+ headers: base_headers.merge({'Content-Type' => 'application/json', 'Location' => 'api-sandbox.globalcollect.com/v1/20000/payments/000002000020142549460000100001'}))
24
+
25
+ response = CLIENT.merchant('20000').payments.create(request, call_context)
26
+
27
+ expect(response).to_not be_nil
28
+ expect(response.payment).to_not be_nil
29
+ expect(response.payment.id).to_not be_nil
30
+ expect(call_context.idempotence_key).to eq(idempotence_key)
31
+ end
32
+
33
+ it 'properly reports when the request has arrived prior' do
34
+ response_body = IO.read(resource_prefix + 'idempotence_success.json')
35
+ idempotence_key = SecureRandom.uuid
36
+ idempotence_timestamp = Time.now.to_f*1000 # Convert time to milliseconds
37
+ call_context = CallContext.new(idempotence_key)
38
+ request = create_payment_request
39
+
40
+
41
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/20000/payments')
42
+ .with(headers: {'X-GCS-Idempotence-Key' => idempotence_key})
43
+ .to_return(status: 201, body: response_body,
44
+ headers: base_headers.merge({'Content-Type' => 'application/json',
45
+ 'Location' => 'api-sandbox.globalcollect.com/v1/20000/payments/000002000020142549460000100001',
46
+ 'X-GCS-Idempotence-Request-Timestamp' => idempotence_timestamp}))
47
+
48
+ response = CLIENT.merchant('20000').payments.create(request, call_context)
49
+
50
+ expect(response).to_not be_nil
51
+ expect(response.payment).to_not be_nil
52
+ expect(response.payment.id).to_not be_nil
53
+ expect(call_context.idempotence_key).to eq(idempotence_key)
54
+ expect(call_context.idempotence_request_timestamp.to_s).to eq(idempotence_timestamp.to_s)
55
+ end
56
+
57
+ it 'throws an exception when payment is refused' do
58
+ response_body = IO.read(resource_prefix + 'idempotence_rejected.json')
59
+ idempotence_key = SecureRandom.uuid
60
+ call_context = CallContext.new(idempotence_key)
61
+ request = create_payment_request
62
+
63
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/20000/payments')
64
+ .with(headers: {'X-GCS-Idempotence-Key' => idempotence_key})
65
+ .to_return(status: 402, body: response_body,
66
+ headers: base_headers.merge({'Content-Type' => 'application/json'}))
67
+
68
+ expect{response = CLIENT.merchant('20000').payments.create(request, call_context)}.
69
+ to raise_error(Ingenico::Connect::SDK::DeclinedPaymentException){ |err|
70
+ expect(err.status_code).to be(402)
71
+ expect(err.response_body).to be(response_body)
72
+ expect(call_context.idempotence_key).to eq(idempotence_key)
73
+ expect(call_context.idempotence_request_timestamp).to be_nil
74
+ }
75
+ end
76
+
77
+ it 'reports idempotence failure when another request has been sent prior' do
78
+ response_body = IO.read(resource_prefix + 'idempotence_rejected.json')
79
+ idempotence_key = SecureRandom.uuid
80
+ idempotence_timestamp = Time.now.to_f*1000 # Convert time to milliseconds
81
+ call_context = CallContext.new(idempotence_key)
82
+ request = create_payment_request
83
+
84
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/20000/payments')
85
+ .with(headers: {'X-GCS-Idempotence-Key' => idempotence_key})
86
+ .to_return(status: 402, body: response_body,
87
+ headers: base_headers.merge({'Content-Type' => 'application/json',
88
+ 'X-GCS-Idempotence-Request-Timestamp' => idempotence_timestamp}))
89
+
90
+ expect{response = CLIENT.merchant('20000').payments.create(request, call_context)}.
91
+ to raise_error(Ingenico::Connect::SDK::DeclinedPaymentException){ |err|
92
+ expect(err.status_code).to be(402)
93
+ expect(err.response_body).to be(response_body)
94
+ expect(call_context.idempotence_key).to eq(idempotence_key)
95
+ expect(call_context.idempotence_request_timestamp.to_s).to eq(idempotence_timestamp.to_s)
96
+ }
97
+ end
98
+
99
+ it 'reports idempotence failure when another request is still in progress' do
100
+ response_body = IO.read(resource_prefix + 'idempotence_duplicate_failure.json')
101
+ idempotence_key = SecureRandom.uuid
102
+ idempotence_timestamp = Time.now.to_f*1000 # Convert time to milliseconds
103
+ call_context = CallContext.new(idempotence_key)
104
+ request = create_payment_request
105
+
106
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/20000/payments')
107
+ .with(headers: {'X-GCS-Idempotence-Key' => idempotence_key})
108
+ .to_return(status: 409, body: response_body,
109
+ headers: base_headers.merge({'Content-Type' => 'application/json',
110
+ 'X-GCS-Idempotence-Request-Timestamp' => idempotence_timestamp}))
111
+
112
+ expect{response = CLIENT.merchant('20000').payments.create(request, call_context)}.
113
+ to raise_error(Ingenico::Connect::SDK::IdempotenceException){ |err|
114
+ expect(err.status_code).to be(409)
115
+ expect(err.response_body).to be(response_body)
116
+ expect(call_context.idempotence_key).to eq(idempotence_key)
117
+ expect(call_context.idempotence_request_timestamp.to_s).to eq(idempotence_timestamp.to_s)
118
+ }
119
+ end
120
+ end
121
+
122
+ def create_payment_request
123
+ amount_of_money = Definitions::AmountOfMoney.new
124
+ amount_of_money.amount = 2345
125
+ amount_of_money.currency_code = 'CAD'
126
+ customer = Payments::Customer.new
127
+ billing_address = Definitions::Address.new
128
+ billing_address.country_code = 'CA'
129
+ customer.billing_address = billing_address
130
+ order = Payments::Order.new
131
+ order.customer = customer
132
+ card = Definitions::Card.new
133
+ card.ccv = '123'
134
+ card.card_number = '4567350000427977'
135
+ card.expiry_date = '1220'
136
+ card_payment_method_specific_input = Payments::CardPaymentMethodSpecificInput.new
137
+ card_payment_method_specific_input.card = card
138
+ card_payment_method_specific_input.payment_product_id = 1
139
+ body = Payments::CreatePaymentRequest.new
140
+ body.card_payment_method_specific_input = card_payment_method_specific_input
141
+ body
142
+ end
@@ -0,0 +1,526 @@
1
+ require 'spec_helper'
2
+ require 'ingenico/connect/sdk/domain/definitions/amount_of_money'
3
+ require 'ingenico/connect/sdk/domain/definitions/card'
4
+ require 'ingenico/connect/sdk/domain/payment/card_payment_method_specific_input'
5
+ require 'ingenico/connect/sdk/domain/payment/create_payment_request'
6
+ require 'ingenico/connect/sdk/domain/payment/customer'
7
+ require 'ingenico/connect/sdk/domain/payment/order'
8
+ require 'ingenico/connect/sdk/merchant/services/convert_amount_params'
9
+ require 'httpclient'
10
+
11
+ # define module first so we can include them
12
+ # contains validation methods for messages logged in the tests
13
+ module ValidationDict
14
+ REQUEST_START = %r(Outgoing request \(requestId='([-a-zA-Z0-9]+)'\):)
15
+ RESPONSE_START = %r(Incoming response \(requestId='([-a-zA-Z0-9]+)', \d+.\d* ms\):)
16
+ GET_METHOD = %r(method: 'GET')
17
+ POST_METHOD = %r(method: 'POST')
18
+ DELETE_METHOD = %r(method: 'DELETE')
19
+ STATUS_200 = %r(status-code: '200')
20
+ STATUS_201 = %r(status-code: '201')
21
+ STATUS_204 = %r(status-code: '204')
22
+ STATUS_400 = %r(status-code: '400')
23
+ STATUS_402 = %r(status-code: '402')
24
+ STATUS_404 = %r(status-code: '404')
25
+ STATUS_500 = %r(status-code: '500')
26
+ DATEHEADER = %r(Date="[^"]+")
27
+ META_INFO_HEADER = %r(X-GCS-ServerMetaInfo="[^"]*")
28
+ AUTHORIZATION_HEADER = %r(Authorization="\*\*\*\*\*\*\*\*"[^']*')
29
+ DUMMY_HEADER = %r(Dummy="none")
30
+ DATA_JSON_HEADER = %r(Content-Type="application/json")
31
+ DATA_JSON = %r(content-type: 'application/json')
32
+
33
+ def validate_request_headers(message)
34
+ expect(message).to match(DATEHEADER)
35
+ expect(message).to match(META_INFO_HEADER)
36
+ expect(message).to match(AUTHORIZATION_HEADER)
37
+ end
38
+
39
+ def convertAmount_request(message)
40
+ expect(message).to match(REQUEST_START)
41
+ message =~ REQUEST_START
42
+ id = $1 # capture id from the regular expression above
43
+ expect(message).to match(GET_METHOD)
44
+ expect(message).to match(%r(uri: '/v1/1234/services/convert/amount\?source=EUR&amount=1000&target=USD'))
45
+ validate_request_headers(message)
46
+ return id
47
+ end
48
+
49
+ def convertAmount_response(message)
50
+ expect(message).to match(RESPONSE_START)
51
+ message =~ RESPONSE_START
52
+ id = $1 # capture id from the regular expression above
53
+ expect(message).to match(STATUS_200)
54
+ expect(message).to match(DATA_JSON_HEADER)
55
+ expect(message).to match(DATEHEADER)
56
+ # expect(message).to match(DUMMY_HEADER)
57
+ expect(message).to match(%r(content-type: 'application/json'))
58
+ # token match to validate that a body is in the message
59
+ expect(message).to match(%r("convertedAmount" : 4547504))
60
+ return id
61
+ end
62
+
63
+ def createPayment_failure_invalidCardNumber_request(message)
64
+ expect(message).to match(REQUEST_START)
65
+ message =~ REQUEST_START
66
+ id = $1 # capture id from the regular expression above
67
+ expect(message).to match(POST_METHOD)
68
+ expect(message).to match(%r(uri: '/v1/1234/payments'))
69
+ validate_request_headers(message)
70
+ expect(message).to match(DATA_JSON_HEADER)
71
+ expect(message).to match(DATA_JSON)
72
+ expect(message).to match(%r("cardPaymentMethodSpecificInput":)) # token match to validate that a body is in the message
73
+ return id
74
+ end
75
+
76
+ def createPayment_failure_invalidCardNumber_response(message)
77
+ expect(message).to match(RESPONSE_START)
78
+ message =~ RESPONSE_START
79
+ id = $1 # capture id from the regular expression above
80
+ expect(message).to match(STATUS_400)
81
+ expect(message).to match(DATA_JSON_HEADER)
82
+ # expect(message).to match(DUMMY_HEADER)
83
+ expect(message).to match(DATEHEADER)
84
+ expect(message).to match(DATA_JSON)
85
+ # token match to validate that a body is in the message
86
+ expect(message).to match(%r("VALUE \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* OF FIELD CREDITCARDNUMBER DID NOT PASS THE LUHNCHECK"))
87
+ return id
88
+ end
89
+
90
+ def createPayment_failure_rejected_request(message)
91
+ expect(message).to match(REQUEST_START)
92
+ message =~ REQUEST_START
93
+ id = $1 # capture id from the regular expression above
94
+ expect(message).to match(POST_METHOD)
95
+ expect(message).to match(%r(uri: '/v1/1234/payments'))
96
+ validate_request_headers(message)
97
+ expect(message).to match(DATA_JSON_HEADER)
98
+ expect(message).to match(DATA_JSON)
99
+ # token match to validate that a body is in the message
100
+ expect(message).to match(%r("cardPaymentMethodSpecificInput":))
101
+ return id
102
+ end
103
+
104
+ def createPayment_failure_rejected_response(message)
105
+ expect(message).to match(RESPONSE_START)
106
+ message =~ RESPONSE_START
107
+ id = $1 # capture id from the regular expression above
108
+ expect(message).to match(STATUS_402)
109
+ expect(message).to match(DATA_JSON_HEADER)
110
+ # expect(message).to match(DUMMY_HEADER)
111
+ expect(message).to match(DATEHEADER)
112
+ expect(message).to match(DATA_JSON)
113
+ # token match to validate that a body is in the message
114
+ expect(message).to match(%r("message": "Not authorised"))
115
+ return id
116
+ end
117
+
118
+ def createPayment_request(message)
119
+ expect(message).to match(REQUEST_START)
120
+ message =~ REQUEST_START
121
+ id = $1 # capture id from the regular expression above
122
+ expect(message).to match(POST_METHOD)
123
+ expect(message).to match(%r(uri: '/v1/1234/payments'))
124
+ validate_request_headers(message)
125
+ expect(message).to match(DATA_JSON_HEADER)
126
+ expect(message).to match(DATA_JSON)
127
+ # token match to validate that a body is in the message
128
+ expect(message).to match(%r("cardPaymentMethodSpecificInput":))
129
+ return id
130
+ end
131
+
132
+ def createPayment_response(message)
133
+ expect(message).to match(RESPONSE_START)
134
+ message =~ RESPONSE_START
135
+ id = $1 # capture id from the regular expression above
136
+ expect(message).to match(STATUS_201)
137
+ expect(message).to match(%r(Location="api-sandbox\.globalcollect\.com/v1/1234/payments/000000123410000595980000100001"))
138
+ expect(message).to match(DATA_JSON_HEADER)
139
+ # expect(message).to match(DUMMY_HEADER)
140
+ expect(message).to match(DATEHEADER)
141
+ expect(message).to match(DATA_JSON)
142
+ # token match to validate that a body is in the message
143
+ expect(message).to match(%r("cardNumber": "\*\*\*\*\*\*\*\*\*\*\*\*3456"))
144
+ return id
145
+ end
146
+
147
+ def deleteToken_request(message)
148
+ expect(message).to match(REQUEST_START)
149
+ message =~ REQUEST_START
150
+ id = $1 # capture id from the regular expression above
151
+ expect(message).to match(DELETE_METHOD)
152
+ expect(message).to match(%r(uri: '/v1/1234/tokens/5678'))
153
+ validate_request_headers(message)
154
+ return id
155
+ end
156
+
157
+ def deleteToken_response(message)
158
+ expect(message).to match(RESPONSE_START)
159
+ message =~ RESPONSE_START
160
+ id = $1 # capture id from the regular expression above
161
+ expect(message).to match(STATUS_204)
162
+ # expect(message).to match(DUMMY_HEADER)
163
+ expect(message).to match(DATEHEADER)
164
+ return id
165
+ end
166
+
167
+ def notFound_response(message)
168
+ expect(message).to match(RESPONSE_START)
169
+ message =~ RESPONSE_START
170
+ id = $1 # capture id from the regular expression above
171
+ expect(message).to match(STATUS_404)
172
+ # expect(message).to match(DUMMY_HEADER)
173
+ expect(message).to match(DATEHEADER)
174
+ expect(message).to match(%r(Content-Type="text/html"))
175
+ expect(message).to match(%r(content-type: 'text/html'))
176
+ expect(message).to match(%r(body: 'Not Found'))
177
+ return id
178
+ end
179
+
180
+ def testConnection_request(message)
181
+ expect(message).to match(REQUEST_START)
182
+ message =~ REQUEST_START
183
+ id = $1 # capture id from the regular expression above
184
+ expect(message).to match(GET_METHOD)
185
+ expect(message).to match(%r(uri: '/v1/1234/services/testconnection'))
186
+ validate_request_headers(message)
187
+ return id
188
+ end
189
+
190
+ def testConnection_response(message)
191
+ expect(message).to match(RESPONSE_START)
192
+ message =~ RESPONSE_START
193
+ id = $1 # capture id from the regular expression above
194
+ expect(message).to match(STATUS_200)
195
+ # expect(message).to match(DUMMY_HEADER)
196
+ expect(message).to match(DATEHEADER)
197
+ expect(message).to match(DATA_JSON_HEADER)
198
+ expect(message).to match(DATA_JSON)
199
+ # token match to validate that a body is in the message
200
+ expect(message).to match(%r("result": "OK"))
201
+ return id
202
+ end
203
+
204
+ def unknownServerError_response(message)
205
+ expect(message).to match(RESPONSE_START)
206
+ message =~ RESPONSE_START
207
+ id = $1 # capture id from the regular expression above
208
+ expect(message).to match(STATUS_500)
209
+ expect(message).to match(DATA_JSON_HEADER)
210
+ # expect(message).to match(DUMMY_HEADER)
211
+ expect(message).to match(DATEHEADER)
212
+ expect(message).to match(DATA_JSON)
213
+ # token match to validate that a body is in the message
214
+ expect(message).to match(%r("message": "UNKNOWN_SERVER_ERROR"))
215
+ return id
216
+ end
217
+ end
218
+
219
+
220
+ # -----test examples-----:
221
+
222
+ describe 'DefaultConnectionLogging' do
223
+
224
+ include ValidationDict
225
+
226
+ let(:logger){TestLogger.new}
227
+ base_headers = {'dummy' => 'none', 'Date' => 'Mon, 1 Jan 2000 00:00:00 GMT'}
228
+ resource_prefix = 'spec/fixtures/resources/defaultimpl/'
229
+
230
+ # tests testconnection
231
+ it 'should be able to log a simple request' do
232
+ response_body = IO.read(resource_prefix + 'testConnection.json')
233
+
234
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/testconnection')
235
+ .to_return(status: 200, body: response_body,
236
+ headers: base_headers.merge({'Content-Type' => 'application/json'}))
237
+
238
+ CLIENT.enable_logging(logger)
239
+ response = CLIENT.merchant('1234').services.testconnection
240
+
241
+ expect(response).to_not be_nil
242
+ expect(response.result).to eq('OK')
243
+
244
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'testConnection')
245
+ end
246
+
247
+ # tests convert_amount
248
+ it 'can log a GET request with parameters' do
249
+ response_body = IO.read(resource_prefix + 'convertAmount.json')
250
+
251
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/convert/amount?amount=1000&source=EUR&target=USD')
252
+ .to_return(status: 200, body: response_body,
253
+ headers: base_headers.merge({'Content-Type' => 'application/json'}))
254
+
255
+ query_params = Ingenico::Connect::SDK::Merchant::Services::ConvertAmountParams.new
256
+ query_params.amount = 1000
257
+ query_params.source = 'EUR'
258
+ query_params.target = 'USD'
259
+ CLIENT.enable_logging(logger)
260
+
261
+ response = CLIENT.merchant('1234').services.convert_amount(query_params)
262
+
263
+ expect(response).to_not be_nil
264
+ expect(response.converted_amount).to_not be_nil
265
+
266
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'convertAmount')
267
+ end
268
+
269
+ # tests delete token
270
+ it 'can log DELETE requests' do
271
+ stub_request(:delete, 'https://api-sandbox.globalcollect.com/v1/1234/tokens/5678')
272
+ .to_return(status: 204, headers: base_headers)
273
+
274
+ CLIENT.enable_logging(logger)
275
+ response = CLIENT.merchant('1234').tokens.delete('5678', nil)
276
+
277
+ expect(response).to_not be_nil
278
+
279
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'deleteToken')
280
+ end
281
+
282
+ # tests create payment
283
+ it 'can log POST responses' do
284
+ response_body = IO.read(resource_prefix + 'createPayment.json')
285
+ request = create_payment_request
286
+
287
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/1234/payments')
288
+ .to_return(status: 201, body: response_body,
289
+ headers: base_headers.merge({'Content-Type' => 'application/json',
290
+ 'Location' => 'api-sandbox.globalcollect.com/v1/1234/payments/000000123410000595980000100001'}))
291
+
292
+ CLIENT.enable_logging(logger)
293
+ response = CLIENT.merchant('1234').payments.create(request)
294
+
295
+ expect(response).to_not be_nil
296
+ expect(response.payment).to_not be_nil
297
+ expect(response.payment.id).to_not be_nil
298
+
299
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'createPayment')
300
+ end
301
+
302
+ # tests create payment with an invalid card number
303
+ it 'can log error responses' do
304
+ response_body = IO.read(resource_prefix + 'createPayment.failure.invalidCardNumber.json')
305
+ request = create_payment_request
306
+
307
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/1234/payments')
308
+ .to_return(status: 400, body: response_body,
309
+ headers: base_headers.merge({'Content-Type' => 'application/json'}))
310
+
311
+ CLIENT.enable_logging(logger)
312
+ expect{CLIENT.merchant('1234').payments.create(request)}.to raise_error(Ingenico::Connect::SDK::ValidationException)
313
+
314
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'createPayment_failure_invalidCardNumber')
315
+ end
316
+
317
+ # tests create payment with a rejected payment
318
+ it 'logs rejected payments' do
319
+ response_body = IO.read(resource_prefix + 'createPayment.failure.rejected.json')
320
+ request = create_payment_request
321
+
322
+ stub_request(:post, 'https://api-sandbox.globalcollect.com/v1/1234/payments')
323
+ .to_return(status: 402, body: response_body,
324
+ headers: base_headers.merge({'Content-Type' => 'application/json'}))
325
+
326
+ CLIENT.enable_logging(logger)
327
+ expect{CLIENT.merchant('1234').payments.create(request)}.to raise_error(Ingenico::Connect::SDK::DeclinedPaymentException)
328
+
329
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'createPayment_failure_rejected')
330
+ end
331
+
332
+ # tests the unknown server error response
333
+ it 'logs general HTTP errors' do
334
+ response_body = IO.read(resource_prefix + 'unknownServerError.json')
335
+
336
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/testconnection')
337
+ .to_return(status: 500, body: response_body,
338
+ headers: base_headers.merge({'Content-Type' => 'application/json'}))
339
+
340
+ CLIENT.enable_logging(logger)
341
+ expect{CLIENT.merchant('1234').services.testconnection}.to raise_error(Ingenico::Connect::SDK::GlobalCollectException)
342
+
343
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'testConnection', 'unknownServerError')
344
+ end
345
+
346
+ # tests a not found response
347
+ it 'logs non-json' do
348
+ response_body = IO.read(resource_prefix + 'notFound.html')
349
+
350
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/testconnection')
351
+ .to_return(status: 404, body: response_body,
352
+ headers: base_headers.merge({'Content-Type' => 'text/html'}))
353
+
354
+ CLIENT.enable_logging(logger)
355
+ expect{CLIENT.merchant('1234').services.testconnection}.to raise_error(Ingenico::Connect::SDK::NotFoundException)
356
+
357
+ validate_request_and_response(logger.entries[0], logger.entries[1], 'testConnection', 'notFound')
358
+ end
359
+
360
+ # tests a read timeout
361
+ it 'logs timeouts' do
362
+ response_body = IO.read(resource_prefix + 'notFound.html')
363
+
364
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/testconnection')
365
+ .to_raise(HTTPClient::ReceiveTimeoutError)
366
+
367
+ CLIENT.enable_logging(logger)
368
+ expect{CLIENT.merchant('1234').services.testconnection}.to raise_error(Ingenico::Connect::SDK::CommunicationException)
369
+
370
+ request = logger.entries[0]
371
+ expect(request[0]).to_not be_nil
372
+ expect(request[1]).to be_nil, "Error logged that should not have been thrown:/n#{request[1]}"
373
+
374
+ response = logger.entries[1]
375
+ expect(response[0]).to_not be_nil
376
+ expect(response[1]).to_not be_nil, 'A timeout error should have been logged'
377
+ expect(response[1]).to be_a(HTTPClient::TimeoutError)
378
+
379
+ validate_request_and_error(logger.entries[0], logger.entries[1], 'testConnection')
380
+ end
381
+
382
+ it 'can log requests individually' do
383
+ response_body = IO.read(resource_prefix + 'testConnection.json')
384
+
385
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/testconnection')
386
+ .to_return{ |request| CLIENT.disable_logging
387
+ {body: response_body, status: 200, headers: base_headers.merge({'Content-type' => 'application/json'})}}
388
+
389
+ CLIENT.enable_logging(logger)
390
+ response = CLIENT.merchant('1234').services.testconnection
391
+
392
+ expect(response.result).to eq('OK')
393
+
394
+ request = logger.entries[0]
395
+ expect(request[0]).to_not be_nil
396
+ expect(request[1]).to be_nil, "Error logged that should not have been thrown:/n#{request[1]}"
397
+
398
+ validate_request(logger.entries[0], 'testConnection')
399
+ end
400
+
401
+ it 'can log responses individually' do
402
+ response_body = IO.read(resource_prefix + 'testConnection.json')
403
+
404
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/testconnection')
405
+ .to_return{ |request| CLIENT.enable_logging(logger)
406
+ {body: response_body, status: 200, headers: base_headers.merge({'Content-type' => 'application/json'})}}
407
+
408
+ response = CLIENT.merchant('1234').services.testconnection
409
+
410
+ expect(response.result).to eq('OK')
411
+
412
+ response = logger.entries[0]
413
+ expect(response[0]).to_not be_nil
414
+ expect(response[1]).to be_nil, "Error logged that should not have been thrown:/n#{response[1]}"
415
+
416
+ validate_response(logger.entries[0], 'testConnection')
417
+ end
418
+
419
+ it 'can log errors individually' do
420
+ response_body = IO.read(resource_prefix + 'notFound.html')
421
+
422
+ stub_request(:get, 'https://api-sandbox.globalcollect.com/v1/1234/services/testconnection')
423
+ .to_return{ |request| CLIENT.enable_logging(logger)
424
+ raise HTTPClient::ReceiveTimeoutError.new}
425
+
426
+ expect{CLIENT.merchant('1234').services.testconnection}.to raise_error(Ingenico::Connect::SDK::CommunicationException)
427
+
428
+ response = logger.entries[0]
429
+ expect(response[0]).to_not be_nil
430
+ expect(response[1]).to_not be_nil, 'A timeout error should have been logged'
431
+ expect(response[1]).to be_a(HTTPClient::TimeoutError)
432
+
433
+ validate_error(logger.entries[0])
434
+ end
435
+ end
436
+
437
+ # Asserts that the request and response contain messages and no errors.
438
+ # Asserts that the request and response messages match the format
439
+ # in request_resource_prefix.request and response_resource_prefix.response respectively.
440
+ # If response_resource_prefix is not given it is assumed to be the same as the request_resource_prefix.
441
+ def validate_request_and_response(request, response,
442
+ request_resource_prefix, response_resource_prefix=nil)
443
+ # for request and response, check that the message exists in the logs and there is no error logged
444
+ expect(request[0]).to_not be_nil
445
+ expect(request[1]).to be_nil, "Error logged that should not have been thrown:/n#{request[1]}"
446
+
447
+ expect(response[0]).to_not be_nil
448
+ expect(response[1]).to be_nil, "Error logged that should not have been thrown:/n#{response[1]}"
449
+
450
+ response_resource_prefix ||= request_resource_prefix
451
+ request_id = validate_request(request, request_resource_prefix)
452
+ fail if request_id.nil? # Request_id was not captured
453
+ validate_response(response, response_resource_prefix, request_id)
454
+ end
455
+
456
+ # Asserts that the request message matches the request format in _resource_prefix.request_
457
+ # and that the request and error id are the same.
458
+ # Resource prefix is the location of the request resource, which will be appended with _.request_ to get the file location.
459
+ def validate_request_and_error(request, response_error, resource_prefix)
460
+ request_id = validate_request(request, resource_prefix)
461
+ validate_error(response_error, request_id)
462
+ end
463
+
464
+ # Asserts that the request message matches the request format in _resource_prefix.request_.
465
+ # Resource prefix is the location of the request resource, which will be appended with _.request_ to get the file location.
466
+ # Returns the request_id found in the request so it can be matched with a possible response or error
467
+ def validate_request(request, request_resource_prefix)
468
+ method = (request_resource_prefix + '_request').to_sym
469
+ return send(method, request[0])
470
+ end
471
+
472
+ # Asserts that the response message matches the response format in _resource_prefix.response_.
473
+ # Resource prefix is the location of the response resource, which will be appended with _.response_ to get the file location.
474
+ # If the parameter _request_id_ is given, it will be matched with the _request_id_ found in the response_message
475
+ def validate_response(response, response_resource_prefix, request_id=nil)
476
+ method = (response_resource_prefix + '_response').to_sym
477
+ response_id = send(method, response[0])
478
+ expect(response_id).to eq(request_id) unless request_id.nil?
479
+ end
480
+
481
+ # Validates that the error message contains a requestId
482
+ # If a request_id is provided, it is matched against the error_id found in the error
483
+ def validate_error(error, request_id=nil)
484
+ error_pattern_string = %r(Error occurred for outgoing request \(requestId='(?<error_id>[-a-zA-Z0-9]+)', \d+.\d* ms\))
485
+ expect(error[0]).to match(error_pattern_string)
486
+ error[0] =~ error_pattern_string # match to capture id
487
+ error_id = $1
488
+ expect(error_id).to eq(request_id) unless request_id.nil?
489
+ end
490
+
491
+
492
+ class TestLogger < Ingenico::Connect::SDK::Logging::CommunicatorLogger
493
+
494
+ attr_accessor :entries
495
+
496
+ def initialize
497
+ @entries = []
498
+ end
499
+
500
+ def log(message, thrown = nil)
501
+ @entries << [message, thrown]
502
+ end
503
+ end
504
+
505
+
506
+ def create_payment_request
507
+ amount_of_money = Ingenico::Connect::SDK::Domain::Definitions::AmountOfMoney.new
508
+ amount_of_money.amount = 2345
509
+ amount_of_money.currency_code = 'CAD'
510
+ customer = Ingenico::Connect::SDK::Domain::Payment::Customer.new
511
+ billing_address = Ingenico::Connect::SDK::Domain::Definitions::Address.new
512
+ billing_address.country_code = 'CA'
513
+ customer.billing_address = billing_address
514
+ order = Ingenico::Connect::SDK::Domain::Payment::Order.new
515
+ order.customer = customer
516
+ card = Ingenico::Connect::SDK::Domain::Definitions::Card.new
517
+ card.cvv = '123'
518
+ card.card_number = '4567350000427977'
519
+ card.expiry_date = '1220'
520
+ card_payment_method_specific_input = Ingenico::Connect::SDK::Domain::Payment::CardPaymentMethodSpecificInput.new
521
+ card_payment_method_specific_input.card = card
522
+ card_payment_method_specific_input.payment_product_id = 1
523
+ body = Ingenico::Connect::SDK::Domain::Payment::CreatePaymentRequest.new
524
+ body.card_payment_method_specific_input = card_payment_method_specific_input
525
+ body
526
+ end