mollie-api-py 1.0.0__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 (337) hide show
  1. mollie/__init__.py +18 -0
  2. mollie/_hooks/__init__.py +5 -0
  3. mollie/_hooks/mollie_hooks.py +165 -0
  4. mollie/_hooks/registration.py +18 -0
  5. mollie/_hooks/sdkhooks.py +76 -0
  6. mollie/_hooks/types.py +113 -0
  7. mollie/_version.py +15 -0
  8. mollie/balance_transfers.py +651 -0
  9. mollie/balances.py +1105 -0
  10. mollie/basesdk.py +360 -0
  11. mollie/capabilities.py +209 -0
  12. mollie/captures.py +677 -0
  13. mollie/chargebacks_sdk.py +675 -0
  14. mollie/client_links.py +325 -0
  15. mollie/clients.py +409 -0
  16. mollie/customers.py +1563 -0
  17. mollie/delayed_routing.py +421 -0
  18. mollie/httpclient.py +125 -0
  19. mollie/invoices.py +429 -0
  20. mollie/mandates.py +895 -0
  21. mollie/methods.py +789 -0
  22. mollie/models/__init__.py +4002 -0
  23. mollie/models/address.py +29 -0
  24. mollie/models/amount.py +25 -0
  25. mollie/models/amount_nullable.py +24 -0
  26. mollie/models/apierror.py +40 -0
  27. mollie/models/balance_card_audience.py +10 -0
  28. mollie/models/balance_card_issuer.py +12 -0
  29. mollie/models/balance_card_region.py +12 -0
  30. mollie/models/balance_fee_type.py +43 -0
  31. mollie/models/balance_prepayment_part_type.py +13 -0
  32. mollie/models/balance_report_grouping.py +10 -0
  33. mollie/models/balance_transaction_type.py +47 -0
  34. mollie/models/balance_transfer_category.py +17 -0
  35. mollie/models/balance_transfer_category_response.py +18 -0
  36. mollie/models/balance_transfer_destination_type.py +14 -0
  37. mollie/models/balance_transfer_party_type.py +10 -0
  38. mollie/models/balance_transfer_party_type_response.py +11 -0
  39. mollie/models/balance_transfer_status.py +13 -0
  40. mollie/models/balance_transfer_status_reason_response.py +19 -0
  41. mollie/models/billingaddress.py +154 -0
  42. mollie/models/cancel_paymentop.py +93 -0
  43. mollie/models/cancel_refundop.py +86 -0
  44. mollie/models/cancel_subscriptionop.py +100 -0
  45. mollie/models/capability_requirement_status.py +15 -0
  46. mollie/models/capability_status.py +12 -0
  47. mollie/models/capability_status_reason.py +10 -0
  48. mollie/models/capture_mode.py +15 -0
  49. mollie/models/capture_mode_response.py +16 -0
  50. mollie/models/capture_response.py +265 -0
  51. mollie/models/client_link_request.py +210 -0
  52. mollie/models/client_link_response.py +56 -0
  53. mollie/models/clienterror.py +30 -0
  54. mollie/models/components_sub_totals.py +127 -0
  55. mollie/models/create_captureop.py +43 -0
  56. mollie/models/create_client_linkop.py +29 -0
  57. mollie/models/create_connect_balance_transferop.py +32 -0
  58. mollie/models/create_customer_paymentop.py +43 -0
  59. mollie/models/create_customerop.py +29 -0
  60. mollie/models/create_mandateop.py +43 -0
  61. mollie/models/create_payment_linkop.py +325 -0
  62. mollie/models/create_paymentop.py +73 -0
  63. mollie/models/create_profileop.py +29 -0
  64. mollie/models/create_refundop.py +43 -0
  65. mollie/models/create_sales_invoiceop.py +29 -0
  66. mollie/models/create_subscriptionop.py +43 -0
  67. mollie/models/create_webhook.py +123 -0
  68. mollie/models/create_webhookop.py +69 -0
  69. mollie/models/currencies.py +20 -0
  70. mollie/models/customer_response.py +169 -0
  71. mollie/models/delete_customerop.py +91 -0
  72. mollie/models/delete_payment_linkop.py +91 -0
  73. mollie/models/delete_profileop.py +29 -0
  74. mollie/models/delete_sales_invoiceop.py +44 -0
  75. mollie/models/delete_values_sales_invoice.py +54 -0
  76. mollie/models/delete_webhookop.py +56 -0
  77. mollie/models/entity_balance.py +325 -0
  78. mollie/models/entity_balance_report.py +541 -0
  79. mollie/models/entity_balance_transaction.py +1068 -0
  80. mollie/models/entity_balance_transfer.py +62 -0
  81. mollie/models/entity_balance_transfer_party.py +28 -0
  82. mollie/models/entity_balance_transfer_party_response.py +32 -0
  83. mollie/models/entity_balance_transfer_response.py +159 -0
  84. mollie/models/entity_capability.py +75 -0
  85. mollie/models/entity_capability_requirement.py +87 -0
  86. mollie/models/entity_capture.py +63 -0
  87. mollie/models/entity_chargeback.py +247 -0
  88. mollie/models/entity_customer.py +86 -0
  89. mollie/models/entity_event.py +46 -0
  90. mollie/models/entity_invoice.py +247 -0
  91. mollie/models/entity_method_get.py +329 -0
  92. mollie/models/entity_onboarding_status.py +95 -0
  93. mollie/models/entity_organization.py +178 -0
  94. mollie/models/entity_payment_route.py +111 -0
  95. mollie/models/entity_payment_route_response.py +140 -0
  96. mollie/models/entity_permission.py +61 -0
  97. mollie/models/entity_refund_response.py +361 -0
  98. mollie/models/entity_route.py +96 -0
  99. mollie/models/entity_settlement.py +467 -0
  100. mollie/models/entity_terminal.py +160 -0
  101. mollie/models/entity_webhook.py +122 -0
  102. mollie/models/entity_webhook_event.py +149 -0
  103. mollie/models/error_response.py +70 -0
  104. mollie/models/get_balance_reportop.py +126 -0
  105. mollie/models/get_balanceop.py +71 -0
  106. mollie/models/get_captureop.py +129 -0
  107. mollie/models/get_chargebackop.py +129 -0
  108. mollie/models/get_clientop.py +216 -0
  109. mollie/models/get_connect_balance_transferop.py +71 -0
  110. mollie/models/get_current_organizationop.py +22 -0
  111. mollie/models/get_current_profileop.py +22 -0
  112. mollie/models/get_customerop.py +286 -0
  113. mollie/models/get_invoiceop.py +29 -0
  114. mollie/models/get_mandateop.py +86 -0
  115. mollie/models/get_methodop.py +199 -0
  116. mollie/models/get_next_settlementop.py +22 -0
  117. mollie/models/get_onboarding_statusop.py +22 -0
  118. mollie/models/get_open_settlementop.py +22 -0
  119. mollie/models/get_organizationop.py +71 -0
  120. mollie/models/get_partner_statusop.py +231 -0
  121. mollie/models/get_payment_link_paymentsop.py +188 -0
  122. mollie/models/get_payment_linkop.py +77 -0
  123. mollie/models/get_paymentop.py +128 -0
  124. mollie/models/get_permissionop.py +73 -0
  125. mollie/models/get_primary_balanceop.py +22 -0
  126. mollie/models/get_profileop.py +71 -0
  127. mollie/models/get_refundop.py +129 -0
  128. mollie/models/get_sales_invoiceop.py +75 -0
  129. mollie/models/get_settlementop.py +29 -0
  130. mollie/models/get_subscriptionop.py +86 -0
  131. mollie/models/get_terminalop.py +77 -0
  132. mollie/models/get_webhook_eventop.py +71 -0
  133. mollie/models/get_webhookop.py +71 -0
  134. mollie/models/internal/__init__.py +54 -0
  135. mollie/models/internal/globals.py +59 -0
  136. mollie/models/line_categories.py +13 -0
  137. mollie/models/line_categories_response.py +14 -0
  138. mollie/models/list_all_chargebacksop.py +236 -0
  139. mollie/models/list_all_methodsop.py +249 -0
  140. mollie/models/list_all_refundsop.py +230 -0
  141. mollie/models/list_all_subscriptionsop.py +202 -0
  142. mollie/models/list_balance_transactionsop.py +174 -0
  143. mollie/models/list_balancesop.py +171 -0
  144. mollie/models/list_capabilitiesop.py +62 -0
  145. mollie/models/list_capture_response.py +264 -0
  146. mollie/models/list_capturesop.py +185 -0
  147. mollie/models/list_chargebacksop.py +185 -0
  148. mollie/models/list_clientsop.py +269 -0
  149. mollie/models/list_connect_balance_transfersop.py +177 -0
  150. mollie/models/list_customer_paymentsop.py +231 -0
  151. mollie/models/list_customer_response.py +164 -0
  152. mollie/models/list_customersop.py +172 -0
  153. mollie/models/list_entity_balance.py +322 -0
  154. mollie/models/list_entity_chargeback.py +244 -0
  155. mollie/models/list_entity_invoice.py +244 -0
  156. mollie/models/list_entity_method.py +315 -0
  157. mollie/models/list_entity_method_all.py +391 -0
  158. mollie/models/list_entity_permission.py +56 -0
  159. mollie/models/list_entity_refund.py +352 -0
  160. mollie/models/list_entity_settlement.py +457 -0
  161. mollie/models/list_entity_terminal.py +157 -0
  162. mollie/models/list_entity_webhook.py +117 -0
  163. mollie/models/list_invoicesop.py +175 -0
  164. mollie/models/list_links.py +68 -0
  165. mollie/models/list_mandate_response.py +261 -0
  166. mollie/models/list_mandatesop.py +186 -0
  167. mollie/models/list_methodsop.py +332 -0
  168. mollie/models/list_payment_linksop.py +159 -0
  169. mollie/models/list_payment_response.py +1953 -0
  170. mollie/models/list_paymentsop.py +217 -0
  171. mollie/models/list_permissionsop.py +85 -0
  172. mollie/models/list_profile_response.py +194 -0
  173. mollie/models/list_profilesop.py +118 -0
  174. mollie/models/list_refundsop.py +189 -0
  175. mollie/models/list_route_get_response.py +97 -0
  176. mollie/models/list_sales_invoice_response.py +505 -0
  177. mollie/models/list_sales_invoicesop.py +172 -0
  178. mollie/models/list_settlement_capturesop.py +187 -0
  179. mollie/models/list_settlement_chargebacksop.py +187 -0
  180. mollie/models/list_settlement_paymentsop.py +233 -0
  181. mollie/models/list_settlement_refundsop.py +191 -0
  182. mollie/models/list_settlementsop.py +178 -0
  183. mollie/models/list_subscription_paymentsop.py +242 -0
  184. mollie/models/list_subscription_response.py +344 -0
  185. mollie/models/list_subscriptionsop.py +189 -0
  186. mollie/models/list_terminalsop.py +172 -0
  187. mollie/models/list_webhooksop.py +189 -0
  188. mollie/models/locale.py +32 -0
  189. mollie/models/locale_response.py +33 -0
  190. mollie/models/mandate_details_card_label_response.py +22 -0
  191. mollie/models/mandate_method.py +15 -0
  192. mollie/models/mandate_method_response.py +16 -0
  193. mollie/models/mandate_request.py +160 -0
  194. mollie/models/mandate_response.py +264 -0
  195. mollie/models/metadata.py +19 -0
  196. mollie/models/method.py +50 -0
  197. mollie/models/method_include_wallets_parameter.py +8 -0
  198. mollie/models/method_resource_parameter.py +9 -0
  199. mollie/models/method_response.py +59 -0
  200. mollie/models/method_status.py +15 -0
  201. mollie/models/mode.py +12 -0
  202. mollie/models/no_response_error.py +17 -0
  203. mollie/models/onboarding_vat_regulation.py +16 -0
  204. mollie/models/organization_vat_regulation.py +17 -0
  205. mollie/models/payment_address.py +130 -0
  206. mollie/models/payment_create_routeop.py +43 -0
  207. mollie/models/payment_details_card_audition_response.py +12 -0
  208. mollie/models/payment_details_card_funding_response.py +14 -0
  209. mollie/models/payment_details_card_label_response.py +23 -0
  210. mollie/models/payment_details_card_security_response.py +12 -0
  211. mollie/models/payment_details_failure_reason_response.py +25 -0
  212. mollie/models/payment_details_fee_region_response.py +20 -0
  213. mollie/models/payment_details_receipt_card_read_method_response.py +17 -0
  214. mollie/models/payment_details_receipt_card_verification_method_response.py +21 -0
  215. mollie/models/payment_details_seller_protection_response.py +20 -0
  216. mollie/models/payment_details_wallet_response.py +11 -0
  217. mollie/models/payment_line_item.py +96 -0
  218. mollie/models/payment_line_item_response.py +104 -0
  219. mollie/models/payment_line_type.py +20 -0
  220. mollie/models/payment_line_type_response.py +21 -0
  221. mollie/models/payment_link_method.py +36 -0
  222. mollie/models/payment_link_method_response.py +37 -0
  223. mollie/models/payment_link_response.py +348 -0
  224. mollie/models/payment_link_sequence_type.py +9 -0
  225. mollie/models/payment_link_sequence_type_response.py +10 -0
  226. mollie/models/payment_list_routesop.py +140 -0
  227. mollie/models/payment_method.py +53 -0
  228. mollie/models/payment_request.py +919 -0
  229. mollie/models/payment_response.py +1953 -0
  230. mollie/models/profile_request.py +67 -0
  231. mollie/models/profile_response.py +197 -0
  232. mollie/models/profile_review_status_response.py +12 -0
  233. mollie/models/recurring_line_item.py +77 -0
  234. mollie/models/refund_external_reference_type.py +10 -0
  235. mollie/models/refund_external_reference_type_response.py +11 -0
  236. mollie/models/refund_request.py +200 -0
  237. mollie/models/release_authorizationop.py +108 -0
  238. mollie/models/request_apple_pay_payment_sessionop.py +76 -0
  239. mollie/models/responsevalidationerror.py +27 -0
  240. mollie/models/revoke_mandateop.py +100 -0
  241. mollie/models/route_create_response.py +97 -0
  242. mollie/models/route_destination_type.py +10 -0
  243. mollie/models/route_destination_type_response.py +11 -0
  244. mollie/models/sales_invoice_discount.py +21 -0
  245. mollie/models/sales_invoice_discount_response.py +25 -0
  246. mollie/models/sales_invoice_discount_type.py +11 -0
  247. mollie/models/sales_invoice_discount_type_response.py +12 -0
  248. mollie/models/sales_invoice_email_details.py +20 -0
  249. mollie/models/sales_invoice_line_item.py +67 -0
  250. mollie/models/sales_invoice_line_item_response.py +70 -0
  251. mollie/models/sales_invoice_payment_details.py +59 -0
  252. mollie/models/sales_invoice_payment_details_response.py +66 -0
  253. mollie/models/sales_invoice_payment_details_source.py +12 -0
  254. mollie/models/sales_invoice_payment_details_source_response.py +13 -0
  255. mollie/models/sales_invoice_payment_term.py +16 -0
  256. mollie/models/sales_invoice_payment_term_response.py +17 -0
  257. mollie/models/sales_invoice_recipient.py +176 -0
  258. mollie/models/sales_invoice_recipient_locale.py +18 -0
  259. mollie/models/sales_invoice_recipient_locale_response.py +19 -0
  260. mollie/models/sales_invoice_recipient_response.py +182 -0
  261. mollie/models/sales_invoice_recipient_type.py +13 -0
  262. mollie/models/sales_invoice_recipient_type_response.py +14 -0
  263. mollie/models/sales_invoice_request.py +256 -0
  264. mollie/models/sales_invoice_response.py +509 -0
  265. mollie/models/sales_invoice_status.py +25 -0
  266. mollie/models/sales_invoice_status_response.py +26 -0
  267. mollie/models/sales_invoice_vat_mode.py +13 -0
  268. mollie/models/sales_invoice_vat_mode_response.py +14 -0
  269. mollie/models/sales_invoice_vat_scheme.py +11 -0
  270. mollie/models/sales_invoice_vat_scheme_response.py +12 -0
  271. mollie/models/security.py +35 -0
  272. mollie/models/sequence_type.py +10 -0
  273. mollie/models/sequence_type_response.py +11 -0
  274. mollie/models/sorting.py +9 -0
  275. mollie/models/status_reason.py +168 -0
  276. mollie/models/sub_group.py +52 -0
  277. mollie/models/sub_totals.py +120 -0
  278. mollie/models/submit_onboarding_dataop.py +214 -0
  279. mollie/models/subscription_method.py +12 -0
  280. mollie/models/subscription_method_response.py +13 -0
  281. mollie/models/subscription_request.py +213 -0
  282. mollie/models/subscription_response.py +349 -0
  283. mollie/models/terminal_brand.py +12 -0
  284. mollie/models/terminal_model.py +16 -0
  285. mollie/models/test_webhookop.py +64 -0
  286. mollie/models/update_customerop.py +43 -0
  287. mollie/models/update_payment_linkop.py +172 -0
  288. mollie/models/update_paymentop.py +332 -0
  289. mollie/models/update_profileop.py +147 -0
  290. mollie/models/update_sales_invoiceop.py +44 -0
  291. mollie/models/update_subscriptionop.py +188 -0
  292. mollie/models/update_values_sales_invoice.py +176 -0
  293. mollie/models/update_webhookop.py +83 -0
  294. mollie/models/url.py +24 -0
  295. mollie/models/url_nullable.py +25 -0
  296. mollie/models/webhook_event_types.py +18 -0
  297. mollie/models/webhook_status.py +14 -0
  298. mollie/onboarding.py +403 -0
  299. mollie/organizations.py +579 -0
  300. mollie/payment_links.py +1323 -0
  301. mollie/payments_sdk.py +1385 -0
  302. mollie/permissions.py +397 -0
  303. mollie/profiles.py +1209 -0
  304. mollie/py.typed +1 -0
  305. mollie/refunds_sdk.py +1111 -0
  306. mollie/sales_invoices.py +1121 -0
  307. mollie/sdk.py +265 -0
  308. mollie/sdkconfiguration.py +50 -0
  309. mollie/settlements.py +1735 -0
  310. mollie/subscriptions.py +1617 -0
  311. mollie/terminals.py +427 -0
  312. mollie/types/__init__.py +21 -0
  313. mollie/types/basemodel.py +39 -0
  314. mollie/utils/__init__.py +200 -0
  315. mollie/utils/annotations.py +79 -0
  316. mollie/utils/datetimes.py +23 -0
  317. mollie/utils/enums.py +74 -0
  318. mollie/utils/eventstreaming.py +248 -0
  319. mollie/utils/forms.py +223 -0
  320. mollie/utils/headers.py +136 -0
  321. mollie/utils/logger.py +27 -0
  322. mollie/utils/metadata.py +118 -0
  323. mollie/utils/queryparams.py +205 -0
  324. mollie/utils/requestbodies.py +66 -0
  325. mollie/utils/retries.py +217 -0
  326. mollie/utils/security.py +195 -0
  327. mollie/utils/serializers.py +249 -0
  328. mollie/utils/unmarshal_json_response.py +24 -0
  329. mollie/utils/url.py +155 -0
  330. mollie/utils/values.py +137 -0
  331. mollie/wallets.py +263 -0
  332. mollie/webhook_events.py +211 -0
  333. mollie/webhooks.py +1305 -0
  334. mollie_api_py-1.0.0.dist-info/METADATA +834 -0
  335. mollie_api_py-1.0.0.dist-info/RECORD +337 -0
  336. mollie_api_py-1.0.0.dist-info/WHEEL +4 -0
  337. mollie_api_py-1.0.0.dist-info/licenses/LICENSE.md +24 -0
