onlinepayments-sdk-python3 7.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (475) hide show
  1. onlinepayments/__init__.py +0 -0
  2. onlinepayments/sdk/__init__.py +4 -0
  3. onlinepayments/sdk/api_exception.py +60 -0
  4. onlinepayments/sdk/api_resource.py +57 -0
  5. onlinepayments/sdk/authentication/__init__.py +0 -0
  6. onlinepayments/sdk/authentication/authenticator.py +24 -0
  7. onlinepayments/sdk/authentication/authorization_type.py +10 -0
  8. onlinepayments/sdk/authentication/v1hmac_authenticator.py +122 -0
  9. onlinepayments/sdk/authorization_exception.py +19 -0
  10. onlinepayments/sdk/call_context.py +72 -0
  11. onlinepayments/sdk/client.py +107 -0
  12. onlinepayments/sdk/communication/__init__.py +0 -0
  13. onlinepayments/sdk/communication/communication_exception.py +8 -0
  14. onlinepayments/sdk/communication/connection.py +84 -0
  15. onlinepayments/sdk/communication/default_connection.py +313 -0
  16. onlinepayments/sdk/communication/i_metadata_provider.py +19 -0
  17. onlinepayments/sdk/communication/metadata_provider.py +132 -0
  18. onlinepayments/sdk/communication/multipart_form_data_object.py +51 -0
  19. onlinepayments/sdk/communication/multipart_form_data_request.py +16 -0
  20. onlinepayments/sdk/communication/not_found_exception.py +10 -0
  21. onlinepayments/sdk/communication/param_request.py +17 -0
  22. onlinepayments/sdk/communication/pooled_connection.py +29 -0
  23. onlinepayments/sdk/communication/request_header.py +60 -0
  24. onlinepayments/sdk/communication/request_param.py +30 -0
  25. onlinepayments/sdk/communication/response_exception.py +58 -0
  26. onlinepayments/sdk/communication/response_header.py +50 -0
  27. onlinepayments/sdk/communicator.py +465 -0
  28. onlinepayments/sdk/communicator_configuration.py +264 -0
  29. onlinepayments/sdk/declined_payment_exception.py +46 -0
  30. onlinepayments/sdk/declined_payout_exception.py +46 -0
  31. onlinepayments/sdk/declined_refund_exception.py +46 -0
  32. onlinepayments/sdk/declined_transaction_exception.py +22 -0
  33. onlinepayments/sdk/domain/__init__.py +4 -0
  34. onlinepayments/sdk/domain/acceptance.py +56 -0
  35. onlinepayments/sdk/domain/account_on_file.py +102 -0
  36. onlinepayments/sdk/domain/account_on_file_attribute.py +97 -0
  37. onlinepayments/sdk/domain/account_on_file_display_hints.py +64 -0
  38. onlinepayments/sdk/domain/acquirer_information.py +59 -0
  39. onlinepayments/sdk/domain/acquirer_selection_information.py +73 -0
  40. onlinepayments/sdk/domain/additional_order_input.py +107 -0
  41. onlinepayments/sdk/domain/address.py +145 -0
  42. onlinepayments/sdk/domain/address_personal.py +185 -0
  43. onlinepayments/sdk/domain/airline_data.py +519 -0
  44. onlinepayments/sdk/domain/airline_flight_leg.py +386 -0
  45. onlinepayments/sdk/domain/airline_passenger.py +129 -0
  46. onlinepayments/sdk/domain/amount_breakdown.py +63 -0
  47. onlinepayments/sdk/domain/amount_of_money.py +59 -0
  48. onlinepayments/sdk/domain/api_error.py +177 -0
  49. onlinepayments/sdk/domain/apple_pay_line_item.py +145 -0
  50. onlinepayments/sdk/domain/apple_pay_recurring_payment_request.py +116 -0
  51. onlinepayments/sdk/domain/bank_account_iban.py +37 -0
  52. onlinepayments/sdk/domain/batch_metadata.py +73 -0
  53. onlinepayments/sdk/domain/browser_data.py +130 -0
  54. onlinepayments/sdk/domain/calculate_surcharge_request.py +63 -0
  55. onlinepayments/sdk/domain/calculate_surcharge_response.py +44 -0
  56. onlinepayments/sdk/domain/cancel_payment_batch_request.py +57 -0
  57. onlinepayments/sdk/domain/cancel_payment_request.py +130 -0
  58. onlinepayments/sdk/domain/cancel_payment_response.py +41 -0
  59. onlinepayments/sdk/domain/capture.py +97 -0
  60. onlinepayments/sdk/domain/capture_output.py +272 -0
  61. onlinepayments/sdk/domain/capture_payment_batch_request.py +57 -0
  62. onlinepayments/sdk/domain/capture_payment_request.py +148 -0
  63. onlinepayments/sdk/domain/capture_response.py +99 -0
  64. onlinepayments/sdk/domain/capture_status_output.py +37 -0
  65. onlinepayments/sdk/domain/captures_response.py +46 -0
  66. onlinepayments/sdk/domain/card.py +91 -0
  67. onlinepayments/sdk/domain/card_bin_details.py +384 -0
  68. onlinepayments/sdk/domain/card_data_without_cvv.py +73 -0
  69. onlinepayments/sdk/domain/card_essentials.py +438 -0
  70. onlinepayments/sdk/domain/card_fraud_results.py +112 -0
  71. onlinepayments/sdk/domain/card_info.py +55 -0
  72. onlinepayments/sdk/domain/card_payment_method_specific_input.py +608 -0
  73. onlinepayments/sdk/domain/card_payment_method_specific_input_base.py +441 -0
  74. onlinepayments/sdk/domain/card_payment_method_specific_input_for_hosted_checkout.py +105 -0
  75. onlinepayments/sdk/domain/card_payment_method_specific_output.py +467 -0
  76. onlinepayments/sdk/domain/card_payout_method_specific_input.py +99 -0
  77. onlinepayments/sdk/domain/card_recurrence_details.py +40 -0
  78. onlinepayments/sdk/domain/card_source.py +95 -0
  79. onlinepayments/sdk/domain/card_without_cvv.py +73 -0
  80. onlinepayments/sdk/domain/click_to_pay.py +37 -0
  81. onlinepayments/sdk/domain/company_information.py +37 -0
  82. onlinepayments/sdk/domain/complete_payment_card_payment_method_specific_input.py +39 -0
  83. onlinepayments/sdk/domain/complete_payment_request.py +61 -0
  84. onlinepayments/sdk/domain/complete_payment_response.py +85 -0
  85. onlinepayments/sdk/domain/contact_details.py +109 -0
  86. onlinepayments/sdk/domain/create_certificate_response.py +55 -0
  87. onlinepayments/sdk/domain/create_hosted_checkout_request.py +195 -0
  88. onlinepayments/sdk/domain/create_hosted_checkout_response.py +132 -0
  89. onlinepayments/sdk/domain/create_hosted_fields_session_request.py +37 -0
  90. onlinepayments/sdk/domain/create_hosted_fields_session_response.py +102 -0
  91. onlinepayments/sdk/domain/create_hosted_tokenization_request.py +133 -0
  92. onlinepayments/sdk/domain/create_hosted_tokenization_response.py +127 -0
  93. onlinepayments/sdk/domain/create_mandate_request.py +187 -0
  94. onlinepayments/sdk/domain/create_mandate_response.py +63 -0
  95. onlinepayments/sdk/domain/create_mandate_with_return_url.py +187 -0
  96. onlinepayments/sdk/domain/create_payment_link_request.py +344 -0
  97. onlinepayments/sdk/domain/create_payment_request.py +249 -0
  98. onlinepayments/sdk/domain/create_payment_response.py +85 -0
  99. onlinepayments/sdk/domain/create_payout_request.py +176 -0
  100. onlinepayments/sdk/domain/create_token_request.py +77 -0
  101. onlinepayments/sdk/domain/created_payment_output.py +57 -0
  102. onlinepayments/sdk/domain/created_token_response.py +142 -0
  103. onlinepayments/sdk/domain/credit_card_specific_input_hosted_tokenization.py +66 -0
  104. onlinepayments/sdk/domain/credit_card_validation_rules.py +55 -0
  105. onlinepayments/sdk/domain/credit_card_validation_rules_hosted_tokenization.py +55 -0
  106. onlinepayments/sdk/domain/crm_token.py +55 -0
  107. onlinepayments/sdk/domain/csr_request.py +37 -0
  108. onlinepayments/sdk/domain/currency_conversion.py +59 -0
  109. onlinepayments/sdk/domain/currency_conversion_input.py +55 -0
  110. onlinepayments/sdk/domain/currency_conversion_request.py +59 -0
  111. onlinepayments/sdk/domain/currency_conversion_response.py +81 -0
  112. onlinepayments/sdk/domain/currency_conversion_result.py +61 -0
  113. onlinepayments/sdk/domain/currency_conversion_specific_input.py +40 -0
  114. onlinepayments/sdk/domain/customer.py +234 -0
  115. onlinepayments/sdk/domain/customer_account.py +204 -0
  116. onlinepayments/sdk/domain/customer_account_authentication.py +81 -0
  117. onlinepayments/sdk/domain/customer_bank_account.py +73 -0
  118. onlinepayments/sdk/domain/customer_device.py +155 -0
  119. onlinepayments/sdk/domain/customer_device_output.py +37 -0
  120. onlinepayments/sdk/domain/customer_output.py +41 -0
  121. onlinepayments/sdk/domain/customer_payment_activity.py +73 -0
  122. onlinepayments/sdk/domain/customer_token.py +83 -0
  123. onlinepayments/sdk/domain/data_object.py +47 -0
  124. onlinepayments/sdk/domain/dcc_card_source.py +93 -0
  125. onlinepayments/sdk/domain/dcc_proposal.py +118 -0
  126. onlinepayments/sdk/domain/decrypted_payment_data.py +120 -0
  127. onlinepayments/sdk/domain/detokenization_response.py +46 -0
  128. onlinepayments/sdk/domain/detokenized_token_response.py +145 -0
  129. onlinepayments/sdk/domain/directory_entry.py +73 -0
  130. onlinepayments/sdk/domain/discount.py +41 -0
  131. onlinepayments/sdk/domain/empty_validator.py +16 -0
  132. onlinepayments/sdk/domain/error_response.py +64 -0
  133. onlinepayments/sdk/domain/external_cardholder_authentication_data.py +216 -0
  134. onlinepayments/sdk/domain/external_token_linked.py +75 -0
  135. onlinepayments/sdk/domain/feedbacks.py +64 -0
  136. onlinepayments/sdk/domain/fixed_list_validator.py +42 -0
  137. onlinepayments/sdk/domain/fraud_fields.py +84 -0
  138. onlinepayments/sdk/domain/fraud_results.py +43 -0
  139. onlinepayments/sdk/domain/g_pay_three_d_secure.py +159 -0
  140. onlinepayments/sdk/domain/get_batch_status_response.py +91 -0
  141. onlinepayments/sdk/domain/get_hosted_checkout_response.py +63 -0
  142. onlinepayments/sdk/domain/get_hosted_tokenization_response.py +61 -0
  143. onlinepayments/sdk/domain/get_iin_details_request.py +57 -0
  144. onlinepayments/sdk/domain/get_iin_details_response.py +450 -0
  145. onlinepayments/sdk/domain/get_mandate_response.py +41 -0
  146. onlinepayments/sdk/domain/get_payment_product_groups_response.py +44 -0
  147. onlinepayments/sdk/domain/get_payment_products_response.py +44 -0
  148. onlinepayments/sdk/domain/get_privacy_policy_response.py +37 -0
  149. onlinepayments/sdk/domain/gift_card_purchase.py +59 -0
  150. onlinepayments/sdk/domain/hosted_checkout_specific_input.py +250 -0
  151. onlinepayments/sdk/domain/hosted_checkout_specific_output.py +55 -0
  152. onlinepayments/sdk/domain/iin_detail.py +423 -0
  153. onlinepayments/sdk/domain/import_cof_series_request.py +113 -0
  154. onlinepayments/sdk/domain/import_cof_series_response.py +37 -0
  155. onlinepayments/sdk/domain/label_template_element.py +55 -0
  156. onlinepayments/sdk/domain/length_validator.py +51 -0
  157. onlinepayments/sdk/domain/line_item.py +107 -0
  158. onlinepayments/sdk/domain/line_item_detail.py +99 -0
  159. onlinepayments/sdk/domain/line_item_invoice_data.py +37 -0
  160. onlinepayments/sdk/domain/loan_recipient.py +109 -0
  161. onlinepayments/sdk/domain/lodging_data.py +37 -0
  162. onlinepayments/sdk/domain/mandate_address.py +109 -0
  163. onlinepayments/sdk/domain/mandate_address_response.py +109 -0
  164. onlinepayments/sdk/domain/mandate_contact_details.py +37 -0
  165. onlinepayments/sdk/domain/mandate_customer.py +125 -0
  166. onlinepayments/sdk/domain/mandate_customer_response.py +125 -0
  167. onlinepayments/sdk/domain/mandate_merchant_action.py +61 -0
  168. onlinepayments/sdk/domain/mandate_personal_information.py +59 -0
  169. onlinepayments/sdk/domain/mandate_personal_information_response.py +59 -0
  170. onlinepayments/sdk/domain/mandate_personal_name.py +55 -0
  171. onlinepayments/sdk/domain/mandate_personal_name_response.py +55 -0
  172. onlinepayments/sdk/domain/mandate_redirect_data.py +55 -0
  173. onlinepayments/sdk/domain/mandate_response.py +150 -0
  174. onlinepayments/sdk/domain/market_place.py +55 -0
  175. onlinepayments/sdk/domain/merchant_action.py +132 -0
  176. onlinepayments/sdk/domain/mobile_payment_data.py +55 -0
  177. onlinepayments/sdk/domain/mobile_payment_method_hosted_checkout_specific_input.py +105 -0
  178. onlinepayments/sdk/domain/mobile_payment_method_specific_input.py +202 -0
  179. onlinepayments/sdk/domain/mobile_payment_method_specific_output.py +139 -0
  180. onlinepayments/sdk/domain/mobile_payment_product302_specific_input.py +103 -0
  181. onlinepayments/sdk/domain/mobile_payment_product320_specific_input.py +103 -0
  182. onlinepayments/sdk/domain/mobile_three_d_secure_challenge_parameters.py +91 -0
  183. onlinepayments/sdk/domain/multiple_payment_information.py +57 -0
  184. onlinepayments/sdk/domain/network_token_data.py +127 -0
  185. onlinepayments/sdk/domain/network_token_essentials.py +134 -0
  186. onlinepayments/sdk/domain/network_token_linked.py +80 -0
  187. onlinepayments/sdk/domain/omnichannel_payment_specific_input.py +37 -0
  188. onlinepayments/sdk/domain/omnichannel_payout_specific_input.py +55 -0
  189. onlinepayments/sdk/domain/omnichannel_refund_specific_input.py +37 -0
  190. onlinepayments/sdk/domain/omnichannel_subsequent_specific_input.py +37 -0
  191. onlinepayments/sdk/domain/operation_output.py +161 -0
  192. onlinepayments/sdk/domain/operation_payment_references.py +55 -0
  193. onlinepayments/sdk/domain/order.py +213 -0
  194. onlinepayments/sdk/domain/order_line_details.py +189 -0
  195. onlinepayments/sdk/domain/order_references.py +120 -0
  196. onlinepayments/sdk/domain/order_status_output.py +119 -0
  197. onlinepayments/sdk/domain/order_type_information.py +64 -0
  198. onlinepayments/sdk/domain/other_details.py +55 -0
  199. onlinepayments/sdk/domain/payment_account_on_file.py +57 -0
  200. onlinepayments/sdk/domain/payment_context.py +77 -0
  201. onlinepayments/sdk/domain/payment_creation_output.py +94 -0
  202. onlinepayments/sdk/domain/payment_details_response.py +148 -0
  203. onlinepayments/sdk/domain/payment_error_response.py +84 -0
  204. onlinepayments/sdk/domain/payment_link_event.py +73 -0
  205. onlinepayments/sdk/domain/payment_link_order_input.py +84 -0
  206. onlinepayments/sdk/domain/payment_link_order_output.py +81 -0
  207. onlinepayments/sdk/domain/payment_link_response.py +216 -0
  208. onlinepayments/sdk/domain/payment_link_specific_input.py +74 -0
  209. onlinepayments/sdk/domain/payment_links_response.py +44 -0
  210. onlinepayments/sdk/domain/payment_output.py +335 -0
  211. onlinepayments/sdk/domain/payment_product.py +296 -0
  212. onlinepayments/sdk/domain/payment_product130_specific_input.py +41 -0
  213. onlinepayments/sdk/domain/payment_product130_specific_three_d_secure.py +91 -0
  214. onlinepayments/sdk/domain/payment_product3012.py +55 -0
  215. onlinepayments/sdk/domain/payment_product3012_specific_input.py +100 -0
  216. onlinepayments/sdk/domain/payment_product3013_specific_input.py +73 -0
  217. onlinepayments/sdk/domain/payment_product302_specific_data.py +44 -0
  218. onlinepayments/sdk/domain/payment_product3203_specific_output.py +62 -0
  219. onlinepayments/sdk/domain/payment_product3204_specific_output.py +37 -0
  220. onlinepayments/sdk/domain/payment_product3208_specific_input.py +37 -0
  221. onlinepayments/sdk/domain/payment_product3208_specific_output.py +37 -0
  222. onlinepayments/sdk/domain/payment_product3209_specific_input.py +37 -0
  223. onlinepayments/sdk/domain/payment_product3209_specific_output.py +37 -0
  224. onlinepayments/sdk/domain/payment_product320_specific_data.py +62 -0
  225. onlinepayments/sdk/domain/payment_product350.py +55 -0
  226. onlinepayments/sdk/domain/payment_product5001.py +58 -0
  227. onlinepayments/sdk/domain/payment_product5001_specific_output.py +112 -0
  228. onlinepayments/sdk/domain/payment_product5100_specific_input.py +37 -0
  229. onlinepayments/sdk/domain/payment_product5402_specific_output.py +37 -0
  230. onlinepayments/sdk/domain/payment_product5404.py +55 -0
  231. onlinepayments/sdk/domain/payment_product5407.py +55 -0
  232. onlinepayments/sdk/domain/payment_product5500_specific_output.py +91 -0
  233. onlinepayments/sdk/domain/payment_product771_specific_output.py +37 -0
  234. onlinepayments/sdk/domain/payment_product840.py +37 -0
  235. onlinepayments/sdk/domain/payment_product840_customer_account.py +170 -0
  236. onlinepayments/sdk/domain/payment_product840_specific_output.py +167 -0
  237. onlinepayments/sdk/domain/payment_product_display_hints.py +73 -0
  238. onlinepayments/sdk/domain/payment_product_field.py +95 -0
  239. onlinepayments/sdk/domain/payment_product_field_data_restrictions.py +60 -0
  240. onlinepayments/sdk/domain/payment_product_field_display_element.py +97 -0
  241. onlinepayments/sdk/domain/payment_product_field_display_hints.py +218 -0
  242. onlinepayments/sdk/domain/payment_product_field_form_element.py +72 -0
  243. onlinepayments/sdk/domain/payment_product_field_tooltip.py +57 -0
  244. onlinepayments/sdk/domain/payment_product_field_validators.py +195 -0
  245. onlinepayments/sdk/domain/payment_product_filter.py +67 -0
  246. onlinepayments/sdk/domain/payment_product_filter_hosted_tokenization.py +42 -0
  247. onlinepayments/sdk/domain/payment_product_filters_hosted_checkout.py +62 -0
  248. onlinepayments/sdk/domain/payment_product_filters_hosted_tokenization.py +62 -0
  249. onlinepayments/sdk/domain/payment_product_group.py +103 -0
  250. onlinepayments/sdk/domain/payment_product_networks_response.py +42 -0
  251. onlinepayments/sdk/domain/payment_references.py +73 -0
  252. onlinepayments/sdk/domain/payment_response.py +143 -0
  253. onlinepayments/sdk/domain/payment_status_output.py +152 -0
  254. onlinepayments/sdk/domain/payout_error_response.py +80 -0
  255. onlinepayments/sdk/domain/payout_output.py +63 -0
  256. onlinepayments/sdk/domain/payout_response.py +93 -0
  257. onlinepayments/sdk/domain/payout_result.py +93 -0
  258. onlinepayments/sdk/domain/payout_status_output.py +76 -0
  259. onlinepayments/sdk/domain/pending_authentication.py +37 -0
  260. onlinepayments/sdk/domain/personal_information.py +77 -0
  261. onlinepayments/sdk/domain/personal_information_token.py +39 -0
  262. onlinepayments/sdk/domain/personal_name.py +73 -0
  263. onlinepayments/sdk/domain/personal_name_token.py +51 -0
  264. onlinepayments/sdk/domain/product302_recurring.py +37 -0
  265. onlinepayments/sdk/domain/product320_recurring.py +37 -0
  266. onlinepayments/sdk/domain/product_directory.py +46 -0
  267. onlinepayments/sdk/domain/protection_eligibility.py +59 -0
  268. onlinepayments/sdk/domain/range_validator.py +51 -0
  269. onlinepayments/sdk/domain/rate_details.py +109 -0
  270. onlinepayments/sdk/domain/reattempt_instructions.py +82 -0
  271. onlinepayments/sdk/domain/reattempt_instructions_conditions.py +55 -0
  272. onlinepayments/sdk/domain/redirect_data.py +55 -0
  273. onlinepayments/sdk/domain/redirect_payment_method_specific_input.py +575 -0
  274. onlinepayments/sdk/domain/redirect_payment_method_specific_output.py +267 -0
  275. onlinepayments/sdk/domain/redirect_payment_product11_specific_input.py +38 -0
  276. onlinepayments/sdk/domain/redirect_payment_product3103_specific_input.py +40 -0
  277. onlinepayments/sdk/domain/redirect_payment_product3112_specific_input.py +40 -0
  278. onlinepayments/sdk/domain/redirect_payment_product3116_specific_input.py +40 -0
  279. onlinepayments/sdk/domain/redirect_payment_product3203_specific_input.py +40 -0
  280. onlinepayments/sdk/domain/redirect_payment_product3204_specific_input.py +55 -0
  281. onlinepayments/sdk/domain/redirect_payment_product3302_specific_input.py +73 -0
  282. onlinepayments/sdk/domain/redirect_payment_product3306_specific_input.py +37 -0
  283. onlinepayments/sdk/domain/redirect_payment_product3307_specific_input.py +16 -0
  284. onlinepayments/sdk/domain/redirect_payment_product5001_specific_input.py +62 -0
  285. onlinepayments/sdk/domain/redirect_payment_product5300_specific_input.py +163 -0
  286. onlinepayments/sdk/domain/redirect_payment_product5402_specific_input.py +40 -0
  287. onlinepayments/sdk/domain/redirect_payment_product5403_specific_input.py +40 -0
  288. onlinepayments/sdk/domain/redirect_payment_product5406_specific_input.py +41 -0
  289. onlinepayments/sdk/domain/redirect_payment_product5408_specific_input.py +60 -0
  290. onlinepayments/sdk/domain/redirect_payment_product5410_specific_input.py +38 -0
  291. onlinepayments/sdk/domain/redirect_payment_product5412_specific_input.py +55 -0
  292. onlinepayments/sdk/domain/redirect_payment_product5601_specific_input.py +40 -0
  293. onlinepayments/sdk/domain/redirect_payment_product809_specific_input.py +40 -0
  294. onlinepayments/sdk/domain/redirect_payment_product840_specific_input.py +100 -0
  295. onlinepayments/sdk/domain/redirection_data.py +37 -0
  296. onlinepayments/sdk/domain/refund_card_method_specific_output.py +71 -0
  297. onlinepayments/sdk/domain/refund_e_wallet_method_specific_output.py +71 -0
  298. onlinepayments/sdk/domain/refund_error_response.py +82 -0
  299. onlinepayments/sdk/domain/refund_mobile_method_specific_output.py +69 -0
  300. onlinepayments/sdk/domain/refund_output.py +217 -0
  301. onlinepayments/sdk/domain/refund_payment_batch_request.py +57 -0
  302. onlinepayments/sdk/domain/refund_payment_product840_customer_account.py +69 -0
  303. onlinepayments/sdk/domain/refund_payment_product840_specific_output.py +39 -0
  304. onlinepayments/sdk/domain/refund_redirect_method_specific_output.py +51 -0
  305. onlinepayments/sdk/domain/refund_redirect_payment_method_specific_input.py +41 -0
  306. onlinepayments/sdk/domain/refund_redirect_payment_product900_specific_input.py +37 -0
  307. onlinepayments/sdk/domain/refund_request.py +210 -0
  308. onlinepayments/sdk/domain/refund_response.py +97 -0
  309. onlinepayments/sdk/domain/refunds_response.py +46 -0
  310. onlinepayments/sdk/domain/regular_expression_validator.py +35 -0
  311. onlinepayments/sdk/domain/revoke_mandate_request.py +48 -0
  312. onlinepayments/sdk/domain/send_test_request.py +37 -0
  313. onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_input.py +59 -0
  314. onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_input_base.py +59 -0
  315. onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_output.py +81 -0
  316. onlinepayments/sdk/domain/sepa_direct_debit_payment_product771_specific_input.py +59 -0
  317. onlinepayments/sdk/domain/sepa_direct_debit_payment_product771_specific_input_base.py +59 -0
  318. onlinepayments/sdk/domain/session_data.py +116 -0
  319. onlinepayments/sdk/domain/session_details.py +55 -0
  320. onlinepayments/sdk/domain/session_request.py +44 -0
  321. onlinepayments/sdk/domain/session_response.py +114 -0
  322. onlinepayments/sdk/domain/shipping.py +214 -0
  323. onlinepayments/sdk/domain/shipping_detail.py +63 -0
  324. onlinepayments/sdk/domain/shipping_method.py +91 -0
  325. onlinepayments/sdk/domain/shopping_cart.py +155 -0
  326. onlinepayments/sdk/domain/shopping_cart_extension.py +77 -0
  327. onlinepayments/sdk/domain/shopping_cart_output.py +46 -0
  328. onlinepayments/sdk/domain/show_form_data.py +173 -0
  329. onlinepayments/sdk/domain/show_instructions_data.py +37 -0
  330. onlinepayments/sdk/domain/split_payment_product_filter.py +42 -0
  331. onlinepayments/sdk/domain/split_payment_product_filters_hosted_checkout.py +62 -0
  332. onlinepayments/sdk/domain/submit_batch_request_body.py +230 -0
  333. onlinepayments/sdk/domain/submit_batch_response.py +55 -0
  334. onlinepayments/sdk/domain/subsequent_card_payment_method_specific_input.py +175 -0
  335. onlinepayments/sdk/domain/subsequent_payment_batch_request.py +57 -0
  336. onlinepayments/sdk/domain/subsequent_payment_product5001_specific_input.py +41 -0
  337. onlinepayments/sdk/domain/subsequent_payment_request.py +107 -0
  338. onlinepayments/sdk/domain/subsequent_payment_response.py +41 -0
  339. onlinepayments/sdk/domain/surcharge.py +141 -0
  340. onlinepayments/sdk/domain/surcharge_calculation_card.py +55 -0
  341. onlinepayments/sdk/domain/surcharge_for_payment_link.py +40 -0
  342. onlinepayments/sdk/domain/surcharge_rate.py +91 -0
  343. onlinepayments/sdk/domain/surcharge_specific_input.py +62 -0
  344. onlinepayments/sdk/domain/surcharge_specific_output.py +84 -0
  345. onlinepayments/sdk/domain/test_connection.py +35 -0
  346. onlinepayments/sdk/domain/three_d_secure.py +281 -0
  347. onlinepayments/sdk/domain/three_d_secure_base.py +219 -0
  348. onlinepayments/sdk/domain/three_d_secure_data.py +78 -0
  349. onlinepayments/sdk/domain/three_d_secure_results.py +266 -0
  350. onlinepayments/sdk/domain/token_card.py +57 -0
  351. onlinepayments/sdk/domain/token_card_data.py +83 -0
  352. onlinepayments/sdk/domain/token_card_specific_input.py +41 -0
  353. onlinepayments/sdk/domain/token_data.py +63 -0
  354. onlinepayments/sdk/domain/token_e_wallet.py +59 -0
  355. onlinepayments/sdk/domain/token_response.py +181 -0
  356. onlinepayments/sdk/domain/transaction.py +41 -0
  357. onlinepayments/sdk/domain/uploadable_file.py +51 -0
  358. onlinepayments/sdk/domain/validate_credentials_request.py +55 -0
  359. onlinepayments/sdk/domain/validate_credentials_response.py +37 -0
  360. onlinepayments/sdk/domain/value_mapping_element.py +62 -0
  361. onlinepayments/sdk/domain/web_hooks_event.py +214 -0
  362. onlinepayments/sdk/exception_factory.py +75 -0
  363. onlinepayments/sdk/factory.py +127 -0
  364. onlinepayments/sdk/i_client.py +78 -0
  365. onlinepayments/sdk/i_communicator.py +180 -0
  366. onlinepayments/sdk/idempotence_exception.py +36 -0
  367. onlinepayments/sdk/json/__init__.py +0 -0
  368. onlinepayments/sdk/json/default_marshaller.py +60 -0
  369. onlinepayments/sdk/json/marshaller.py +32 -0
  370. onlinepayments/sdk/json/marshaller_syntax_exception.py +13 -0
  371. onlinepayments/sdk/log/__init__.py +0 -0
  372. onlinepayments/sdk/log/body_obfuscator.py +113 -0
  373. onlinepayments/sdk/log/communicator_logger.py +35 -0
  374. onlinepayments/sdk/log/header_obfuscator.py +49 -0
  375. onlinepayments/sdk/log/log_message.py +94 -0
  376. onlinepayments/sdk/log/logging_capable.py +26 -0
  377. onlinepayments/sdk/log/obfuscation_capable.py +24 -0
  378. onlinepayments/sdk/log/obfuscation_rule.py +50 -0
  379. onlinepayments/sdk/log/python_communicator_logger.py +54 -0
  380. onlinepayments/sdk/log/request_log_message.py +28 -0
  381. onlinepayments/sdk/log/response_log_message.py +37 -0
  382. onlinepayments/sdk/log/sys_out_communicator_logger.py +36 -0
  383. onlinepayments/sdk/merchant/__init__.py +4 -0
  384. onlinepayments/sdk/merchant/captures/__init__.py +4 -0
  385. onlinepayments/sdk/merchant/captures/captures_client.py +63 -0
  386. onlinepayments/sdk/merchant/captures/i_captures_client.py +34 -0
  387. onlinepayments/sdk/merchant/cofseries/__init__.py +4 -0
  388. onlinepayments/sdk/merchant/cofseries/cof_series_client.py +62 -0
  389. onlinepayments/sdk/merchant/cofseries/i_cof_series_client.py +35 -0
  390. onlinepayments/sdk/merchant/complete/__init__.py +4 -0
  391. onlinepayments/sdk/merchant/complete/complete_client.py +67 -0
  392. onlinepayments/sdk/merchant/complete/i_complete_client.py +37 -0
  393. onlinepayments/sdk/merchant/hostedcheckout/__init__.py +4 -0
  394. onlinepayments/sdk/merchant/hostedcheckout/hosted_checkout_client.py +99 -0
  395. onlinepayments/sdk/merchant/hostedcheckout/i_hosted_checkout_client.py +55 -0
  396. onlinepayments/sdk/merchant/hostedfields/__init__.py +4 -0
  397. onlinepayments/sdk/merchant/hostedfields/hosted_fields_client.py +62 -0
  398. onlinepayments/sdk/merchant/hostedfields/i_hosted_fields_client.py +35 -0
  399. onlinepayments/sdk/merchant/hostedtokenization/__init__.py +4 -0
  400. onlinepayments/sdk/merchant/hostedtokenization/hosted_tokenization_client.py +99 -0
  401. onlinepayments/sdk/merchant/hostedtokenization/i_hosted_tokenization_client.py +55 -0
  402. onlinepayments/sdk/merchant/i_merchant_client.py +202 -0
  403. onlinepayments/sdk/merchant/mandates/__init__.py +4 -0
  404. onlinepayments/sdk/merchant/mandates/i_mandates_client.py +114 -0
  405. onlinepayments/sdk/merchant/mandates/mandates_client.py +212 -0
  406. onlinepayments/sdk/merchant/merchant_client.py +232 -0
  407. onlinepayments/sdk/merchant/merchantbatch/__init__.py +4 -0
  408. onlinepayments/sdk/merchant/merchantbatch/i_merchant_batch_client.py +74 -0
  409. onlinepayments/sdk/merchant/merchantbatch/merchant_batch_client.py +138 -0
  410. onlinepayments/sdk/merchant/paymentlinks/__init__.py +4 -0
  411. onlinepayments/sdk/merchant/paymentlinks/get_payment_links_in_bulk_params.py +36 -0
  412. onlinepayments/sdk/merchant/paymentlinks/i_payment_links_client.py +73 -0
  413. onlinepayments/sdk/merchant/paymentlinks/payment_links_client.py +135 -0
  414. onlinepayments/sdk/merchant/payments/__init__.py +4 -0
  415. onlinepayments/sdk/merchant/payments/i_payments_client.py +143 -0
  416. onlinepayments/sdk/merchant/payments/payments_client.py +260 -0
  417. onlinepayments/sdk/merchant/payouts/__init__.py +4 -0
  418. onlinepayments/sdk/merchant/payouts/i_payouts_client.py +55 -0
  419. onlinepayments/sdk/merchant/payouts/payouts_client.py +100 -0
  420. onlinepayments/sdk/merchant/privacypolicy/__init__.py +4 -0
  421. onlinepayments/sdk/merchant/privacypolicy/get_privacy_policy_params.py +54 -0
  422. onlinepayments/sdk/merchant/privacypolicy/i_privacy_policy_client.py +36 -0
  423. onlinepayments/sdk/merchant/privacypolicy/privacy_policy_client.py +61 -0
  424. onlinepayments/sdk/merchant/productgroups/__init__.py +4 -0
  425. onlinepayments/sdk/merchant/productgroups/get_product_group_params.py +140 -0
  426. onlinepayments/sdk/merchant/productgroups/get_product_groups_params.py +140 -0
  427. onlinepayments/sdk/merchant/productgroups/i_product_groups_client.py +58 -0
  428. onlinepayments/sdk/merchant/productgroups/product_groups_client.py +100 -0
  429. onlinepayments/sdk/merchant/products/__init__.py +4 -0
  430. onlinepayments/sdk/merchant/products/get_payment_product_networks_params.py +89 -0
  431. onlinepayments/sdk/merchant/products/get_payment_product_params.py +138 -0
  432. onlinepayments/sdk/merchant/products/get_payment_products_params.py +138 -0
  433. onlinepayments/sdk/merchant/products/get_product_directory_params.py +54 -0
  434. onlinepayments/sdk/merchant/products/i_products_client.py +102 -0
  435. onlinepayments/sdk/merchant/products/products_client.py +178 -0
  436. onlinepayments/sdk/merchant/refunds/__init__.py +4 -0
  437. onlinepayments/sdk/merchant/refunds/i_refunds_client.py +34 -0
  438. onlinepayments/sdk/merchant/refunds/refunds_client.py +63 -0
  439. onlinepayments/sdk/merchant/services/__init__.py +4 -0
  440. onlinepayments/sdk/merchant/services/i_services_client.py +96 -0
  441. onlinepayments/sdk/merchant/services/services_client.py +167 -0
  442. onlinepayments/sdk/merchant/sessions/__init__.py +4 -0
  443. onlinepayments/sdk/merchant/sessions/i_sessions_client.py +35 -0
  444. onlinepayments/sdk/merchant/sessions/sessions_client.py +62 -0
  445. onlinepayments/sdk/merchant/subsequent/__init__.py +4 -0
  446. onlinepayments/sdk/merchant/subsequent/i_subsequent_client.py +37 -0
  447. onlinepayments/sdk/merchant/subsequent/subsequent_client.py +67 -0
  448. onlinepayments/sdk/merchant/tokenization/__init__.py +4 -0
  449. onlinepayments/sdk/merchant/tokenization/get_card_data_by_payments_params.py +48 -0
  450. onlinepayments/sdk/merchant/tokenization/get_card_data_by_tokens_params.py +48 -0
  451. onlinepayments/sdk/merchant/tokenization/i_tokenization_client.py +77 -0
  452. onlinepayments/sdk/merchant/tokenization/tokenization_client.py +131 -0
  453. onlinepayments/sdk/merchant/tokens/__init__.py +4 -0
  454. onlinepayments/sdk/merchant/tokens/i_tokens_client.py +74 -0
  455. onlinepayments/sdk/merchant/tokens/tokens_client.py +135 -0
  456. onlinepayments/sdk/merchant/webhooks/__init__.py +4 -0
  457. onlinepayments/sdk/merchant/webhooks/i_webhooks_client.py +55 -0
  458. onlinepayments/sdk/merchant/webhooks/webhooks_client.py +97 -0
  459. onlinepayments/sdk/platform_exception.py +19 -0
  460. onlinepayments/sdk/proxy_configuration.py +102 -0
  461. onlinepayments/sdk/reference_exception.py +19 -0
  462. onlinepayments/sdk/validation_exception.py +19 -0
  463. onlinepayments/sdk/webhooks/__init__.py +0 -0
  464. onlinepayments/sdk/webhooks/api_version_mismatch_exception.py +24 -0
  465. onlinepayments/sdk/webhooks/in_memory_secret_key_store.py +48 -0
  466. onlinepayments/sdk/webhooks/secret_key_not_available_exception.py +18 -0
  467. onlinepayments/sdk/webhooks/secret_key_store.py +15 -0
  468. onlinepayments/sdk/webhooks/signature_validation_exception.py +17 -0
  469. onlinepayments/sdk/webhooks/signature_validator.py +56 -0
  470. onlinepayments/sdk/webhooks/webhooks_helper.py +52 -0
  471. onlinepayments_sdk_python3-7.4.1.dist-info/METADATA +154 -0
  472. onlinepayments_sdk_python3-7.4.1.dist-info/RECORD +475 -0
  473. onlinepayments_sdk_python3-7.4.1.dist-info/WHEEL +5 -0
  474. onlinepayments_sdk_python3-7.4.1.dist-info/licenses/LICENSE.txt +52 -0
  475. onlinepayments_sdk_python3-7.4.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # This file was automatically generated.
