keble-payment 2.4.1__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 (179) hide show
  1. keble_payment-2.4.1/.gitattributes +2 -0
  2. keble_payment-2.4.1/.gitignore +163 -0
  3. keble_payment-2.4.1/.python-version +1 -0
  4. keble_payment-2.4.1/AGENTS.md +24 -0
  5. keble_payment-2.4.1/AiAgentChangesLogs.md +160 -0
  6. keble_payment-2.4.1/CLAUDE.md +24 -0
  7. keble_payment-2.4.1/PKG-INFO +132 -0
  8. keble_payment-2.4.1/README.md +119 -0
  9. keble_payment-2.4.1/deps/keble_typing-0.3.17-py3-none-any.whl +0 -0
  10. keble_payment-2.4.1/docs/testing.md +135 -0
  11. keble_payment-2.4.1/keble.2.3.0.README.improved.md +744 -0
  12. keble_payment-2.4.1/keble_payment/__init__.py +5 -0
  13. keble_payment-2.4.1/keble_payment/alipay/__init__.py +1 -0
  14. keble_payment-2.4.1/keble_payment/alipay/client.py +199 -0
  15. keble_payment-2.4.1/keble_payment/crud/__init__.py +14 -0
  16. keble_payment-2.4.1/keble_payment/crud/alipay.py +27 -0
  17. keble_payment-2.4.1/keble_payment/crud/bank_transaction.py +27 -0
  18. keble_payment-2.4.1/keble_payment/crud/coupon.py +254 -0
  19. keble_payment-2.4.1/keble_payment/crud/coupon_history.py +297 -0
  20. keble_payment-2.4.1/keble_payment/crud/order.py +20 -0
  21. keble_payment-2.4.1/keble_payment/crud/payment.py +35 -0
  22. keble_payment-2.4.1/keble_payment/crud/paypal_payout.py +416 -0
  23. keble_payment-2.4.1/keble_payment/crud/stripe_card.py +140 -0
  24. keble_payment-2.4.1/keble_payment/crud/stripe_checkout_session.py +247 -0
  25. keble_payment-2.4.1/keble_payment/crud/stripe_customer.py +135 -0
  26. keble_payment-2.4.1/keble_payment/crud/stripe_invoice.py +221 -0
  27. keble_payment-2.4.1/keble_payment/crud/stripe_payment_intent.py +252 -0
  28. keble_payment-2.4.1/keble_payment/crud/stripe_payment_method.py +180 -0
  29. keble_payment-2.4.1/keble_payment/crud/stripe_subscription.py +430 -0
  30. keble_payment-2.4.1/keble_payment/main/__init__.py +29 -0
  31. keble_payment-2.4.1/keble_payment/main/base.py +141 -0
  32. keble_payment-2.4.1/keble_payment/main/client.py +131 -0
  33. keble_payment-2.4.1/keble_payment/main/coupon.py +298 -0
  34. keble_payment-2.4.1/keble_payment/main/order.py +3252 -0
  35. keble_payment-2.4.1/keble_payment/main/paypal_webhook_handler.py +366 -0
  36. keble_payment-2.4.1/keble_payment/main/stripe_webhook_handler.py +348 -0
  37. keble_payment-2.4.1/keble_payment/main/utils.py +126 -0
  38. keble_payment-2.4.1/keble_payment/paypal/__init__.py +24 -0
  39. keble_payment-2.4.1/keble_payment/paypal/api/__init__.py +9 -0
  40. keble_payment-2.4.1/keble_payment/paypal/api/base.py +19 -0
  41. keble_payment-2.4.1/keble_payment/paypal/api/payout.py +163 -0
  42. keble_payment-2.4.1/keble_payment/paypal/client.py +361 -0
  43. keble_payment-2.4.1/keble_payment/paypal/config.py +54 -0
  44. keble_payment-2.4.1/keble_payment/paypal/enum.py +148 -0
  45. keble_payment-2.4.1/keble_payment/paypal/schemas/__init__.py +45 -0
  46. keble_payment-2.4.1/keble_payment/paypal/schemas/payout.py +603 -0
  47. keble_payment-2.4.1/keble_payment/paypal/schemas/webhook.py +21 -0
  48. keble_payment-2.4.1/keble_payment/paypal/utils.py +21 -0
  49. keble_payment-2.4.1/keble_payment/protocols.py +26 -0
  50. keble_payment-2.4.1/keble_payment/schemas/__init__.py +100 -0
  51. keble_payment-2.4.1/keble_payment/schemas/alipay.py +51 -0
  52. keble_payment-2.4.1/keble_payment/schemas/bank_transaction.py +26 -0
  53. keble_payment-2.4.1/keble_payment/schemas/base.py +15 -0
  54. keble_payment-2.4.1/keble_payment/schemas/coupon.py +182 -0
  55. keble_payment-2.4.1/keble_payment/schemas/coupon_attribution.py +378 -0
  56. keble_payment-2.4.1/keble_payment/schemas/coupon_history.py +40 -0
  57. keble_payment-2.4.1/keble_payment/schemas/enum.py +118 -0
  58. keble_payment-2.4.1/keble_payment/schemas/order.py +168 -0
  59. keble_payment-2.4.1/keble_payment/schemas/payment.py +34 -0
  60. keble_payment-2.4.1/keble_payment/schemas/paypal_payout.py +162 -0
  61. keble_payment-2.4.1/keble_payment/schemas/stripe_card.py +66 -0
  62. keble_payment-2.4.1/keble_payment/schemas/stripe_charge.py +89 -0
  63. keble_payment-2.4.1/keble_payment/schemas/stripe_checkout_session.py +99 -0
  64. keble_payment-2.4.1/keble_payment/schemas/stripe_customer.py +63 -0
  65. keble_payment-2.4.1/keble_payment/schemas/stripe_invoice.py +463 -0
  66. keble_payment-2.4.1/keble_payment/schemas/stripe_payment_intent.py +160 -0
  67. keble_payment-2.4.1/keble_payment/schemas/stripe_payment_method.py +70 -0
  68. keble_payment-2.4.1/keble_payment/schemas/stripe_subscription.py +168 -0
  69. keble_payment-2.4.1/keble_payment/stripe/__init__.py +1 -0
  70. keble_payment-2.4.1/keble_payment/stripe/api/__init__.py +45 -0
  71. keble_payment-2.4.1/keble_payment/stripe/api/base.py +41 -0
  72. keble_payment-2.4.1/keble_payment/stripe/api/billing_portal_session.py +37 -0
  73. keble_payment-2.4.1/keble_payment/stripe/api/charge.py +60 -0
  74. keble_payment-2.4.1/keble_payment/stripe/api/checkout_session.py +107 -0
  75. keble_payment-2.4.1/keble_payment/stripe/api/customer.py +92 -0
  76. keble_payment-2.4.1/keble_payment/stripe/api/event.py +43 -0
  77. keble_payment-2.4.1/keble_payment/stripe/api/invoice.py +174 -0
  78. keble_payment-2.4.1/keble_payment/stripe/api/payment_intent.py +190 -0
  79. keble_payment-2.4.1/keble_payment/stripe/api/payment_methods.py +200 -0
  80. keble_payment-2.4.1/keble_payment/stripe/api/portal_configuration.py +104 -0
  81. keble_payment-2.4.1/keble_payment/stripe/api/price.py +212 -0
  82. keble_payment-2.4.1/keble_payment/stripe/api/refund.py +98 -0
  83. keble_payment-2.4.1/keble_payment/stripe/api/setup_intent.py +182 -0
  84. keble_payment-2.4.1/keble_payment/stripe/api/subscription.py +222 -0
  85. keble_payment-2.4.1/keble_payment/stripe/api/subscription_schedule.py +192 -0
  86. keble_payment-2.4.1/keble_payment/stripe/api/transfer.py +118 -0
  87. keble_payment-2.4.1/keble_payment/stripe/config.py +21 -0
  88. keble_payment-2.4.1/keble_payment/stripe/enum.py +770 -0
  89. keble_payment-2.4.1/keble_payment/stripe/exceptions/__init__.py +1 -0
  90. keble_payment-2.4.1/keble_payment/stripe/exceptions/utils.py +2 -0
  91. keble_payment-2.4.1/keble_payment/stripe/schemas/__init__.py +255 -0
  92. keble_payment-2.4.1/keble_payment/stripe/schemas/address.py +27 -0
  93. keble_payment-2.4.1/keble_payment/stripe/schemas/amount.py +9 -0
  94. keble_payment-2.4.1/keble_payment/stripe/schemas/balance_transaction.py +91 -0
  95. keble_payment-2.4.1/keble_payment/stripe/schemas/billing.py +41 -0
  96. keble_payment-2.4.1/keble_payment/stripe/schemas/billing_portal_session.py +254 -0
  97. keble_payment-2.4.1/keble_payment/stripe/schemas/cash_balance.py +18 -0
  98. keble_payment-2.4.1/keble_payment/stripe/schemas/charge.py +390 -0
  99. keble_payment-2.4.1/keble_payment/stripe/schemas/checkout_session.py +1630 -0
  100. keble_payment-2.4.1/keble_payment/stripe/schemas/checks.py +10 -0
  101. keble_payment-2.4.1/keble_payment/stripe/schemas/coupon.py +131 -0
  102. keble_payment-2.4.1/keble_payment/stripe/schemas/customer.py +652 -0
  103. keble_payment-2.4.1/keble_payment/stripe/schemas/detailed.py +433 -0
  104. keble_payment-2.4.1/keble_payment/stripe/schemas/discount.py +49 -0
  105. keble_payment-2.4.1/keble_payment/stripe/schemas/dispute.py +45 -0
  106. keble_payment-2.4.1/keble_payment/stripe/schemas/event.py +62 -0
  107. keble_payment-2.4.1/keble_payment/stripe/schemas/evidence_detail.py +24 -0
  108. keble_payment-2.4.1/keble_payment/stripe/schemas/fee.py +19 -0
  109. keble_payment-2.4.1/keble_payment/stripe/schemas/invoice.py +642 -0
  110. keble_payment-2.4.1/keble_payment/stripe/schemas/out_come.py +13 -0
  111. keble_payment-2.4.1/keble_payment/stripe/schemas/payment_channels.py +224 -0
  112. keble_payment-2.4.1/keble_payment/stripe/schemas/payment_error.py +32 -0
  113. keble_payment-2.4.1/keble_payment/stripe/schemas/payment_intent.py +517 -0
  114. keble_payment-2.4.1/keble_payment/stripe/schemas/payment_method.py +177 -0
  115. keble_payment-2.4.1/keble_payment/stripe/schemas/portal_configuration.py +412 -0
  116. keble_payment-2.4.1/keble_payment/stripe/schemas/price.py +524 -0
  117. keble_payment-2.4.1/keble_payment/stripe/schemas/refund.py +150 -0
  118. keble_payment-2.4.1/keble_payment/stripe/schemas/setup_error.py +27 -0
  119. keble_payment-2.4.1/keble_payment/stripe/schemas/setup_intent.py +228 -0
  120. keble_payment-2.4.1/keble_payment/stripe/schemas/shipping.py +20 -0
  121. keble_payment-2.4.1/keble_payment/stripe/schemas/subscription.py +571 -0
  122. keble_payment-2.4.1/keble_payment/stripe/schemas/subscription_schedule.py +174 -0
  123. keble_payment-2.4.1/keble_payment/stripe/schemas/tip.py +8 -0
  124. keble_payment-2.4.1/keble_payment/stripe/schemas/transfer.py +136 -0
  125. keble_payment-2.4.1/keble_payment/stripe/schemas/transfer_data.py +18 -0
  126. keble_payment-2.4.1/keble_payment/stripe/schemas/transfer_reversal.py +26 -0
  127. keble_payment-2.4.1/keble_payment/stripe/schemas/utils.py +42 -0
  128. keble_payment-2.4.1/keble_payment/testing/__init__.py +6 -0
  129. keble_payment-2.4.1/keble_payment/testing/config.py +205 -0
  130. keble_payment-2.4.1/keble_payment/testing/helpers.py +17 -0
  131. keble_payment-2.4.1/keble_payment/utils.py +25 -0
  132. keble_payment-2.4.1/logs/AiAgentChangesLogs.20260630.md +156 -0
  133. keble_payment-2.4.1/poetry.lock +3797 -0
  134. keble_payment-2.4.1/pyproject.poetry.toml +29 -0
  135. keble_payment-2.4.1/pyproject.toml +58 -0
  136. keble_payment-2.4.1/pyrightconfig.json +18 -0
  137. keble_payment-2.4.1/tests/assets/.gitkeep +1 -0
  138. keble_payment-2.4.1/tests/assets/old/.gitkeep +1 -0
  139. keble_payment-2.4.1/tests/conftest.py +374 -0
  140. keble_payment-2.4.1/tests/integration/crud/test_alipay.py +35 -0
  141. keble_payment-2.4.1/tests/integration/crud/test_bank_transaction.py +37 -0
  142. keble_payment-2.4.1/tests/integration/crud/test_coupon.py +543 -0
  143. keble_payment-2.4.1/tests/integration/crud/test_coupon_history.py +242 -0
  144. keble_payment-2.4.1/tests/integration/crud/test_coupon_performance.py +235 -0
  145. keble_payment-2.4.1/tests/integration/crud/test_mongo_indexes.py +187 -0
  146. keble_payment-2.4.1/tests/integration/crud/test_order.py +36 -0
  147. keble_payment-2.4.1/tests/integration/crud/test_payment.py +50 -0
  148. keble_payment-2.4.1/tests/integration/main/test_admin_simulated_order.py +149 -0
  149. keble_payment-2.4.1/tests/integration/main/test_coupon.py +484 -0
  150. keble_payment-2.4.1/tests/integration/main/test_order.py +1075 -0
  151. keble_payment-2.4.1/tests/live/alipay_client/test_client_live.py +84 -0
  152. keble_payment-2.4.1/tests/live/stripe_api/api/test_checkout_session_live.py +123 -0
  153. keble_payment-2.4.1/tests/unit/alipay_client/test_client.py +55 -0
  154. keble_payment-2.4.1/tests/unit/assets/test_assets.py +20 -0
  155. keble_payment-2.4.1/tests/unit/main/test_coupon_attribution_history.py +189 -0
  156. keble_payment-2.4.1/tests/unit/main/test_payment_method_sync.py +390 -0
  157. keble_payment-2.4.1/tests/unit/main/test_stripe_crud_validation.py +522 -0
  158. keble_payment-2.4.1/tests/unit/main/test_stripe_payment_validation.py +470 -0
  159. keble_payment-2.4.1/tests/unit/main/test_subscription_no_stripe_customer.py +84 -0
  160. keble_payment-2.4.1/tests/unit/paypal/schemas/test_payout.py +53 -0
  161. keble_payment-2.4.1/tests/unit/schemas/test_alipay.py +20 -0
  162. keble_payment-2.4.1/tests/unit/schemas/test_coupon.py +87 -0
  163. keble_payment-2.4.1/tests/unit/schemas/test_coupon_attribution.py +128 -0
  164. keble_payment-2.4.1/tests/unit/schemas/test_order.py +228 -0
  165. keble_payment-2.4.1/tests/unit/schemas/test_order_referral.py +104 -0
  166. keble_payment-2.4.1/tests/unit/stripe_api/api/test_charge.py +151 -0
  167. keble_payment-2.4.1/tests/unit/stripe_api/api/test_checkout_session.py +511 -0
  168. keble_payment-2.4.1/tests/unit/stripe_api/api/test_customer.py +187 -0
  169. keble_payment-2.4.1/tests/unit/stripe_api/api/test_payment_intent.py +373 -0
  170. keble_payment-2.4.1/tests/unit/stripe_api/api/test_payment_method.py +226 -0
  171. keble_payment-2.4.1/tests/unit/stripe_api/conftest.py +101 -0
  172. keble_payment-2.4.1/tests/unit/stripe_api/test_checkout_session_webhook.py +388 -0
  173. keble_payment-2.4.1/tests/unit/stripe_api/test_invoices.py +784 -0
  174. keble_payment-2.4.1/tests/unit/stripe_api/test_order_apis.py +1457 -0
  175. keble_payment-2.4.1/tests/unit/stripe_api/test_price_schema.py +495 -0
  176. keble_payment-2.4.1/tests/unit/stripe_api/test_stripe_account.py +237 -0
  177. keble_payment-2.4.1/tests/unit/stripe_api/test_stripe_webhook_handler.py +344 -0
  178. keble_payment-2.4.1/tests/unit/stripe_api/test_subscriptions.py +663 -0
  179. keble_payment-2.4.1/uv.lock +1470 -0
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,163 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
105
+ __pypackages__/
106
+
107
+ # Celery stuff
108
+ celerybeat-schedule
109
+ celerybeat.pid
110
+
111
+ # SageMath parsed files
112
+ *.sage.py
113
+
114
+ # Environments
115
+ .env
116
+ .venv
117
+ env/
118
+ venv/
119
+ ENV/
120
+ env.bak/
121
+ venv.bak/
122
+
123
+ # Spyder project settings
124
+ .spyderproject
125
+ .spyproject
126
+
127
+ # Rope project settings
128
+ .ropeproject
129
+
130
+ # mkdocs documentation
131
+ /site
132
+
133
+ # mypy
134
+ .mypy_cache/
135
+ .dmypy.json
136
+ dmypy.json
137
+
138
+ # Pyre type checker
139
+ .pyre/
140
+
141
+ # pytype static type analyzer
142
+ .pytype/
143
+
144
+ # Cython debug symbols
145
+ cython_debug/
146
+
147
+ # PyCharm
148
+ # JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
149
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
150
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
151
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
152
+ .idea/
153
+ .vscode/
154
+ .cursor/
155
+ .idea/
156
+ .lprof/
157
+ .ruff_cache/
158
+
159
+ # Local payment-provider test keys belong outside git.
160
+ tests/**/*.pem
161
+
162
+ run_copy_readme.sh
163
+ .claude
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,24 @@
1
+ # keble-payment Agent Notes
2
+
3
+ ## Testing Guideline
4
+
5
+ - Follow root `../../TESTING_GUIDELINE.md` for all payment test work.
6
+ - The Keble development default is local-full and runs Mongo/Redis integration tests while excluding hosted providers:
7
+ `RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 uv run pytest -q -m "not live and not container"`.
8
+ - Keep the portable-offline fallback for machines without local DBs:
9
+ `uv run pytest -q -m "not live and not slow and not eval and not local_stack and not db_stack and not container"`.
10
+ - Real Stripe, Alipay, PayPal, container, live, and eval tests must be explicitly marked and env-gated.
11
+ - Prefer shared `keble_db.testing` helpers for new DB tests instead of ad hoc database cleanup.
12
+ - Payment integration tests must use per-test Mongo databases and Redis namespaces from `keble_db.testing`; do not add broad collection deletes against shared databases.
13
+ - Keep payment-specific reusable test settings and asset helpers in `keble_payment.testing`; do not recreate root `tests/config.py`, root `tests/helpers.py`, or `tests/support`.
14
+ - If payment or DB test data is missing, enrich `keble_payment.testing` or `keble_db.testing` first instead of creating another downstream-only fixture.
15
+ - Keep executable tests only under canonical layer roots: `tests/unit`, `tests/integration`, `tests/live`, `tests/contract`, `tests/evals`, and `tests/db_stack`.
16
+ - Put pure schema/client-shape tests in the `unit` layer and real Mongo/Redis behavior in the `integration db` layer that runs in local-full with `RUN_INTEGRATION=1 RUN_REAL_DB=1`.
17
+ - Do not add provider-specific pytest markers such as Stripe, Alipay, or PayPal. Use canonical `live` plus provider env guards, paths, or `-k` selection for provider slices.
18
+ - Once a provider live slice is explicitly enabled and credentials are present, provider request/schema errors must fail the test; do not catch provider exceptions and convert them to skips.
19
+ - Do not cache successful provider responses to skip real Stripe, Alipay, PayPal, Keepa, LLM, or embedding checks. Keep live tests tiny and explicit.
20
+ - Future payment quality or provider-contract regression datasets belong under `tests/evals` with `eval`; selecting `-m eval` is enough, so do not add a generic `RUN_EVALS` gate.
21
+ - Update `README.md`, `docs/testing.md`, `AGENTS.md`/`CLAUDE.md`, and `AiAgentChangesLogs.md` when test infrastructure changes.
22
+ - Update `docs/testing.md` timing tables whenever test counts, speed, or layer gates change.
23
+ - After Python test or fixture changes, run local-full, portable-offline, unit, eval, relevant integration/live selectors, `npx --yes pyright .`, and `uv build` from this repo root.
24
+ - `pyrightconfig.json` currently keeps payment pyright as a Python 3.13 syntax/import sanity gate, not a strict full-repo type gate; do not claim strict type cleanliness until that config is intentionally tightened and still passes.
@@ -0,0 +1,160 @@
1
+ # Ai Agent Changes Logs
2
+
3
+ Historical entries before 2026-06-30 23:13 were moved to `logs/AiAgentChangesLogs.20260630.md`.
4
+
5
+ ## 2026-07-03 03:37 CST
6
+ State: branch `refactor/local-db-evals-keble-payment`; local-full DB default and eval-selector alignment.
7
+
8
+ zma:
9
+ - Follow `prompts/20260702/1.8-pytests-heavy.md` repo by repo.
10
+ - Make local DB-heavy tests run in the default local-full development selector.
11
+ - Keep eval-quality tests under `tests/evals` with `eval` marks and run the eval selector too.
12
+
13
+ Ai:
14
+ - Tightened payment integration gating to the shared `RUN_INTEGRATION=1 RUN_REAL_DB=1` local-full shape while keeping Stripe/Alipay/PayPal live providers behind separate live env gates.
15
+ - Updated README, AGENTS, CLAUDE, and `docs/testing.md` so local-full is the development default, portable-offline is the no-DB fallback, and future payment quality/provider-contract datasets belong under `tests/evals` with `eval` marks and no generic `RUN_EVALS` gate.
16
+ - Refreshed the timing table and `uv.lock` to the current local `keble-helpers 1.46.0` path dependency exposed by the proof run.
17
+ - Proof: local-full `RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 uv run pytest -q -m "not live and not container"` `344 passed, 6 deselected` in 29.79s; portable-offline `279 passed, 71 deselected` in 3.46s; unit `279 passed, 71 deselected` in 3.41s; eval selector `350 deselected` in 2.12s; contract selector `350 deselected` in 2.11s; db_stack selector `350 deselected` in 2.12s; integration `65 passed, 285 deselected` in 4.05s; Stripe live `1 passed, 3 skipped` in 3.65s; Alipay live `2 skipped` in 1.46s with `RUN_ALIPAY_TRANSFER_LIVE` intentionally not enabled; `npx --yes pyright .` `0 errors` in 3.58s; `uv lock --check` passed; `uv build` produced sdist and wheel.
18
+
19
+ ## 2026-07-02 15:32 CST
20
+ State: branch `feature/service-pricing-policies`; package version `2.3.2`.
21
+
22
+ zma:
23
+ - Persist service pricing policy facts on orders so users and callbacks know the purchase used a limited-time deal or other pricing policy.
24
+
25
+ Ai:
26
+ - Added `OrderPricingPolicySnapshot` and optional `pricing_policy_snapshot` on orders without changing amount math.
27
+ - Threaded the snapshot through `OrderClient.acreate_order` so backend checkout can store policy/tag/original/base/deal price and linked-claim facts.
28
+ - Added focused order schema coverage proving the snapshot is stored separately from the charged amount.
29
+
30
+ ## 2026-07-02 13:49 CST
31
+ State: branch `refactor/harden-pytests-keble-payment`; payment tests now use per-test DB/Redis isolation and backend-env-aware live config.
32
+
33
+ zma:
34
+ - Continue the cross-repo pytest hardening follow-up.
35
+ - Reconsider over-trimmed real tests, remove weak skip/pass patterns, use shared backend env credentials, and keep canonical marks aligned.
36
+
37
+ Ai:
38
+ - Bumped `keble-payment` to `2.3.1`, required `keble-db>=1.8.1`, and added `httpx[socks]` so provider clients work under SOCKS proxy environments.
39
+ - Routed payment test settings through `keble_db.testing.resolve_test_env`, including backend `.env` aliases for Mongo, Redis, Stripe, Alipay, and PayPal.
40
+ - Replaced broad Mongo cleanup with per-test Mongo databases and Redis namespaces from `keble_db.testing.create_test_namespace`.
41
+ - Kept ordinary integration tests offline by patching only Alipay payment-url construction outside live tests, while preserving real Alipay/Stripe behavior in guarded live slices.
42
+ - Strengthened coupon/order/webhook tests by replacing manual try/except, placeholder skips, and weak concurrency checks with specific assertions.
43
+ - Updated README, docs/testing.md, AGENTS.md, and CLAUDE.md with namespace isolation, env resolution, no provider-success caching, and current timing proof.
44
+ - Proof: default offline pytest `278 passed, 71 deselected` in `1.61s`; unit `278 passed, 71 deselected` in `1.61s`; integration `65 passed, 284 deselected` in `1.74s`; Stripe live `1 passed, 3 skipped` in `2.07s`; Alipay live `2 skipped`; `npx --yes pyright .` `0 errors`.
45
+
46
+ ## 2026-07-01 17:22 CST
47
+ State: branch `refactor/testing-quality-audit-payment-live`; live Stripe checkout-session tests strengthened.
48
+
49
+ zma:
50
+ - Continue the cross-repo testing follow-up audit from `prompts/202060701/1.1-tests-enrich-and-run.md`.
51
+ - Ensure real/live tests are useful and not weakened into skip-on-failure behavior.
52
+
53
+ Ai:
54
+ - Removed broad exception-to-skip handling from Stripe checkout-session live tests so explicitly enabled live provider request/schema failures fail the test instead of being reported as skips.
55
+ - Kept skips only for missing live preconditions such as `STRIPE_TEST_API_KEY`, `STRIPE_TEST_PRICE_ID`, or missing dependent session state.
56
+ - Strengthened the checkout-session list assertion to validate returned item shape instead of asserting a non-negative list length.
57
+ - Updated README, docs/testing.md, AGENTS.md, and CLAUDE.md with the provider-live failure contract.
58
+
59
+ ## 2026-07-01 15:49 CST
60
+ State: branch `refactor/testing-quality-audit-keble-payment`; follow-up audit for skipped Stripe payment-intent tests.
61
+
62
+ zma:
63
+ - Continue the cross-repo testing follow-up audit from `prompts/202060701/1.1-tests-enrich-and-run.md`.
64
+ - Replace skipped or placeholder tests with meaningful behavior assertions instead of weakening coverage.
65
+
66
+ Ai:
67
+ - Replaced two permanently skipped tests for removed `OrderClient._acreate_stripe_payment_intent` with current `_aget_payment_by_stripe_payment_intent` webhook-path assertions.
68
+ - Covered missing webhook intent persistence, typed `DataIntegrityCompromised` wrapping for failed payload persistence, and subscription-style payment intents that intentionally return `None` when no payment is linked.
69
+ - Proof: focused `tests/unit/stripe_api/test_order_apis.py` `53 passed`; default offline pytest `276 passed, 2 skipped, 71 deselected`; unit pytest `276 passed, 2 skipped, 71 deselected`; unconditional-skip scan clean for the repaired file; `npx --yes pyright .` `0 errors`.
70
+
71
+ ## 2026-07-01 12:06 CST
72
+ State: branch `refactor/testing-quality-audit-keble-payment-skips`; follow-up audit for unconditional live-test skips.
73
+
74
+ zma:
75
+ - Continue the cross-repo testing follow-up audit from `prompts/202060701/1.1-tests-enrich-and-run.md`.
76
+ - Remove placeholder or permanent skips while keeping live provider tests explicitly gated and offline by default.
77
+
78
+ Ai:
79
+ - Replaced the permanent Alipay transfer skip with an explicit slow live gate requiring `RUN_ALIPAY_TRANSFER_LIVE=1` in addition to the repo live-test controls.
80
+ - Replaced manual try/except assertions in the Alipay live test with `pytest.raises` so expected provider validation failures are asserted directly.
81
+ - Proof: focused transfer test is skipped by the opt-in gate; default offline pytest `273 passed, 4 skipped, 71 deselected`; unit pytest `273 passed, 4 skipped, 71 deselected`; hard-skip scan clean; `uv run npx --yes pyright .` `0 errors`; `uv build` succeeded.
82
+
83
+ ## 2026-07-01 11:33 CST
84
+ State: branch `refactor/testing-quality-audit-keble-payment`; follow-up audit for placeholder tests and payment order-state coverage.
85
+
86
+ zma:
87
+ - Continue the cross-repo testing follow-up audit from `prompts/202060701/1.1-tests-enrich-and-run.md`.
88
+ - Replace useless placeholder tests with real assertions, keep default tests offline, and run pytest plus `npx --yes pyright .`.
89
+
90
+ Ai:
91
+ - Replaced the two placeholder order paid-check tests with integration assertions for unpaid, paid, and missing order IDs.
92
+ - Covered Redis paid-cache behavior through the offline admin-simulated payment success path and covered stored paid-state behavior through the bank-prepaid order path.
93
+ - Refreshed `uv.lock` for the actual local path-source `keble-exceptions 0.1.1` resolution used by `uv run`.
94
+ - Proof: focused payment checks `2 passed`; default offline pytest `273 passed, 4 skipped, 71 deselected`; unit pytest `273 passed, 4 skipped, 71 deselected`; placeholder scan clean; `npx --yes pyright .` `0 errors`.
95
+
96
+ ## 2026-07-01 07:18 CST
97
+ State: Strict test-support root cleanup for `keble-payment`.
98
+
99
+ zma:
100
+ - Continue the strict cross-repo testing cleanup.
101
+ - Remove final root `tests/` support blockers while preserving payment test docs and local key ignores.
102
+
103
+ Ai:
104
+ - Moved root `tests/README.md` to `docs/testing.md` and linked it from README.
105
+ - Moved the local PEM key ignore behavior from `tests/.gitignore` into the repo root `.gitignore`.
106
+ - Added repo-local `uv` sources for `keble-db`, `keble-exceptions`, and `keble-helpers` so proof commands use the current local Keble dependency line instead of stale published helper metadata.
107
+ - Updated AGENTS/CLAUDE so future workers update `docs/testing.md` instead of recreating root test docs.
108
+
109
+ ## 2026-07-01 03:28 CST
110
+ State: Strict folder follow-up for `keble-payment`; package runtime behavior and dependency versions were not changed.
111
+
112
+ zma:
113
+ - Continue the cross-repo testing cleanup with stricter folder and marker allowances.
114
+ - Remove legacy `test_*` source-group folders, root test helper modules, and duplicate test configs while keeping default tests offline.
115
+
116
+ Ai:
117
+ - Moved offline payment tests into `tests/unit`, real Mongo/Redis tests into `tests/integration`, and live provider canaries into `tests/live`.
118
+ - Moved reusable payment test settings and asset helpers into `keble_payment.testing`.
119
+ - Moved pytest marker config from duplicate `tests/pytest.ini` into `pyproject.toml` and updated docs to the canonical folder structure.
120
+
121
+ ## 2026-06-30 23:13
122
+ State: Documentation-only README compaction and AI log archival; no runtime code, schemas, dependencies, or tests were changed.
123
+
124
+ zma:
125
+ - Auto compact and summarize README.md files across repos unless already small.
126
+ - Cross-check retained README information for validity and keep only critical, necessary information.
127
+ - Move lengthy AiAgentChangesLogs.md files into repo-local logs/AiAgentChangesLogs.2026****.md.
128
+ - Merge the documentation changes to main repo by repo.
129
+
130
+ Ai:
131
+ - Archived the previous long agent change log into `logs/AiAgentChangesLogs.20260630.md`.
132
+ - Compacted `README.md` to current purpose, validated wiring, install/test gates, and high-risk side effects.
133
+ - Kept only critical current README facts cross-checked against manifests, config, source roots, compose scripts, or existing guideline files.
134
+ ## 2026-07-12 15:50 CST
135
+ State: `feature/coupon-attribution-performance`; package 2.4.0 attribution and reporting contract implemented and under release verification.
136
+
137
+ zma:
138
+ - Add scalable AI/human coupon attribution support across Keble and Truth.
139
+ - Preserve historical tag/contributor truth and answer monthly or arbitrary-range performance questions.
140
+
141
+ Ai:
142
+ - Added immutable coupon redemption snapshots for currency, marketplace, tags, contributors, and exact basis-point allocation.
143
+ - Replaced fetch-all coupon reads with indexed `CouponListQuery`/`CouponPage`, assignment migration, text search, and explicit sort indexes.
144
+ - Added indexed coupon/tag/contributor performance aggregation and explicit approved legacy-history backfill with optional Mongo session participation.
145
+ - Added unit and real-Mongo coverage for allocation, history writes, indexes, pagination, reporting, and backfill.
146
+ ## 2026-07-18 04:47 CST
147
+ State: `fix/review2-money-contract`; exact PayPal boundary migration for `keble-payment 2.4.1`.
148
+
149
+ zma:
150
+ - Continue the complete Data Infra REVIEW2 plan and close every transitive Money caller before backend integration.
151
+ - Preserve strong typing, exact financial semantics, release proof, and comprehensive exponent edge tests.
152
+
153
+ Ai:
154
+ - Removed float parsing and hard-coded two-decimal formatting from `PayPalMoney`.
155
+ - Added exact JPY/USD/BHD round trips, negative adjustments, and excess-precision rejection coverage.
156
+ - Corrected three local-full Mongo tests to create UTC-aware expiry/refund timestamps, matching the canonical aware Motor client instead of failing during datetime subtraction.
157
+ - Removed module-import Mongo writes from three order scenarios and made their coupon cases create real rows inside per-test async namespaces; portable collection is now offline and the formerly `None` coupon cases exercise discounts.
158
+ - Raised the public `keble-helpers` floor to 1.54.0 and removed the local helper source override for registry-reproducible builds.
159
+ - Repaired the pre-existing full-repository Ruff gate without changing public exports, so the release now has a clean static-quality baseline.
160
+ - Proof: exact PayPal `5 passed`; portable `291 passed, 75 deselected`; isolated local-full `360 passed, 6 deselected`; isolated integration `69 passed, 297 deselected`; Pyright `0 errors`; Ruff clean; lock check and wheel/sdist build passed.
@@ -0,0 +1,24 @@
1
+ # keble-payment Agent Notes
2
+
3
+ ## Testing Guideline
4
+
5
+ - Follow root `../../TESTING_GUIDELINE.md` for all payment test work.
6
+ - The Keble development default is local-full and runs Mongo/Redis integration tests while excluding hosted providers:
7
+ `RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 uv run pytest -q -m "not live and not container"`.
8
+ - Keep the portable-offline fallback for machines without local DBs:
9
+ `uv run pytest -q -m "not live and not slow and not eval and not local_stack and not db_stack and not container"`.
10
+ - Real Stripe, Alipay, PayPal, container, live, and eval tests must be explicitly marked and env-gated.
11
+ - Prefer shared `keble_db.testing` helpers for new DB tests instead of ad hoc database cleanup.
12
+ - Payment integration tests must use per-test Mongo databases and Redis namespaces from `keble_db.testing`; do not add broad collection deletes against shared databases.
13
+ - Keep payment-specific reusable test settings and asset helpers in `keble_payment.testing`; do not recreate root `tests/config.py`, root `tests/helpers.py`, or `tests/support`.
14
+ - If payment or DB test data is missing, enrich `keble_payment.testing` or `keble_db.testing` first instead of creating another downstream-only fixture.
15
+ - Keep executable tests only under canonical layer roots: `tests/unit`, `tests/integration`, `tests/live`, `tests/contract`, `tests/evals`, and `tests/db_stack`.
16
+ - Put pure schema/client-shape tests in the `unit` layer and real Mongo/Redis behavior in the `integration db` layer that runs in local-full with `RUN_INTEGRATION=1 RUN_REAL_DB=1`.
17
+ - Do not add provider-specific pytest markers such as Stripe, Alipay, or PayPal. Use canonical `live` plus provider env guards, paths, or `-k` selection for provider slices.
18
+ - Once a provider live slice is explicitly enabled and credentials are present, provider request/schema errors must fail the test; do not catch provider exceptions and convert them to skips.
19
+ - Do not cache successful provider responses to skip real Stripe, Alipay, PayPal, Keepa, LLM, or embedding checks. Keep live tests tiny and explicit.
20
+ - Future payment quality or provider-contract regression datasets belong under `tests/evals` with `eval`; selecting `-m eval` is enough, so do not add a generic `RUN_EVALS` gate.
21
+ - Update `README.md`, `docs/testing.md`, `AGENTS.md`/`CLAUDE.md`, and `AiAgentChangesLogs.md` when test infrastructure changes.
22
+ - Update `docs/testing.md` timing tables whenever test counts, speed, or layer gates change.
23
+ - After Python test or fixture changes, run local-full, portable-offline, unit, eval, relevant integration/live selectors, `npx --yes pyright .`, and `uv build` from this repo root.
24
+ - `pyrightconfig.json` currently keeps payment pyright as a Python 3.13 syntax/import sanity gate, not a strict full-repo type gate; do not claim strict type cleanliness until that config is intentionally tightened and still passes.
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: keble-payment
3
+ Version: 2.4.1
4
+ Author-email: zhenhao-ma <bob0103779@gmail.com>
5
+ Requires-Python: <3.14,>=3.13
6
+ Requires-Dist: httpx[socks]<1.0.0,>=0
7
+ Requires-Dist: keble-db<2.0.0,>=1.8.1
8
+ Requires-Dist: keble-exceptions<1.0.0,>=0,>=0.0.9
9
+ Requires-Dist: keble-helpers<2.0.0,>=1.54.0
10
+ Requires-Dist: python-alipay-sdk==1.10.1
11
+ Requires-Dist: stripe<15.0.0,>=14
12
+ Description-Content-Type: text/markdown
13
+
14
+ # keble-payment
15
+
16
+ `keble-payment` owns payment provider integration schemas and helpers for
17
+ Alipay, Stripe, and payment persistence used by Keble services.
18
+
19
+ ## Verified State
20
+
21
+ Checked on 2026-07-12 against `pyproject.toml`, `keble_payment/`, and tests
22
+ on `feature/coupon-attribution-performance`.
23
+
24
+ - Package: `keble-payment 2.4.0`
25
+ - Python: `>=3.13,<3.14`
26
+ - Critical deps: `keble-helpers`, `keble-db`, `keble-exceptions`,
27
+ `python-alipay-sdk`, `stripe`, `httpx`
28
+ - Source roots: `alipay/`, `stripe/`, `paypal/`, `schemas/`, `crud/`, `main/`
29
+ - Public exports: provider modules, payment schemas, and main client/helpers.
30
+
31
+ ## Runtime Contract
32
+
33
+ - `keble-payment 2.4.1` converts PayPal decimal strings through exact
34
+ `Money.from_major_units` / `Money.to_major_units` APIs. Provider output uses
35
+ each currency's audited scale (JPY 0, USD 2, BHD 3) instead of a hard-coded
36
+ two-decimal formatter; unrepresentable precision fails before payout.
37
+ - Provider API details stay in provider modules. Backend checkout flows should
38
+ consume package schemas and helpers rather than embedding provider payloads.
39
+ - Stripe stored models support optional `stripe_account` for multi-account
40
+ handling; preserve that field across schema changes.
41
+ - Tests must not perform live payment requests in the local-full or
42
+ portable-offline suites. Provider
43
+ fixtures/assets belong under tests and must stay deterministic.
44
+ - Enabled provider live tests fail on provider request/schema errors; skips are
45
+ only for missing live-test preconditions such as credentials or test price IDs.
46
+ - Reusable test settings and asset helpers live in `keble_payment.testing`.
47
+ - Payment tests resolve shared test env values through `keble_db.testing`, so
48
+ backend-level `.env` values can be reused without duplicating secrets in this
49
+ package.
50
+ - `OrderPricingPolicySnapshot` is the immutable paid-order audit shape for
51
+ service pricing policies. The snapshot records the selected policy/tag,
52
+ original/base/deal prices, currency, validity window, and optional linked
53
+ claim clue so backend callbacks can consume limited deals only after success.
54
+ - Coupon histories snapshot currency, marketplace, and normalized tag/contributor
55
+ attribution at payment success. Multiple tags split 10,000 basis points with
56
+ deterministic largest-remainder allocation, so coupon/tag/contributor totals
57
+ reconcile exactly.
58
+ - `CouponListQuery`/`CouponPage` own server search, sort, and pagination. Coupon
59
+ search uses `coupon_search_text_idx`; attribution review uses
60
+ `attribution_status_created_desc_idx`; supported sort fields have explicit indexes.
61
+ - `CouponPerformanceQuery` is the only reporting contract. It uses closed-open
62
+ time ranges, IANA timezones, DAY/MONTH/TOTAL buckets, and exact Decimal output
63
+ grouped separately by currency and marketplace.
64
+ - Historical attribution changes are explicit human-approved backfills through
65
+ `abackfill_coupon_history_attribution`; never infer current tags during reports.
66
+ - Mongo and Redis integration tests must use per-test namespaces/databases and
67
+ cleanup, not broad session-level deletes against shared databases.
68
+ - Executable tests stay under canonical layer roots: `tests/unit`,
69
+ `tests/integration`, `tests/live`, `tests/contract`, `tests/evals`, and
70
+ `tests/db_stack`.
71
+
72
+ ## Testing
73
+
74
+ Detailed test-layer notes live in `docs/testing.md`.
75
+
76
+ Local-full development command:
77
+
78
+ ```bash
79
+ uv sync --group test
80
+ RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 \
81
+ uv run pytest -q -m "not live and not container"
82
+ ```
83
+
84
+ Portable-offline command:
85
+
86
+ ```bash
87
+ uv run pytest -q -m "not live and not slow and not eval and not local_stack and not db_stack and not container"
88
+ ```
89
+
90
+ Real Mongo/Redis integration tests:
91
+
92
+ ```bash
93
+ RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 uv run pytest -q -m integration
94
+ ```
95
+
96
+ Eval selector:
97
+
98
+ ```bash
99
+ uv run pytest -q -m eval
100
+ ```
101
+
102
+ Syntax/type gate:
103
+
104
+ ```bash
105
+ npx --yes pyright .
106
+ ```
107
+
108
+ Latest proof on 2026-07-18:
109
+
110
+ - Local-full selector: `360 passed, 6 deselected` in `4.40s`.
111
+ - Portable-offline selector: `291 passed, 75 deselected` in `1.60s`.
112
+ - Unit selector: `291 passed, 75 deselected` in `1.55s`.
113
+ - Eval selector: `366 deselected` in `0.07s` (no eval tests are registered).
114
+ - Contract selector: `366 deselected` in `0.07s` (no contract tests are registered).
115
+ - DB-stack selector: `366 deselected` (no DB-stack-only tests are registered).
116
+ - Integration selector: `69 passed, 297 deselected` in `2.95s`.
117
+ - Stripe live canary: `1 passed, 3 skipped` in `3.65s`; skipped cases lacked
118
+ `STRIPE_TEST_PRICE_ID`.
119
+ - Alipay live canary: `2 skipped` in `1.46s`; local Alipay key material was unavailable.
120
+ - `npx --yes pyright .`: `0 errors`.
121
+
122
+ ## Change Logs
123
+
124
+ Historical release notes and long AI change history live under `logs/` when
125
+ archived.
126
+
127
+ ## Side Effect If Changes
128
+
129
+ - Backend checkout, membership upgrade, payment callback, and admin order
130
+ routes depend on these provider schemas.
131
+ - Frontend purchase success tracking depends on backend payment state derived
132
+ from this package.
@@ -0,0 +1,119 @@
1
+ # keble-payment
2
+
3
+ `keble-payment` owns payment provider integration schemas and helpers for
4
+ Alipay, Stripe, and payment persistence used by Keble services.
5
+
6
+ ## Verified State
7
+
8
+ Checked on 2026-07-12 against `pyproject.toml`, `keble_payment/`, and tests
9
+ on `feature/coupon-attribution-performance`.
10
+
11
+ - Package: `keble-payment 2.4.0`
12
+ - Python: `>=3.13,<3.14`
13
+ - Critical deps: `keble-helpers`, `keble-db`, `keble-exceptions`,
14
+ `python-alipay-sdk`, `stripe`, `httpx`
15
+ - Source roots: `alipay/`, `stripe/`, `paypal/`, `schemas/`, `crud/`, `main/`
16
+ - Public exports: provider modules, payment schemas, and main client/helpers.
17
+
18
+ ## Runtime Contract
19
+
20
+ - `keble-payment 2.4.1` converts PayPal decimal strings through exact
21
+ `Money.from_major_units` / `Money.to_major_units` APIs. Provider output uses
22
+ each currency's audited scale (JPY 0, USD 2, BHD 3) instead of a hard-coded
23
+ two-decimal formatter; unrepresentable precision fails before payout.
24
+ - Provider API details stay in provider modules. Backend checkout flows should
25
+ consume package schemas and helpers rather than embedding provider payloads.
26
+ - Stripe stored models support optional `stripe_account` for multi-account
27
+ handling; preserve that field across schema changes.
28
+ - Tests must not perform live payment requests in the local-full or
29
+ portable-offline suites. Provider
30
+ fixtures/assets belong under tests and must stay deterministic.
31
+ - Enabled provider live tests fail on provider request/schema errors; skips are
32
+ only for missing live-test preconditions such as credentials or test price IDs.
33
+ - Reusable test settings and asset helpers live in `keble_payment.testing`.
34
+ - Payment tests resolve shared test env values through `keble_db.testing`, so
35
+ backend-level `.env` values can be reused without duplicating secrets in this
36
+ package.
37
+ - `OrderPricingPolicySnapshot` is the immutable paid-order audit shape for
38
+ service pricing policies. The snapshot records the selected policy/tag,
39
+ original/base/deal prices, currency, validity window, and optional linked
40
+ claim clue so backend callbacks can consume limited deals only after success.
41
+ - Coupon histories snapshot currency, marketplace, and normalized tag/contributor
42
+ attribution at payment success. Multiple tags split 10,000 basis points with
43
+ deterministic largest-remainder allocation, so coupon/tag/contributor totals
44
+ reconcile exactly.
45
+ - `CouponListQuery`/`CouponPage` own server search, sort, and pagination. Coupon
46
+ search uses `coupon_search_text_idx`; attribution review uses
47
+ `attribution_status_created_desc_idx`; supported sort fields have explicit indexes.
48
+ - `CouponPerformanceQuery` is the only reporting contract. It uses closed-open
49
+ time ranges, IANA timezones, DAY/MONTH/TOTAL buckets, and exact Decimal output
50
+ grouped separately by currency and marketplace.
51
+ - Historical attribution changes are explicit human-approved backfills through
52
+ `abackfill_coupon_history_attribution`; never infer current tags during reports.
53
+ - Mongo and Redis integration tests must use per-test namespaces/databases and
54
+ cleanup, not broad session-level deletes against shared databases.
55
+ - Executable tests stay under canonical layer roots: `tests/unit`,
56
+ `tests/integration`, `tests/live`, `tests/contract`, `tests/evals`, and
57
+ `tests/db_stack`.
58
+
59
+ ## Testing
60
+
61
+ Detailed test-layer notes live in `docs/testing.md`.
62
+
63
+ Local-full development command:
64
+
65
+ ```bash
66
+ uv sync --group test
67
+ RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 \
68
+ uv run pytest -q -m "not live and not container"
69
+ ```
70
+
71
+ Portable-offline command:
72
+
73
+ ```bash
74
+ uv run pytest -q -m "not live and not slow and not eval and not local_stack and not db_stack and not container"
75
+ ```
76
+
77
+ Real Mongo/Redis integration tests:
78
+
79
+ ```bash
80
+ RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 uv run pytest -q -m integration
81
+ ```
82
+
83
+ Eval selector:
84
+
85
+ ```bash
86
+ uv run pytest -q -m eval
87
+ ```
88
+
89
+ Syntax/type gate:
90
+
91
+ ```bash
92
+ npx --yes pyright .
93
+ ```
94
+
95
+ Latest proof on 2026-07-18:
96
+
97
+ - Local-full selector: `360 passed, 6 deselected` in `4.40s`.
98
+ - Portable-offline selector: `291 passed, 75 deselected` in `1.60s`.
99
+ - Unit selector: `291 passed, 75 deselected` in `1.55s`.
100
+ - Eval selector: `366 deselected` in `0.07s` (no eval tests are registered).
101
+ - Contract selector: `366 deselected` in `0.07s` (no contract tests are registered).
102
+ - DB-stack selector: `366 deselected` (no DB-stack-only tests are registered).
103
+ - Integration selector: `69 passed, 297 deselected` in `2.95s`.
104
+ - Stripe live canary: `1 passed, 3 skipped` in `3.65s`; skipped cases lacked
105
+ `STRIPE_TEST_PRICE_ID`.
106
+ - Alipay live canary: `2 skipped` in `1.46s`; local Alipay key material was unavailable.
107
+ - `npx --yes pyright .`: `0 errors`.
108
+
109
+ ## Change Logs
110
+
111
+ Historical release notes and long AI change history live under `logs/` when
112
+ archived.
113
+
114
+ ## Side Effect If Changes
115
+
116
+ - Backend checkout, membership upgrade, payment callback, and admin order
117
+ routes depend on these provider schemas.
118
+ - Frontend purchase success tracking depends on backend payment state derived
119
+ from this package.