@@ -0,0 +1,217 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import asyncio
4
+ import random
5
+ import time
6
+ from typing import List
7
+
8
+ import httpx
9
+
10
+
11
+ class BackoffStrategy:
12
+ initial_interval: int
13
+ max_interval: int
14
+ exponent: float
15
+ max_elapsed_time: int
16
+
17
+ def __init__(
18
+ self,
19
+ initial_interval: int,
20
+ max_interval: int,
21
+ exponent: float,
22
+ max_elapsed_time: int,
23
+ ):
24
+ self.initial_interval = initial_interval
25
+ self.max_interval = max_interval
26
+ self.exponent = exponent
27
+ self.max_elapsed_time = max_elapsed_time
28
+
29
+
30
+ class RetryConfig:
31
+ strategy: str
32
+ backoff: BackoffStrategy
33
+ retry_connection_errors: bool
34
+
35
+ def __init__(
36
+ self, strategy: str, backoff: BackoffStrategy, retry_connection_errors: bool
37
+ ):
38
+ self.strategy = strategy
39
+ self.backoff = backoff
40
+ self.retry_connection_errors = retry_connection_errors
41
+
42
+
43
+ class Retries:
44
+ config: RetryConfig
45
+ status_codes: List[str]
46
+
47
+ def __init__(self, config: RetryConfig, status_codes: List[str]):
48
+ self.config = config
49
+ self.status_codes = status_codes
50
+
51
+
52
+ class TemporaryError(Exception):
53
+ response: httpx.Response
54
+
55
+ def __init__(self, response: httpx.Response):
56
+ self.response = response
57
+
58
+
59
+ class PermanentError(Exception):
60
+ inner: Exception
61
+
62
+ def __init__(self, inner: Exception):
63
+ self.inner = inner
64
+
65
+
66
+ def retry(func, retries: Retries):
67
+ if retries.config.strategy == "backoff":
68
+
69
+ def do_request() -> httpx.Response:
70
+ res: httpx.Response
71
+ try:
72
+ res = func()
73
+
74
+ for code in retries.status_codes:
75
+ if "X" in code.upper():
76
+ code_range = int(code[0])
77
+
78
+ status_major = res.status_code / 100
79
+
80
+ if code_range <= status_major < code_range + 1:
81
+ raise TemporaryError(res)
82
+ else:
83
+ parsed_code = int(code)
84
+
85
+ if res.status_code == parsed_code:
86
+ raise TemporaryError(res)
87
+ except httpx.ConnectError as exception:
88
+ if retries.config.retry_connection_errors:
89
+ raise
90
+
91
+ raise PermanentError(exception) from exception
92
+ except httpx.TimeoutException as exception:
93
+ if retries.config.retry_connection_errors:
94
+ raise
95
+
96
+ raise PermanentError(exception) from exception
97
+ except TemporaryError:
98
+ raise
99
+ except Exception as exception:
100
+ raise PermanentError(exception) from exception
101
+
102
+ return res
103
+
104
+ return retry_with_backoff(
105
+ do_request,
106
+ retries.config.backoff.initial_interval,
107
+ retries.config.backoff.max_interval,
108
+ retries.config.backoff.exponent,
109
+ retries.config.backoff.max_elapsed_time,
110
+ )
111
+
112
+ return func()
113
+
114
+
115
+ async def retry_async(func, retries: Retries):
116
+ if retries.config.strategy == "backoff":
117
+
118
+ async def do_request() -> httpx.Response:
119
+ res: httpx.Response
120
+ try:
121
+ res = await func()
122
+
123
+ for code in retries.status_codes:
124
+ if "X" in code.upper():
125
+ code_range = int(code[0])
126
+
127
+ status_major = res.status_code / 100
128
+
129
+ if code_range <= status_major < code_range + 1:
130
+ raise TemporaryError(res)
131
+ else:
132
+ parsed_code = int(code)
133
+
134
+ if res.status_code == parsed_code:
135
+ raise TemporaryError(res)
136
+ except httpx.ConnectError as exception:
137
+ if retries.config.retry_connection_errors:
138
+ raise
139
+
140
+ raise PermanentError(exception) from exception
141
+ except httpx.TimeoutException as exception:
142
+ if retries.config.retry_connection_errors:
143
+ raise
144
+
145
+ raise PermanentError(exception) from exception
146
+ except TemporaryError:
147
+ raise
148
+ except Exception as exception:
149
+ raise PermanentError(exception) from exception
150
+
151
+ return res
152
+
153
+ return await retry_with_backoff_async(
154
+ do_request,
155
+ retries.config.backoff.initial_interval,
156
+ retries.config.backoff.max_interval,
157
+ retries.config.backoff.exponent,
158
+ retries.config.backoff.max_elapsed_time,
159
+ )
160
+
161
+ return await func()
162
+
163
+
164
+ def retry_with_backoff(
165
+ func,
166
+ initial_interval=500,
167
+ max_interval=60000,
168
+ exponent=1.5,
169
+ max_elapsed_time=3600000,
170
+ ):
171
+ start = round(time.time() * 1000)
172
+ retries = 0
173
+
174
+ while True:
175
+ try:
176
+ return func()
177
+ except PermanentError as exception:
178
+ raise exception.inner
179
+ except Exception as exception: # pylint: disable=broad-exception-caught
180
+ now = round(time.time() * 1000)
181
+ if now - start > max_elapsed_time:
182
+ if isinstance(exception, TemporaryError):
183
+ return exception.response
184
+
185
+ raise
186
+ sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
187
+ sleep = min(sleep, max_interval / 1000)
188
+ time.sleep(sleep)
189
+ retries += 1
190
+
191
+
192
+ async def retry_with_backoff_async(
193
+ func,
194
+ initial_interval=500,
195
+ max_interval=60000,
196
+ exponent=1.5,
197
+ max_elapsed_time=3600000,
198
+ ):
199
+ start = round(time.time() * 1000)
200
+ retries = 0
201
+
202
+ while True:
203
+ try:
204
+ return await func()
205
+ except PermanentError as exception:
206
+ raise exception.inner
207
+ except Exception as exception: # pylint: disable=broad-exception-caught
208
+ now = round(time.time() * 1000)
209
+ if now - start > max_elapsed_time:
210
+ if isinstance(exception, TemporaryError):
211
+ return exception.response
212
+
213
+ raise
214
+ sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
215
+ sleep = min(sleep, max_interval / 1000)
216
+ await asyncio.sleep(sleep)
217
+ retries += 1
@@ -0,0 +1,195 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import base64
4
+
5
+ from typing import (
6
+ Any,
7
+ Dict,
8
+ List,
9
+ Optional,
10
+ Tuple,
11
+ )
12
+ from pydantic import BaseModel
13
+ from pydantic.fields import FieldInfo
14
+
15
+ from .metadata import (
16
+ SecurityMetadata,
17
+ find_field_metadata,
18
+ )
19
+ import os
20
+
21
+
22
+ def get_security(security: Any) -> Tuple[Dict[str, str], Dict[str, List[str]]]:
23
+ headers: Dict[str, str] = {}
24
+ query_params: Dict[str, List[str]] = {}
25
+
26
+ if security is None:
27
+ return headers, query_params
28
+
29
+ if not isinstance(security, BaseModel):
30
+ raise TypeError("security must be a pydantic model")
31
+
32
+ sec_fields: Dict[str, FieldInfo] = security.__class__.model_fields
33
+ for name in sec_fields:
34
+ sec_field = sec_fields[name]
35
+
36
+ value = getattr(security, name)
37
+ if value is None:
38
+ continue
39
+
40
+ metadata = find_field_metadata(sec_field, SecurityMetadata)
41
+ if metadata is None:
42
+ continue
43
+ if metadata.option:
44
+ _parse_security_option(headers, query_params, value)
45
+ return headers, query_params
46
+ if metadata.scheme:
47
+ # Special case for basic auth or custom auth which could be a flattened model
48
+ if metadata.sub_type in ["basic", "custom"] and not isinstance(
49
+ value, BaseModel
50
+ ):
51
+ _parse_security_scheme(headers, query_params, metadata, name, security)
52
+ else:
53
+ _parse_security_scheme(headers, query_params, metadata, name, value)
54
+
55
+ return headers, query_params
56
+
57
+
58
+ def get_security_from_env(security: Any, security_class: Any) -> Optional[BaseModel]:
59
+ if security is not None:
60
+ return security
61
+
62
+ if not issubclass(security_class, BaseModel):
63
+ raise TypeError("security_class must be a pydantic model class")
64
+
65
+ security_dict: Any = {}
66
+
67
+ if os.getenv("CLIENT_API_KEY"):
68
+ security_dict["api_key"] = os.getenv("CLIENT_API_KEY")
69
+
70
+ if os.getenv("CLIENT_O_AUTH"):
71
+ security_dict["o_auth"] = os.getenv("CLIENT_O_AUTH")
72
+
73
+ return security_class(**security_dict) if security_dict else None
74
+
75
+
76
+ def _parse_security_option(
77
+ headers: Dict[str, str], query_params: Dict[str, List[str]], option: Any
78
+ ):
79
+ if not isinstance(option, BaseModel):
80
+ raise TypeError("security option must be a pydantic model")
81
+
82
+ opt_fields: Dict[str, FieldInfo] = option.__class__.model_fields
83
+ for name in opt_fields:
84
+ opt_field = opt_fields[name]
85
+
86
+ metadata = find_field_metadata(opt_field, SecurityMetadata)
87
+ if metadata is None or not metadata.scheme:
88
+ continue
89
+ _parse_security_scheme(
90
+ headers, query_params, metadata, name, getattr(option, name)
91
+ )
92
+
93
+
94
+ def _parse_security_scheme(
95
+ headers: Dict[str, str],
96
+ query_params: Dict[str, List[str]],
97
+ scheme_metadata: SecurityMetadata,
98
+ field_name: str,
99
+ scheme: Any,
100
+ ):
101
+ scheme_type = scheme_metadata.scheme_type
102
+ sub_type = scheme_metadata.sub_type
103
+
104
+ if isinstance(scheme, BaseModel):
105
+ if scheme_type == "http":
106
+ if sub_type == "basic":
107
+ _parse_basic_auth_scheme(headers, scheme)
108
+ return
109
+ if sub_type == "custom":
110
+ return
111
+
112
+ scheme_fields: Dict[str, FieldInfo] = scheme.__class__.model_fields
113
+ for name in scheme_fields:
114
+ scheme_field = scheme_fields[name]
115
+
116
+ metadata = find_field_metadata(scheme_field, SecurityMetadata)
117
+ if metadata is None or metadata.field_name is None:
118
+ continue
119
+
120
+ value = getattr(scheme, name)
121
+
122
+ _parse_security_scheme_value(
123
+ headers, query_params, scheme_metadata, metadata, name, value
124
+ )
125
+ else:
126
+ _parse_security_scheme_value(
127
+ headers, query_params, scheme_metadata, scheme_metadata, field_name, scheme
128
+ )
129
+
130
+
131
+ def _parse_security_scheme_value(
132
+ headers: Dict[str, str],
133
+ query_params: Dict[str, List[str]],
134
+ scheme_metadata: SecurityMetadata,
135
+ security_metadata: SecurityMetadata,
136
+ field_name: str,
137
+ value: Any,
138
+ ):
139
+ scheme_type = scheme_metadata.scheme_type
140
+ sub_type = scheme_metadata.sub_type
141
+
142
+ header_name = security_metadata.get_field_name(field_name)
143
+
144
+ if scheme_type == "apiKey":
145
+ if sub_type == "header":
146
+ headers[header_name] = value
147
+ elif sub_type == "query":
148
+ query_params[header_name] = [value]
149
+ else:
150
+ raise ValueError("sub type {sub_type} not supported")
151
+ elif scheme_type == "openIdConnect":
152
+ headers[header_name] = _apply_bearer(value)
153
+ elif scheme_type == "oauth2":
154
+ if sub_type != "client_credentials":
155
+ headers[header_name] = _apply_bearer(value)
156
+ elif scheme_type == "http":
157
+ if sub_type == "bearer":
158
+ headers[header_name] = _apply_bearer(value)
159
+ elif sub_type == "custom":
160
+ return
161
+ else:
162
+ raise ValueError("sub type {sub_type} not supported")
163
+ else:
164
+ raise ValueError("scheme type {scheme_type} not supported")
165
+
166
+
167
+ def _apply_bearer(token: str) -> str:
168
+ return token.lower().startswith("bearer ") and token or f"Bearer {token}"
169
+
170
+
171
+ def _parse_basic_auth_scheme(headers: Dict[str, str], scheme: Any):
172
+ username = ""
173
+ password = ""
174
+
175
+ if not isinstance(scheme, BaseModel):
176
+ raise TypeError("basic auth scheme must be a pydantic model")
177
+
178
+ scheme_fields: Dict[str, FieldInfo] = scheme.__class__.model_fields
179
+ for name in scheme_fields:
180
+ scheme_field = scheme_fields[name]
181
+
182
+ metadata = find_field_metadata(scheme_field, SecurityMetadata)
183
+ if metadata is None or metadata.field_name is None:
184
+ continue
185
+
186
+ field_name = metadata.field_name
187
+ value = getattr(scheme, name)
188
+
189
+ if field_name == "username":
190
+ username = value
191
+ if field_name == "password":
192
+ password = value
193
+
194
+ data = f"{username}:{password}".encode()
195
+ headers["Authorization"] = f"Basic {base64.b64encode(data).decode()}"
@@ -0,0 +1,249 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from decimal import Decimal
4
+ import functools
5
+ import json
6
+ import typing
7
+ from typing import Any, Dict, List, Tuple, Union, get_args
8
+ import typing_extensions
9
+ from typing_extensions import get_origin
10
+
11
+ import httpx
12
+ from pydantic import ConfigDict, create_model
13
+ from pydantic_core import from_json
14
+
15
+ from ..types.basemodel import BaseModel, Nullable, OptionalNullable, Unset
16
+
17
+
18
+ def serialize_decimal(as_str: bool):
19
+ def serialize(d):
20
+ # Optional[T] is a Union[T, None]
21
+ if is_union(type(d)) and type(None) in get_args(type(d)) and d is None:
22
+ return None
23
+ if isinstance(d, Unset):
24
+ return d
25
+
26
+ if not isinstance(d, Decimal):
27
+ raise ValueError("Expected Decimal object")
28
+
29
+ return str(d) if as_str else float(d)
30
+
31
+ return serialize
32
+
33
+
34
+ def validate_decimal(d):
35
+ if d is None:
36
+ return None
37
+
38
+ if isinstance(d, (Decimal, Unset)):
39
+ return d
40
+
41
+ if not isinstance(d, (str, int, float)):
42
+ raise ValueError("Expected string, int or float")
43
+
44
+ return Decimal(str(d))
45
+
46
+
47
+ def serialize_float(as_str: bool):
48
+ def serialize(f):
49
+ # Optional[T] is a Union[T, None]
50
+ if is_union(type(f)) and type(None) in get_args(type(f)) and f is None:
51
+ return None
52
+ if isinstance(f, Unset):
53
+ return f
54
+
55
+ if not isinstance(f, float):
56
+ raise ValueError("Expected float")
57
+
58
+ return str(f) if as_str else f
59
+
60
+ return serialize
61
+
62
+
63
+ def validate_float(f):
64
+ if f is None:
65
+ return None
66
+
67
+ if isinstance(f, (float, Unset)):
68
+ return f
69
+
70
+ if not isinstance(f, str):
71
+ raise ValueError("Expected string")
72
+
73
+ return float(f)
74
+
75
+
76
+ def serialize_int(as_str: bool):
77
+ def serialize(i):
78
+ # Optional[T] is a Union[T, None]
79
+ if is_union(type(i)) and type(None) in get_args(type(i)) and i is None:
80
+ return None
81
+ if isinstance(i, Unset):
82
+ return i
83
+
84
+ if not isinstance(i, int):
85
+ raise ValueError("Expected int")
86
+
87
+ return str(i) if as_str else i
88
+
89
+ return serialize
90
+
91
+
92
+ def validate_int(b):
93
+ if b is None:
94
+ return None
95
+
96
+ if isinstance(b, (int, Unset)):
97
+ return b
98
+
99
+ if not isinstance(b, str):
100
+ raise ValueError("Expected string")
101
+
102
+ return int(b)
103
+
104
+
105
+ def validate_open_enum(is_int: bool):
106
+ def validate(e):
107
+ if e is None:
108
+ return None
109
+
110
+ if isinstance(e, Unset):
111
+ return e
112
+
113
+ if is_int:
114
+ if not isinstance(e, int):
115
+ raise ValueError("Expected int")
116
+ else:
117
+ if not isinstance(e, str):
118
+ raise ValueError("Expected string")
119
+
120
+ return e
121
+
122
+ return validate
123
+
124
+
125
+ def validate_const(v):
126
+ def validate(c):
127
+ # Optional[T] is a Union[T, None]
128
+ if is_union(type(c)) and type(None) in get_args(type(c)) and c is None:
129
+ return None
130
+
131
+ if v != c:
132
+ raise ValueError(f"Expected {v}")
133
+
134
+ return c
135
+
136
+ return validate
137
+
138
+
139
+ def unmarshal_json(raw, typ: Any) -> Any:
140
+ return unmarshal(from_json(raw), typ)
141
+
142
+
143
+ def unmarshal(val, typ: Any) -> Any:
144
+ unmarshaller = create_model(
145
+ "Unmarshaller",
146
+ body=(typ, ...),
147
+ __config__=ConfigDict(populate_by_name=True, arbitrary_types_allowed=True),
148
+ )
149
+
150
+ m = unmarshaller(body=val)
151
+
152
+ # pyright: ignore[reportAttributeAccessIssue]
153
+ return m.body # type: ignore
154
+
155
+
156
+ def marshal_json(val, typ):
157
+ if is_nullable(typ) and val is None:
158
+ return "null"
159
+
160
+ marshaller = create_model(
161
+ "Marshaller",
162
+ body=(typ, ...),
163
+ __config__=ConfigDict(populate_by_name=True, arbitrary_types_allowed=True),
164
+ )
165
+
166
+ m = marshaller(body=val)
167
+
168
+ d = m.model_dump(by_alias=True, mode="json", exclude_none=True)
169
+
170
+ if len(d) == 0:
171
+ return ""
172
+
173
+ return json.dumps(d[next(iter(d))], separators=(",", ":"))
174
+
175
+
176
+ def is_nullable(field):
177
+ origin = get_origin(field)
178
+ if origin is Nullable or origin is OptionalNullable:
179
+ return True
180
+
181
+ if not origin is Union or type(None) not in get_args(field):
182
+ return False
183
+
184
+ for arg in get_args(field):
185
+ if get_origin(arg) is Nullable or get_origin(arg) is OptionalNullable:
186
+ return True
187
+
188
+ return False
189
+
190
+
191
+ def is_union(obj: object) -> bool:
192
+ """
193
+ Returns True if the given object is a typing.Union or typing_extensions.Union.
194
+ """
195
+ return any(
196
+ obj is typing_obj for typing_obj in _get_typing_objects_by_name_of("Union")
197
+ )
198
+
199
+
200
+ def stream_to_text(stream: httpx.Response) -> str:
201
+ return "".join(stream.iter_text())
202
+
203
+
204
+ async def stream_to_text_async(stream: httpx.Response) -> str:
205
+ return "".join([chunk async for chunk in stream.aiter_text()])
206
+
207
+
208
+ def stream_to_bytes(stream: httpx.Response) -> bytes:
209
+ return stream.content
210
+
211
+
212
+ async def stream_to_bytes_async(stream: httpx.Response) -> bytes:
213
+ return await stream.aread()
214
+
215
+
216
+ def get_pydantic_model(data: Any, typ: Any) -> Any:
217
+ if not _contains_pydantic_model(data):
218
+ return unmarshal(data, typ)
219
+
220
+ return data
221
+
222
+
223
+ def _contains_pydantic_model(data: Any) -> bool:
224
+ if isinstance(data, BaseModel):
225
+ return True
226
+ if isinstance(data, List):
227
+ return any(_contains_pydantic_model(item) for item in data)
228
+ if isinstance(data, Dict):
229
+ return any(_contains_pydantic_model(value) for value in data.values())
230
+
231
+ return False
232
+
233
+
234
+ @functools.cache
235
+ def _get_typing_objects_by_name_of(name: str) -> Tuple[Any, ...]:
236
+ """
237
+ Get typing objects by name from typing and typing_extensions.
238
+ Reference: https://typing-extensions.readthedocs.io/en/latest/#runtime-use-of-types
239
+ """
240
+ result = tuple(
241
+ getattr(module, name)
242
+ for module in (typing, typing_extensions)
243
+ if hasattr(module, name)
244
+ )
245
+ if not result:
246
+ raise ValueError(
247
+ f"Neither typing nor typing_extensions has an object called {name!r}"
248
+ )
249
+ return result
@@ -0,0 +1,24 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from typing import Any, Optional
4
+
5
+ import httpx
6
+
7
+ from .serializers import unmarshal_json
8
+ from mollie import models
9
+
10
+
11
+ def unmarshal_json_response(
12
+ typ: Any, http_res: httpx.Response, body: Optional[str] = None
13
+ ) -> Any:
14
+ if body is None:
15
+ body = http_res.text
16
+ try:
17
+ return unmarshal_json(body, typ)
18
+ except Exception as e:
19
+ raise models.ResponseValidationError(
20
+ "Response validation failed",
21
+ http_res,
22
+ e,
23
+ body,
24
+ ) from e