4
+ #
5
+ from typing import List, Optional
6
+
7
+ from .api_exception import ApiException
8
+
9
+ from onlinepayments.sdk.domain.api_error import APIError
10
+
11
+
12
+ class IdempotenceException(ApiException):
13
+ """
14
+ Represents an error response from the payment platform when an idempotent request failed because the first request has not finished yet.
15
+ """
16
+
17
+ def __init__(self, idempotence_key: str, idempotence_request_timestamp: int,
18
+ status_code: int, response_body: str, error_id: Optional[str], errors: Optional[List[APIError]],
19
+ message: str = "the payment platform returned a duplicate request error response"):
20
+ super(IdempotenceException, self).__init__(status_code, response_body, error_id, errors, message)
21
+ self.__idempotence_key = idempotence_key
22
+ self.__idempotence_request_timestamp = idempotence_request_timestamp
23
+
24
+ @property
25
+ def idempotence_key(self) -> str:
26
+ """
27
+ :return: The key that was used for the idempotent request.
28
+ """
29
+ return self.__idempotence_key
30
+
31
+ @property
32
+ def idempotence_request_timestamp(self) -> int:
33
+ """
34
+ :return: The request timestamp of the first idempotent request with the same key.
35
+ """
36
+ return self.__idempotence_request_timestamp
File without changes
@@ -0,0 +1,60 @@
1
+ from json import dumps, loads
2
+ from typing import Any, Type, Union
3
+
4
+ from .marshaller import Marshaller, T
5
+ from .marshaller_syntax_exception import MarshallerSyntaxException
6
+
7
+ from onlinepayments.sdk.domain.data_object import DataObject
8
+
9
+
10
+ class DefaultMarshaller(Marshaller):
11
+ """
12
+ Marshaller implementation based on json.
13
+ """
14
+
15
+ @staticmethod
16
+ def instance() -> 'DefaultMarshaller':
17
+ return _DEFAULT_MARSHALLER_INSTANCE
18
+
19
+ def marshal(self, request_object: Any) -> str:
20
+ if isinstance(request_object, DataObject):
21
+ dictionary = request_object.to_dictionary()
22
+ return dumps(dictionary,
23
+ default=lambda o: o.to_dictionary(),
24
+ indent=4)
25
+ else:
26
+ return dumps(request_object,
27
+ default=lambda o: o.__dict__,
28
+ indent=4)
29
+
30
+ def unmarshal(self, response_json: Union[str, bytes, None], type_class: Type[T]) -> T:
31
+ if not response_json:
32
+ return None
33
+ if issubclass(type_class, DataObject):
34
+ try:
35
+ return type_class().from_dictionary(loads(response_json))
36
+ except ValueError as e:
37
+ raise MarshallerSyntaxException(e) from e
38
+
39
+ class Object(object):
40
+ pass
41
+
42
+ def convert_to_object(d):
43
+ try:
44
+ d = dict(d)
45
+ except (TypeError, ValueError):
46
+ return d
47
+ o = Object()
48
+ for key, value in d.items():
49
+ o.__dict__[key] = convert_to_object(value)
50
+ return o
51
+
52
+ try:
53
+ dictionary = loads(response_json)
54
+ converted_object = convert_to_object(dictionary)
55
+ return converted_object
56
+ except ValueError as e:
57
+ raise MarshallerSyntaxException(e) from e
58
+
59
+
60
+ _DEFAULT_MARSHALLER_INSTANCE = DefaultMarshaller()
@@ -0,0 +1,32 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Any, Optional, Type, TypeVar, Union
3
+
4
+
5
+ T = TypeVar('T')
6
+
7
+
8
+ class Marshaller(ABC):
9
+ """
10
+ Used to marshal and unmarshal Online Payments platform request and response objects to and from JSON.
11
+ """
12
+
13
+ @abstractmethod
14
+ def marshal(self, request_object: Any) -> str:
15
+ """
16
+ Marshal a request object to a JSON string.
17
+
18
+ :param request_object: the object to marshal into a serialized JSON string
19
+ :return: the serialized JSON string of the request_object
20
+ """
21
+ raise NotImplementedError
22
+
23
+ @abstractmethod
24
+ def unmarshal(self, response_json: Union[str, bytes, None], type_class: Type[T]) -> Optional[T]:
25
+ """
26
+ Unmarshal a JSON string to a response object.
27
+
28
+ :param response_json: the json body that should be unmarshalled
29
+ :param type_class: The class to which the response_json should be unmarshalled
30
+ :raise MarshallerSyntaxException: if the JSON is not a valid representation for an object of the given type
31
+ """
32
+ raise NotImplementedError
@@ -0,0 +1,13 @@
1
+ from typing import Optional
2
+
3
+
4
+ class MarshallerSyntaxException(RuntimeError):
5
+ """
6
+ Thrown when a JSON string cannot be converted to a response object.
7
+ """
8
+
9
+ def __init__(self, cause: Optional[Exception] = None):
10
+ if cause:
11
+ super(MarshallerSyntaxException, self).__init__(cause)
12
+ else:
13
+ super(MarshallerSyntaxException, self).__init__()
File without changes
@@ -0,0 +1,113 @@
1
+ import codecs
2
+ import re
3
+
4
+ from typing import AnyStr, Dict, Mapping, Optional, Pattern, Sequence, Union
5
+
6
+ from .obfuscation_rule import ObfuscationRule, obfuscate_all, obfuscate_with_fixed_length, obfuscate_all_but_first, obfuscate_all_but_last
7
+
8
+
9
+ class BodyObfuscator(object):
10
+ """
11
+ A class that can be used to obfuscate properties in JSON bodies.
12
+ """
13
+
14
+ __obfuscation_rules: Dict[str, ObfuscationRule] = None
15
+ __property_pattern: Pattern[AnyStr] = None
16
+
17
+ def __init__(self, additional_rules: Optional[Mapping[str, ObfuscationRule]] = None):
18
+ """
19
+ Creates a new body obfuscator.
20
+ This will contain some pre-defined obfuscation rules, as well as any provided custom rules
21
+
22
+ :param additional_rules: An optional mapping from property names to obfuscation rules,
23
+ where an obfuscation rule is a function that obfuscates a single string,
24
+ """
25
+ self.__obfuscation_rules = {
26
+ "additionalInfo": obfuscate_all(),
27
+ "cardholderName": obfuscate_all(),
28
+ "dateOfBirth": obfuscate_all(),
29
+ "emailAddress": obfuscate_all(),
30
+ "faxNumber": obfuscate_all(),
31
+ "firstName": obfuscate_all(),
32
+ "houseNumber": obfuscate_all(),
33
+ "mobilePhoneNumber": obfuscate_all(),
34
+ "passengerName": obfuscate_all(),
35
+ "phoneNumber": obfuscate_all(),
36
+ "street": obfuscate_all(),
37
+ "workPhoneNumber": obfuscate_all(),
38
+ "zip": obfuscate_all(),
39
+ "cardNumber": obfuscate_all_but_last(4),
40
+ "expiryDate": obfuscate_all_but_last(2),
41
+ "cvv": obfuscate_all(),
42
+ "iban": obfuscate_all_but_last(4),
43
+ "accountNumber": obfuscate_all_but_last(4),
44
+ "reformattedAccountNumber": obfuscate_all_but_last(4),
45
+ "bin": obfuscate_all_but_first(6),
46
+ "value": obfuscate_all(),
47
+ "keyId": obfuscate_with_fixed_length(8),
48
+ "secretKey": obfuscate_with_fixed_length(8),
49
+ "publicKey": obfuscate_with_fixed_length(8),
50
+ "userAuthenticationToken": obfuscate_with_fixed_length(8),
51
+ "encryptedPayload": obfuscate_with_fixed_length(8),
52
+ "decryptedPayload": obfuscate_with_fixed_length(8),
53
+ "encryptedCustomerInput": obfuscate_with_fixed_length(8),
54
+ }
55
+ if additional_rules:
56
+ for name, rule in additional_rules.items():
57
+ self.__obfuscation_rules[name] = rule
58
+
59
+ property_names = tuple(self.__obfuscation_rules.keys())
60
+ self.__property_pattern = self.__build_property_pattern(property_names)
61
+
62
+ @staticmethod
63
+ def __build_property_pattern(property_names: Sequence[str]) -> Pattern[AnyStr]:
64
+ if not property_names:
65
+ return re.compile("$^")
66
+ s = "([\"'])("
67
+ for p in property_names:
68
+ s += '|' + re.escape(p)
69
+ s += ")\\1\\s*:\\s*(?:([\"'])(.*?)(?<!\\\\)\\3|([^\"'\\s\\[\\{]((?!,)\\S)*))"
70
+ return re.compile(s, re.DOTALL)
71
+
72
+ def __obfuscate_value(self, property_name: str, value: str) -> str:
73
+ obfuscation_rule = self.__obfuscation_rules.get(property_name)
74
+ if obfuscation_rule:
75
+ return obfuscation_rule(value)
76
+ return value
77
+
78
+ def obfuscate_body(self, body: Union[str, bytes, None], charset: Optional[str] = None) -> Optional[str]:
79
+ """
80
+ Obfuscates the body from the given stream as necessary.
81
+ :param body: The body to obfuscate, as string or bytes.
82
+ :param charset: The charset to use to read the body bytes.
83
+ """
84
+ if charset:
85
+ body = codecs.decode(body, charset)
86
+
87
+ if body is None:
88
+ return None
89
+ if not body:
90
+ return ""
91
+ index = 0
92
+ s_obfuscate = ""
93
+ matcher = self.__property_pattern.finditer(body)
94
+ for x in matcher:
95
+ property_name = x.group(2)
96
+ value = x.group(4)
97
+ value_start = x.start(4)
98
+ value_end = x.end(4)
99
+ if not value:
100
+ value = x.group(5)
101
+ value_start = x.start(5)
102
+ value_end = x.end(5)
103
+ obfuscated_value = self.__obfuscate_value(property_name, value)
104
+ s_obfuscate += body[index:value_start] + obfuscated_value
105
+ index = value_end
106
+ return s_obfuscate + body[index:]
107
+
108
+ @staticmethod
109
+ def default_body_obfuscator() -> 'BodyObfuscator':
110
+ return _DEFAULT_BODY_OBFUSCATOR
111
+
112
+
113
+ _DEFAULT_BODY_OBFUSCATOR = BodyObfuscator()
@@ -0,0 +1,35 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Optional
3
+
4
+ from .request_log_message import RequestLogMessage
5
+ from .response_log_message import ResponseLogMessage
6
+
7
+
8
+ class CommunicatorLogger(ABC):
9
+ """
10
+ Used to log messages from communicators.
11
+ """
12
+
13
+ def log_request(self, request_log_message: RequestLogMessage) -> None:
14
+ """
15
+ Logs a request message object
16
+
17
+ """
18
+ self.log(request_log_message.get_message())
19
+
20
+ def log_response(self, response_log_message: ResponseLogMessage) -> None:
21
+ """
22
+ Logs a response message object
23
+
24
+ """
25
+ self.log(response_log_message.get_message())
26
+
27
+ @abstractmethod
28
+ def log(self, message: str, thrown: Optional[Exception] = None) -> None:
29
+ """
30
+ Logs a throwable with an accompanying message.
31
+
32
+ :param message: The message accompanying the throwable.
33
+ :param thrown: The throwable to log.
34
+ """
35
+ raise NotImplementedError
@@ -0,0 +1,49 @@
1
+ from typing import Dict, Mapping, Optional
2
+
3
+ from .obfuscation_rule import ObfuscationRule, obfuscate_with_fixed_length
4
+
5
+
6
+ class HeaderObfuscator(object):
7
+ """
8
+ A class that can be used to obfuscate headers.
9
+ """
10
+
11
+ __obfuscation_rules: Dict[str, ObfuscationRule] = None
12
+
13
+ def __init__(self, additional_rules: Optional[Mapping[str, ObfuscationRule]] = None):
14
+ """
15
+ Creates a new header obfuscator.
16
+ This will contain some pre-defined obfuscation rules, as well as any provided custom rules
17
+
18
+ :param additional_rules: An optional mapping from property names to obfuscation rules,
19
+ where an obfuscation rule is a function that obfuscates a single string,
20
+ """
21
+ self.__obfuscation_rules = {
22
+ "X-GCS-Authentication-Token": obfuscate_with_fixed_length(8),
23
+ "X-GCS-CallerPassword": obfuscate_with_fixed_length(8),
24
+ "authorization": obfuscate_with_fixed_length(8),
25
+ "www-authenticate": obfuscate_with_fixed_length(8),
26
+ "proxy-authenticate": obfuscate_with_fixed_length(8),
27
+ "proxy-authorization": obfuscate_with_fixed_length(8),
28
+ }
29
+ if additional_rules:
30
+ for name, rule in additional_rules.items():
31
+ name = name.lower()
32
+ self.__obfuscation_rules[name] = rule
33
+
34
+ def obfuscate_header(self, header_name: str, value: str) -> str:
35
+ """
36
+ Obfuscates the value for the given header as necessary.
37
+ """
38
+ header_name = header_name.lower()
39
+ obfuscation_rule = self.__obfuscation_rules.get(header_name)
40
+ if obfuscation_rule:
41
+ return obfuscation_rule(value)
42
+ return value
43
+
44
+ @staticmethod
45
+ def default_header_obfuscator() -> 'HeaderObfuscator':
46
+ return _DEFAULT_HEADER_OBFUSCATOR
47
+
48
+
49
+ _DEFAULT_HEADER_OBFUSCATOR = HeaderObfuscator()
@@ -0,0 +1,94 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import List, Optional, Sequence, Tuple, Union
3
+
4
+ from .body_obfuscator import BodyObfuscator
5
+ from .header_obfuscator import HeaderObfuscator
6
+
7
+
8
+ class LogMessage(ABC):
9
+ """
10
+ A utility class to build log messages.
11
+ """
12
+ __request_id: str = None
13
+ __headers: str = None
14
+ __body: Optional[str] = None
15
+ __content_type: Optional[str] = None
16
+ __header_list: List[Tuple[str, str]] = None
17
+ __body_obfuscator: BodyObfuscator = None
18
+ __header_obfuscator: HeaderObfuscator = None
19
+
20
+ def __init__(self, request_id: str,
21
+ body_obfuscator: BodyObfuscator = BodyObfuscator.default_body_obfuscator(),
22
+ header_obfuscator: HeaderObfuscator = HeaderObfuscator.default_header_obfuscator()):
23
+ if not request_id:
24
+ raise ValueError("request_id is required")
25
+ if not body_obfuscator:
26
+ raise ValueError("body_obfuscator is required")
27
+ if not header_obfuscator:
28
+ raise ValueError("header_obfuscator is required")
29
+ self.__request_id = request_id
30
+ self.__headers = ""
31
+ self.__header_list = []
32
+ self.__body_obfuscator = body_obfuscator
33
+ self.__header_obfuscator = header_obfuscator
34
+
35
+ @property
36
+ def request_id(self) -> str:
37
+ return self.__request_id
38
+
39
+ @property
40
+ def headers(self) -> str:
41
+ return str(self.__headers)
42
+
43
+ @property
44
+ def body(self) -> Optional[str]:
45
+ return self.__body
46
+
47
+ @property
48
+ def content_type(self) -> Optional[str]:
49
+ return self.__content_type
50
+
51
+ def add_header(self, name: str, value: Optional[str]) -> None:
52
+ if self.__headers:
53
+ self.__headers += ", "
54
+ self.__headers += name + "=\""
55
+ if value is not None and value.lower() != 'none':
56
+ obfuscated_value = self.__header_obfuscator.obfuscate_header(name, value)
57
+ self.__headers += obfuscated_value
58
+ self.__header_list.append((name, "\"" + obfuscated_value + "\""))
59
+ else:
60
+ self.__header_list.append((name, "\"\""))
61
+ self.__headers += "\""
62
+
63
+ def set_body(self, body: Union[str, bytes, None], content_type: Optional[str], charset: Optional[str] = None) -> None:
64
+ self.__content_type = content_type
65
+ if self.__is_binary(content_type):
66
+ self.__body = "<binary content>"
67
+ else:
68
+ self.__body = self.__body_obfuscator.obfuscate_body(body, charset)
69
+
70
+ def set_binary_body(self, content_type: Optional[str]) -> None:
71
+ if not self.__is_binary(content_type):
72
+ raise ValueError("Not a binary content type: " + content_type)
73
+ self.__content_type = content_type
74
+ self.__body = "<binary content>"
75
+
76
+ @staticmethod
77
+ def __is_binary(content_type: Optional[str]) -> bool:
78
+ if content_type is None:
79
+ return False
80
+ content_type = content_type.lower()
81
+ return not (content_type.startswith("text/") or "json" in content_type or "xml" in content_type)
82
+
83
+ @staticmethod
84
+ def empty_if_none(value: Optional[str]) -> str:
85
+ if value is not None:
86
+ return value
87
+ return ""
88
+
89
+ @abstractmethod
90
+ def get_message(self) -> str:
91
+ raise NotImplementedError
92
+
93
+ def get_header_list(self) -> Sequence[Tuple[str, str]]:
94
+ return self.__header_list
@@ -0,0 +1,26 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from .communicator_logger import CommunicatorLogger
4
+
5
+
6
+ class LoggingCapable(ABC):
7
+ """
8
+ Classes that extend this class have support for log messages from
9
+ communicators.
10
+ """
11
+
12
+ @abstractmethod
13
+ def enable_logging(self, communicator_logger: CommunicatorLogger) -> None:
14
+ """
15
+ Turns on logging using the given communicator logger.
16
+
17
+ :raise ValueError: If the given communicator logger is None.
18
+ """
19
+ raise NotImplementedError
20
+
21
+ @abstractmethod
22
+ def disable_logging(self) -> None:
23
+ """
24
+ Turns off logging.
25
+ """
26
+ raise NotImplementedError
@@ -0,0 +1,24 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from .body_obfuscator import BodyObfuscator
4
+ from .header_obfuscator import HeaderObfuscator
5
+
6
+
7
+ class ObfuscationCapable(ABC):
8
+ """
9
+ Classes that extend this class support obfuscating bodies and headers.
10
+ """
11
+
12
+ @abstractmethod
13
+ def set_body_obfuscator(self, body_obfuscator: BodyObfuscator) -> None:
14
+ """
15
+ Sets the current body obfuscator to use.
16
+ """
17
+ raise NotImplementedError
18
+
19
+ @abstractmethod
20
+ def set_header_obfuscator(self, header_obfuscator: HeaderObfuscator) -> None:
21
+ """
22
+ Sets the current header obfuscator to use.
23
+ """
24
+ raise NotImplementedError
@@ -0,0 +1,50 @@
1
+ from typing import Callable
2
+
3
+
4
+ ObfuscationRule = Callable[[str], str]
5
+
6
+
7
+ def obfuscate_all() -> ObfuscationRule:
8
+ """
9
+ Returns an obfuscation rule (function) that will replace all characters with *
10
+ """
11
+ return lambda value: '*' * len(value) if value else value
12
+
13
+
14
+ def obfuscate_with_fixed_length(fixed_length: int) -> ObfuscationRule:
15
+ """
16
+ Returns an obfuscation rule (function) that will replace values with a fixed length string containing only *
17
+ """
18
+ return lambda value: '*' * fixed_length
19
+
20
+
21
+ def obfuscate_all_but_first(count: int) -> ObfuscationRule:
22
+ """
23
+ Returns an obfuscation rule (function) that will keep a fixed number of characters at the start,
24
+ then replaces all other characters with *
25
+ """
26
+ def obfuscate_value(value: str) -> str:
27
+ if not value:
28
+ return value
29
+ length = len(value)
30
+ if length < count:
31
+ return value
32
+ end = '*' * (length - count)
33
+ return value[:count] + end
34
+ return obfuscate_value
35
+
36
+
37
+ def obfuscate_all_but_last(count: int) -> ObfuscationRule:
38
+ """
39
+ Returns an obfuscation rule that will keep a fixed number of characters at the end,
40
+ then replaces all other characters with *
41
+ """
42
+ def obfuscate_value(value: str) -> str:
43
+ if not value:
44
+ return value
45
+ length = len(value)
46
+ if length < count:
47
+ return value
48
+ start = '*' * (length - count)
49
+ return start + value[-count:]
50
+ return obfuscate_value
@@ -0,0 +1,54 @@
1
+ from logging import Logger
2
+ from typing import Optional
3
+
4
+ from .communicator_logger import CommunicatorLogger
5
+
6
+
7
+ class PythonCommunicatorLogger(CommunicatorLogger):
8
+ """
9
+ A communicator logger that is backed by the log library.
10
+ """
11
+
12
+ def __init__(self, logger: Logger, log_level: int, error_log_level: Optional[int] = None):
13
+ """
14
+ Logs messages to the argument logger using the argument log_level.
15
+ If absent, the error_log_level will be equal to the log_level.
16
+ Note that if the CommunicatorLogger's log level is lower than the
17
+ argument logger's log level (e.g. the CommunicatorLogger is given
18
+ log.INFO as level and the argument logger has a level of
19
+ log.WARNING), then nothing will be logged to the logger.
20
+
21
+ :param logger: the logger to log to
22
+ :param log_level: the log level that will be used for non-error
23
+ messages logged via the CommunicatorLogger
24
+ :param error_log_level: the log level that will be used for error
25
+ messages logged via the CommunicatorLogger.
26
+ """
27
+ CommunicatorLogger.__init__(self)
28
+ if not error_log_level:
29
+ error_log_level = log_level
30
+ if logger is None:
31
+ raise ValueError("logger is required")
32
+ if log_level is None:
33
+ raise ValueError("log_level is required")
34
+ if error_log_level is None:
35
+ raise ValueError("error_log_level is required")
36
+ self.__logger = logger
37
+ self.__log_level = log_level
38
+ self.__error_log_level = error_log_level
39
+
40
+ def log(self, message: str, thrown: Optional[Exception] = None) -> None:
41
+ """
42
+ Log a message to the underlying logger.
43
+ If thrown is absent, the message will be logged with the
44
+ CommunicatorLogger's log_level, if a thrown object is provided,
45
+ the message and exception will be logged with the CommunicatorLogger's
46
+ error_log_level.
47
+
48
+ :param message: the message to be logged
49
+ :param thrown: an optional throwable object
50
+ """
51
+ if not thrown:
52
+ self.__logger.log(self.__log_level, message)
53
+ else:
54
+ self.__logger.log(self.__error_log_level, message, thrown)
@@ -0,0 +1,28 @@
1
+ from .body_obfuscator import BodyObfuscator
2
+ from .header_obfuscator import HeaderObfuscator
3
+ from .log_message import LogMessage
4
+
5
+
6
+ class RequestLogMessage(LogMessage):
7
+ """
8
+ A utility class to build request log messages.
9
+ """
10
+
11
+ def __init__(self, request_id: str, method: str, uri: str,
12
+ body_obfuscator: BodyObfuscator = BodyObfuscator.default_body_obfuscator(),
13
+ header_obfuscator: HeaderObfuscator = HeaderObfuscator.default_header_obfuscator()):
14
+ super(RequestLogMessage, self).__init__(request_id, body_obfuscator, header_obfuscator)
15
+ self.method = method
16
+ self.uri = uri
17
+
18
+ def get_message(self) -> str:
19
+ string = "Outgoing request (requestId='" + str(self.request_id) + "'):\n" + \
20
+ " method: " + self.empty_if_none("'" + self.method + "'") + "\n" + \
21
+ " uri: " + self.empty_if_none("'" + self.uri + "'") + "\n" + \
22
+ " headers: " + self.headers
23
+ body = self.body
24
+ if body is None:
25
+ return string
26
+ else:
27
+ return string + "\n content-type: '" + self.empty_if_none(self.content_type) + "'\n" + \
28
+ " body: '" + body + "'"
@@ -0,0 +1,37 @@
1
+ from .body_obfuscator import BodyObfuscator
2
+ from .header_obfuscator import HeaderObfuscator
3
+ from .log_message import LogMessage
4
+
5
+
6
+ class ResponseLogMessage(LogMessage):
7
+ """
8
+ A utility class to build request log messages.
9
+ """
10
+
11
+ def __init__(self, request_id: str, status_code: int, duration: int = -1,
12
+ body_obfuscator: BodyObfuscator = BodyObfuscator.default_body_obfuscator(),
13
+ header_obfuscator: HeaderObfuscator = HeaderObfuscator.default_header_obfuscator()):
14
+ super(ResponseLogMessage, self).__init__(request_id, body_obfuscator, header_obfuscator)
15
+ self.__status_code = status_code
16
+ self.__duration = duration
17
+
18
+ def get_duration(self) -> int:
19
+ return self.__duration
20
+
21
+ def get_status_code(self) -> int:
22
+ return self.__status_code
23
+
24
+ def get_message(self) -> str:
25
+ if self.__duration < 0:
26
+ return "Incoming response (requestId='" + self.request_id + "'):\n" + \
27
+ " status_code: " + str(self.__status_code) + "\n" + \
28
+ " headers: " + self.headers + "\n" + \
29
+ " content-type: " + self.empty_if_none(self.content_type) + "\n" + \
30
+ " body: " + self.empty_if_none(self.body)
31
+
32
+ else:
33
+ return "Incoming response (requestId='" + self.request_id + "', " + str(self.__duration) + " ms):\n" + \
34
+ " status_code: " + str(self.__status_code) + "\n" + \
35
+ " headers: " + self.headers + "\n" + \
36
+ " content-type: " + self.empty_if_none(self.content_type) + "\n" + \
37
+ " body: " + self.empty_if_none(self.body)