yoonpay 0.1.0__tar.gz

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 (75) hide show
  1. yoonpay-0.1.0/.gitignore +7 -0
  2. yoonpay-0.1.0/CHANGELOG.md +9 -0
  3. yoonpay-0.1.0/LICENSE +202 -0
  4. yoonpay-0.1.0/PKG-INFO +197 -0
  5. yoonpay-0.1.0/README.md +165 -0
  6. yoonpay-0.1.0/e2e/run.py +128 -0
  7. yoonpay-0.1.0/generated/yoonpay/generated/__init__.py +134 -0
  8. yoonpay-0.1.0/generated/yoonpay/generated/api/__init__.py +11 -0
  9. yoonpay-0.1.0/generated/yoonpay/generated/api/events_api.py +937 -0
  10. yoonpay-0.1.0/generated/yoonpay/generated/api/exports_api.py +1219 -0
  11. yoonpay-0.1.0/generated/yoonpay/generated/api/ledger_api.py +640 -0
  12. yoonpay-0.1.0/generated/yoonpay/generated/api/meta_api.py +530 -0
  13. yoonpay-0.1.0/generated/yoonpay/generated/api/payments_api.py +1296 -0
  14. yoonpay-0.1.0/generated/yoonpay/generated/api/payouts_api.py +1210 -0
  15. yoonpay-0.1.0/generated/yoonpay/generated/api/refunds_api.py +1459 -0
  16. yoonpay-0.1.0/generated/yoonpay/generated/api_client.py +804 -0
  17. yoonpay-0.1.0/generated/yoonpay/generated/api_response.py +21 -0
  18. yoonpay-0.1.0/generated/yoonpay/generated/configuration.py +589 -0
  19. yoonpay-0.1.0/generated/yoonpay/generated/exceptions.py +216 -0
  20. yoonpay-0.1.0/generated/yoonpay/generated/models/__init__.py +53 -0
  21. yoonpay-0.1.0/generated/yoonpay/generated/models/admin_replay_dead_letter202_response.py +96 -0
  22. yoonpay-0.1.0/generated/yoonpay/generated/models/admin_resolve_payout_request.py +97 -0
  23. yoonpay-0.1.0/generated/yoonpay/generated/models/create_payment_request.py +122 -0
  24. yoonpay-0.1.0/generated/yoonpay/generated/models/create_payment_request_customer.py +90 -0
  25. yoonpay-0.1.0/generated/yoonpay/generated/models/create_payout_request.py +118 -0
  26. yoonpay-0.1.0/generated/yoonpay/generated/models/create_payout_request_recipient.py +90 -0
  27. yoonpay-0.1.0/generated/yoonpay/generated/models/create_refund_request.py +90 -0
  28. yoonpay-0.1.0/generated/yoonpay/generated/models/delivery_status.py +48 -0
  29. yoonpay-0.1.0/generated/yoonpay/generated/models/event.py +125 -0
  30. yoonpay-0.1.0/generated/yoonpay/generated/models/event_delivery.py +119 -0
  31. yoonpay-0.1.0/generated/yoonpay/generated/models/event_page.py +104 -0
  32. yoonpay-0.1.0/generated/yoonpay/generated/models/event_payload.py +108 -0
  33. yoonpay-0.1.0/generated/yoonpay/generated/models/event_payload_data.py +91 -0
  34. yoonpay-0.1.0/generated/yoonpay/generated/models/event_payload_data_object.py +151 -0
  35. yoonpay-0.1.0/generated/yoonpay/generated/models/event_type.py +52 -0
  36. yoonpay-0.1.0/generated/yoonpay/generated/models/failure.py +89 -0
  37. yoonpay-0.1.0/generated/yoonpay/generated/models/get_about200_response.py +93 -0
  38. yoonpay-0.1.0/generated/yoonpay/generated/models/get_balances200_response.py +106 -0
  39. yoonpay-0.1.0/generated/yoonpay/generated/models/get_balances200_response_data_inner.py +93 -0
  40. yoonpay-0.1.0/generated/yoonpay/generated/models/ledger_entry.py +100 -0
  41. yoonpay-0.1.0/generated/yoonpay/generated/models/ledger_entry_page.py +104 -0
  42. yoonpay-0.1.0/generated/yoonpay/generated/models/list_providers200_response_inner.py +101 -0
  43. yoonpay-0.1.0/generated/yoonpay/generated/models/list_providers200_response_inner_capabilities_inner.py +100 -0
  44. yoonpay-0.1.0/generated/yoonpay/generated/models/payment.py +175 -0
  45. yoonpay-0.1.0/generated/yoonpay/generated/models/payment_customer.py +92 -0
  46. yoonpay-0.1.0/generated/yoonpay/generated/models/payment_page.py +104 -0
  47. yoonpay-0.1.0/generated/yoonpay/generated/models/payment_status.py +49 -0
  48. yoonpay-0.1.0/generated/yoonpay/generated/models/payout.py +149 -0
  49. yoonpay-0.1.0/generated/yoonpay/generated/models/payout_page.py +104 -0
  50. yoonpay-0.1.0/generated/yoonpay/generated/models/payout_recipient.py +92 -0
  51. yoonpay-0.1.0/generated/yoonpay/generated/models/payout_status.py +49 -0
  52. yoonpay-0.1.0/generated/yoonpay/generated/models/problem.py +97 -0
  53. yoonpay-0.1.0/generated/yoonpay/generated/models/receive_provider_callback200_response.py +87 -0
  54. yoonpay-0.1.0/generated/yoonpay/generated/models/refund.py +132 -0
  55. yoonpay-0.1.0/generated/yoonpay/generated/models/refund_page.py +104 -0
  56. yoonpay-0.1.0/generated/yoonpay/generated/models/refund_status.py +49 -0
  57. yoonpay-0.1.0/generated/yoonpay/generated/models/status_event.py +129 -0
  58. yoonpay-0.1.0/generated/yoonpay/generated/py.typed +0 -0
  59. yoonpay-0.1.0/generated/yoonpay/generated/rest.py +258 -0
  60. yoonpay-0.1.0/pyproject.toml +53 -0
  61. yoonpay-0.1.0/src/yoonpay/__init__.py +38 -0
  62. yoonpay-0.1.0/src/yoonpay/_version.py +2 -0
  63. yoonpay-0.1.0/src/yoonpay/client.py +210 -0
  64. yoonpay-0.1.0/src/yoonpay/django.py +73 -0
  65. yoonpay-0.1.0/src/yoonpay/errors.py +68 -0
  66. yoonpay-0.1.0/src/yoonpay/fastapi.py +67 -0
  67. yoonpay-0.1.0/src/yoonpay/flask.py +67 -0
  68. yoonpay-0.1.0/src/yoonpay/py.typed +0 -0
  69. yoonpay-0.1.0/src/yoonpay/webhook.py +181 -0
  70. yoonpay-0.1.0/tests/conftest.py +24 -0
  71. yoonpay-0.1.0/tests/test_client.py +283 -0
  72. yoonpay-0.1.0/tests/test_django.py +98 -0
  73. yoonpay-0.1.0/tests/test_fastapi.py +82 -0
  74. yoonpay-0.1.0/tests/test_flask.py +69 -0
  75. yoonpay-0.1.0/tests/test_webhook_signature.py +65 -0
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-10-01
4
+
5
+ - First release of the Python client: `Yoon` with `create_payment`, `get_payment`, `refund`,
6
+ `create_payout` and `export_csv` (explicit idempotency key on every write, no retries,
7
+ `YoonException` with Yoon's problem `code`), the generated API objects for everything else,
8
+ webhook signature verification (`verify_signature`, `Event`), and webhook helpers for Django
9
+ (`yoonpay.django`), FastAPI (`yoonpay.fastapi`) and Flask (`yoonpay.flask`).
yoonpay-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
yoonpay-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,197 @@
1
+ Metadata-Version: 2.5
2
+ Name: yoonpay
3
+ Version: 0.1.0
4
+ Summary: Python client for Yoon, a self-hosted payment gateway for African payment providers, with Django, FastAPI and Flask helpers.
5
+ Project-URL: Homepage, https://github.com/crossben/yoonpay
6
+ Project-URL: Source, https://github.com/crossben/yoonpay/tree/main/clients/python
7
+ Project-URL: Issues, https://github.com/crossben/yoonpay/issues
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: dexpay,naboopay,orange-money,paydunya,payments,senegal,wave,xof,yoon
11
+ Classifier: Framework :: Django
12
+ Classifier: Framework :: FastAPI
13
+ Classifier: Framework :: Flask
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: pydantic>=2.0
18
+ Requires-Dist: python-dateutil>=2.8.2
19
+ Requires-Dist: typing-extensions>=4.7.1
20
+ Requires-Dist: urllib3<3.0.0,>=2.1.0
21
+ Provides-Extra: django
22
+ Requires-Dist: django>=4.2; extra == 'django'
23
+ Provides-Extra: fastapi
24
+ Requires-Dist: fastapi>=0.100; extra == 'fastapi'
25
+ Provides-Extra: flask
26
+ Requires-Dist: flask>=2.3; extra == 'flask'
27
+ Provides-Extra: test
28
+ Requires-Dist: httpx>=0.24; extra == 'test'
29
+ Requires-Dist: pytest-httpserver>=1.0; extra == 'test'
30
+ Requires-Dist: pytest>=8; extra == 'test'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # yoonpay
34
+
35
+ Python client for [Yoon](https://github.com/crossben/yoonpay), a self-hosted payment gateway
36
+ for African payment providers, with Django, FastAPI and Flask helpers. Apache-2.0.
37
+
38
+ Requires Python 3.10+. Synchronous (urllib3); there is no async client yet.
39
+
40
+ ```sh
41
+ pip install yoonpay # the client
42
+ pip install "yoonpay[django]" # or [fastapi], [flask]: the framework is an optional extra
43
+ ```
44
+
45
+ ## Plain Python
46
+
47
+ ```python
48
+ import os
49
+ from yoonpay import Yoon, YoonException
50
+
51
+ yoon = Yoon("https://pay.example.com", os.environ["YOON_API_KEY"]) # timeout=30, connect_timeout=5
52
+
53
+ try:
54
+ payment = yoon.create_payment(
55
+ {
56
+ "amount": 5000, # XOF has no minor unit: 5 000 FCFA
57
+ "currency": "XOF",
58
+ "country": "SN",
59
+ "method": "wave", # wave, orange_money, free_money, card
60
+ "customer": {"phone": "+221771234567"},
61
+ "reference": "order_1042",
62
+ "return_url": "https://shop.example/orders/1042",
63
+ },
64
+ idempotency_key="order-1042", # tie it to your order: a retry can never charge twice
65
+ )
66
+ redirect_to = payment.checkout_url
67
+ except YoonException as e:
68
+ e.problem_code # e.g. no_provider_for_method, refund_exceeds_payment
69
+ e.is_retryable() # True: retry with the same idempotency key
70
+ ```
71
+
72
+ Helpers: `create_payment`, `get_payment`, `refund(payment_id, idempotency_key, amount=None,
73
+ reason=None)`, `create_payout`, `export_csv("payments" | "refunds" | "payouts" | "ledger",
74
+ from_=None, to=None)`. Every other operation of the API is on the generated API objects —
75
+ `yoon.payments()`, `.refunds()`, `.payouts()`, `.events()`, `.ledger()`, `.meta()` — wrapped
76
+ with `yoon.call(lambda: …)` to turn errors into `YoonException`:
77
+
78
+ ```python
79
+ page = yoon.call(lambda: yoon.payments().list_payments(reference="order_1042"))
80
+ ```
81
+
82
+ The idempotency key is a required argument of every write: the client never makes one up and
83
+ never retries on its own (urllib3's retries are switched off). Retrying is your decision, with
84
+ the same key.
85
+
86
+ ## Django
87
+
88
+ ```python
89
+ # settings.py
90
+ YOON_WEBHOOK_SECRET = os.environ["YOON_WEBHOOK_SECRET"] # YOON_APPS_<APP>_WEBHOOK_SECRET on the Yoon side
91
+ # optional: YOON_WEBHOOK_CACHE = "default", YOON_WEBHOOK_DEDUPE_SECONDS = 259200
92
+
93
+ # views.py
94
+ from django.http import HttpResponse
95
+ from yoonpay.django import yoon_webhook
96
+
97
+ @yoon_webhook
98
+ def yoon_events(request, event):
99
+ if event.type == "payment.succeeded":
100
+ Order.objects.filter(yoon_payment_id=event.object["id"]).update(status="paid")
101
+ return HttpResponse(status=204)
102
+
103
+ # urls.py
104
+ urlpatterns = [path("yoon/webhook", yoon_events)]
105
+ ```
106
+
107
+ The decorator exempts the view from CSRF, accepts only POST, and remembers handled event ids in
108
+ Django's cache (use a shared backend such as Redis when you run several servers).
109
+
110
+ ## FastAPI
111
+
112
+ ```python
113
+ import os
114
+ from fastapi import APIRouter, Depends, FastAPI
115
+ from yoonpay import Event
116
+ from yoonpay.fastapi import yoon_event, yoon_webhook_route
117
+
118
+ webhooks = APIRouter(route_class=yoon_webhook_route(secret=os.environ["YOON_WEBHOOK_SECRET"]))
119
+
120
+ @webhooks.post("/yoon/webhook", status_code=204)
121
+ def yoon_events(event: Event = Depends(yoon_event)) -> None:
122
+ if event.type == "payment.succeeded":
123
+ ...
124
+
125
+ app = FastAPI()
126
+ app.include_router(webhooks)
127
+ ```
128
+
129
+ Only the routes of that router are checked. The default id store is in-process; with several
130
+ workers pass `store=CacheEventStore(shared_cache)`.
131
+
132
+ ## Flask
133
+
134
+ ```python
135
+ from yoonpay.flask import yoon_webhook
136
+
137
+ app.config["YOON_WEBHOOK_SECRET"] = os.environ["YOON_WEBHOOK_SECRET"]
138
+
139
+ @app.post("/yoon/webhook")
140
+ @yoon_webhook
141
+ def yoon_events(event):
142
+ if event.type == "payment.succeeded":
143
+ ...
144
+ return "", 204
145
+ ```
146
+
147
+ The default id store is in-process, per app; with several workers pass
148
+ `@yoon_webhook(store=CacheEventStore(cache))`, e.g. over Flask-Caching.
149
+
150
+ ## Webhooks
151
+
152
+ All three helpers behave the same: a wrong or stale signature (more than 300 s off) gets 401
153
+ without reaching your code, an already-handled event gets 200 without reaching your code, and an
154
+ event id is remembered only after your code answered 2xx — if it fails or raises, Yoon's retry
155
+ reaches it again. Events are unordered and may arrive more than once: act on the state in
156
+ `event.object`, not on arrival order.
157
+
158
+ **Raw body.** The signature covers the bytes Yoon sent. The helpers read the raw body
159
+ (`request.body` in Django, `await request.body()` in FastAPI, `request.get_data()` in Flask);
160
+ if you verify by hand, do the same — a body parsed and re-encoded as JSON no longer matches
161
+ and is rejected.
162
+
163
+ Outside these frameworks:
164
+
165
+ ```python
166
+ from yoonpay import Event, verify_signature
167
+
168
+ if not verify_signature(secret, headers.get("Yoon-Signature"), raw_body):
169
+ ... # answer 401
170
+ event = Event.from_json(raw_body) # event.id, event.type, event.object
171
+ ```
172
+
173
+ `sign_signature(secret, raw_body)` builds a header for your own tests.
174
+
175
+ ## Errors
176
+
177
+ `YoonException` carries `http_status` (`None` when Yoon was not reached), `problem_code` (Yoon's
178
+ stable `code`, `None` when Yoon was not reached), `problem` (the full problem document) and
179
+ `is_retryable()` — true when Yoon was unreachable, busy (`idempotency_in_progress`) or failing
180
+ (5xx). A 2xx answer the client cannot read gets `problem_code = "unreadable_response"` and is
181
+ **not** retryable: the call may have worked, look it up first. The API key never appears in
182
+ errors or in `repr(yoon)`.
183
+
184
+ A status or event type added by a newer Yoon server does not break parsing: the value is kept
185
+ as a string (`payment.status == "new_status"`).
186
+
187
+ ## Layout
188
+
189
+ - `generated/` — generated from `api/openapi.yaml` by `clients/generate.sh` (the package
190
+ `yoonpay.generated`). Never edit by hand; CI fails if it drifts from the contract.
191
+ - `src/yoonpay/` — the hand-written layer: `Yoon`, `YoonException`, webhook helpers, framework
192
+ integrations.
193
+ - `e2e/run.py` — the shared end-to-end scenario (`clients/e2e/scenario.md`) against a real server.
194
+
195
+ ```sh
196
+ pip install -e ".[django,fastapi,flask,test]" && pytest
197
+ ```
@@ -0,0 +1,165 @@
1
+ # yoonpay
2
+
3
+ Python client for [Yoon](https://github.com/crossben/yoonpay), a self-hosted payment gateway
4
+ for African payment providers, with Django, FastAPI and Flask helpers. Apache-2.0.
5
+
6
+ Requires Python 3.10+. Synchronous (urllib3); there is no async client yet.
7
+
8
+ ```sh
9
+ pip install yoonpay # the client
10
+ pip install "yoonpay[django]" # or [fastapi], [flask]: the framework is an optional extra
11
+ ```
12
+
13
+ ## Plain Python
14
+
15
+ ```python
16
+ import os
17
+ from yoonpay import Yoon, YoonException
18
+
19
+ yoon = Yoon("https://pay.example.com", os.environ["YOON_API_KEY"]) # timeout=30, connect_timeout=5
20
+
21
+ try:
22
+ payment = yoon.create_payment(
23
+ {
24
+ "amount": 5000, # XOF has no minor unit: 5 000 FCFA
25
+ "currency": "XOF",
26
+ "country": "SN",
27
+ "method": "wave", # wave, orange_money, free_money, card
28
+ "customer": {"phone": "+221771234567"},
29
+ "reference": "order_1042",
30
+ "return_url": "https://shop.example/orders/1042",
31
+ },
32
+ idempotency_key="order-1042", # tie it to your order: a retry can never charge twice
33
+ )
34
+ redirect_to = payment.checkout_url
35
+ except YoonException as e:
36
+ e.problem_code # e.g. no_provider_for_method, refund_exceeds_payment
37
+ e.is_retryable() # True: retry with the same idempotency key
38
+ ```
39
+
40
+ Helpers: `create_payment`, `get_payment`, `refund(payment_id, idempotency_key, amount=None,
41
+ reason=None)`, `create_payout`, `export_csv("payments" | "refunds" | "payouts" | "ledger",
42
+ from_=None, to=None)`. Every other operation of the API is on the generated API objects —
43
+ `yoon.payments()`, `.refunds()`, `.payouts()`, `.events()`, `.ledger()`, `.meta()` — wrapped
44
+ with `yoon.call(lambda: …)` to turn errors into `YoonException`:
45
+
46
+ ```python
47
+ page = yoon.call(lambda: yoon.payments().list_payments(reference="order_1042"))
48
+ ```
49
+
50
+ The idempotency key is a required argument of every write: the client never makes one up and
51
+ never retries on its own (urllib3's retries are switched off). Retrying is your decision, with
52
+ the same key.
53
+
54
+ ## Django
55
+
56
+ ```python
57
+ # settings.py
58
+ YOON_WEBHOOK_SECRET = os.environ["YOON_WEBHOOK_SECRET"] # YOON_APPS_<APP>_WEBHOOK_SECRET on the Yoon side
59
+ # optional: YOON_WEBHOOK_CACHE = "default", YOON_WEBHOOK_DEDUPE_SECONDS = 259200
60
+
61
+ # views.py
62
+ from django.http import HttpResponse
63
+ from yoonpay.django import yoon_webhook
64
+
65
+ @yoon_webhook
66
+ def yoon_events(request, event):
67
+ if event.type == "payment.succeeded":
68
+ Order.objects.filter(yoon_payment_id=event.object["id"]).update(status="paid")
69
+ return HttpResponse(status=204)
70
+
71
+ # urls.py
72
+ urlpatterns = [path("yoon/webhook", yoon_events)]
73
+ ```
74
+
75
+ The decorator exempts the view from CSRF, accepts only POST, and remembers handled event ids in
76
+ Django's cache (use a shared backend such as Redis when you run several servers).
77
+
78
+ ## FastAPI
79
+
80
+ ```python
81
+ import os
82
+ from fastapi import APIRouter, Depends, FastAPI
83
+ from yoonpay import Event
84
+ from yoonpay.fastapi import yoon_event, yoon_webhook_route
85
+
86
+ webhooks = APIRouter(route_class=yoon_webhook_route(secret=os.environ["YOON_WEBHOOK_SECRET"]))
87
+
88
+ @webhooks.post("/yoon/webhook", status_code=204)
89
+ def yoon_events(event: Event = Depends(yoon_event)) -> None:
90
+ if event.type == "payment.succeeded":
91
+ ...
92
+
93
+ app = FastAPI()
94
+ app.include_router(webhooks)
95
+ ```
96
+
97
+ Only the routes of that router are checked. The default id store is in-process; with several
98
+ workers pass `store=CacheEventStore(shared_cache)`.
99
+
100
+ ## Flask
101
+
102
+ ```python
103
+ from yoonpay.flask import yoon_webhook
104
+
105
+ app.config["YOON_WEBHOOK_SECRET"] = os.environ["YOON_WEBHOOK_SECRET"]
106
+
107
+ @app.post("/yoon/webhook")
108
+ @yoon_webhook
109
+ def yoon_events(event):
110
+ if event.type == "payment.succeeded":
111
+ ...
112
+ return "", 204
113
+ ```
114
+
115
+ The default id store is in-process, per app; with several workers pass
116
+ `@yoon_webhook(store=CacheEventStore(cache))`, e.g. over Flask-Caching.
117
+
118
+ ## Webhooks
119
+
120
+ All three helpers behave the same: a wrong or stale signature (more than 300 s off) gets 401
121
+ without reaching your code, an already-handled event gets 200 without reaching your code, and an
122
+ event id is remembered only after your code answered 2xx — if it fails or raises, Yoon's retry
123
+ reaches it again. Events are unordered and may arrive more than once: act on the state in
124
+ `event.object`, not on arrival order.
125
+
126
+ **Raw body.** The signature covers the bytes Yoon sent. The helpers read the raw body
127
+ (`request.body` in Django, `await request.body()` in FastAPI, `request.get_data()` in Flask);
128
+ if you verify by hand, do the same — a body parsed and re-encoded as JSON no longer matches
129
+ and is rejected.
130
+
131
+ Outside these frameworks:
132
+
133
+ ```python
134
+ from yoonpay import Event, verify_signature
135
+
136
+ if not verify_signature(secret, headers.get("Yoon-Signature"), raw_body):
137
+ ... # answer 401
138
+ event = Event.from_json(raw_body) # event.id, event.type, event.object
139
+ ```
140
+
141
+ `sign_signature(secret, raw_body)` builds a header for your own tests.
142
+
143
+ ## Errors
144
+
145
+ `YoonException` carries `http_status` (`None` when Yoon was not reached), `problem_code` (Yoon's
146
+ stable `code`, `None` when Yoon was not reached), `problem` (the full problem document) and
147
+ `is_retryable()` — true when Yoon was unreachable, busy (`idempotency_in_progress`) or failing
148
+ (5xx). A 2xx answer the client cannot read gets `problem_code = "unreadable_response"` and is
149
+ **not** retryable: the call may have worked, look it up first. The API key never appears in
150
+ errors or in `repr(yoon)`.
151
+
152
+ A status or event type added by a newer Yoon server does not break parsing: the value is kept
153
+ as a string (`payment.status == "new_status"`).
154
+
155
+ ## Layout
156
+
157
+ - `generated/` — generated from `api/openapi.yaml` by `clients/generate.sh` (the package
158
+ `yoonpay.generated`). Never edit by hand; CI fails if it drifts from the contract.
159
+ - `src/yoonpay/` — the hand-written layer: `Yoon`, `YoonException`, webhook helpers, framework
160
+ integrations.
161
+ - `e2e/run.py` — the shared end-to-end scenario (`clients/e2e/scenario.md`) against a real server.
162
+
163
+ ```sh
164
+ pip install -e ".[django,fastapi,flask,test]" && pytest
165
+ ```