svc-infra 0.1.706__py3-none-any.whl → 1.1.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.
Potentially problematic release.
This version of svc-infra might be problematic. Click here for more details.
- svc_infra/apf_payments/models.py +47 -108
- svc_infra/apf_payments/provider/__init__.py +2 -2
- svc_infra/apf_payments/provider/aiydan.py +42 -100
- svc_infra/apf_payments/provider/base.py +10 -26
- svc_infra/apf_payments/provider/registry.py +3 -5
- svc_infra/apf_payments/provider/stripe.py +63 -135
- svc_infra/apf_payments/schemas.py +82 -90
- svc_infra/apf_payments/service.py +40 -86
- svc_infra/apf_payments/settings.py +10 -13
- svc_infra/api/__init__.py +13 -13
- svc_infra/api/fastapi/__init__.py +19 -0
- svc_infra/api/fastapi/admin/add.py +13 -18
- svc_infra/api/fastapi/apf_payments/router.py +47 -84
- svc_infra/api/fastapi/apf_payments/setup.py +7 -13
- svc_infra/api/fastapi/auth/__init__.py +1 -1
- svc_infra/api/fastapi/auth/_cookies.py +3 -9
- svc_infra/api/fastapi/auth/add.py +4 -8
- svc_infra/api/fastapi/auth/gaurd.py +9 -26
- svc_infra/api/fastapi/auth/mfa/models.py +4 -7
- svc_infra/api/fastapi/auth/mfa/pre_auth.py +3 -3
- svc_infra/api/fastapi/auth/mfa/router.py +9 -15
- svc_infra/api/fastapi/auth/mfa/security.py +3 -5
- svc_infra/api/fastapi/auth/mfa/utils.py +3 -2
- svc_infra/api/fastapi/auth/mfa/verify.py +2 -9
- svc_infra/api/fastapi/auth/providers.py +4 -6
- svc_infra/api/fastapi/auth/routers/apikey_router.py +16 -18
- svc_infra/api/fastapi/auth/routers/oauth_router.py +37 -85
- svc_infra/api/fastapi/auth/routers/session_router.py +3 -6
- svc_infra/api/fastapi/auth/security.py +17 -28
- svc_infra/api/fastapi/auth/sender.py +1 -3
- svc_infra/api/fastapi/auth/settings.py +18 -19
- svc_infra/api/fastapi/auth/state.py +6 -7
- svc_infra/api/fastapi/auth/ws_security.py +2 -2
- svc_infra/api/fastapi/billing/router.py +6 -8
- svc_infra/api/fastapi/db/http.py +10 -11
- svc_infra/api/fastapi/db/nosql/mongo/add.py +5 -15
- svc_infra/api/fastapi/db/nosql/mongo/crud_router.py +14 -15
- svc_infra/api/fastapi/db/sql/add.py +6 -14
- svc_infra/api/fastapi/db/sql/crud_router.py +27 -40
- svc_infra/api/fastapi/db/sql/health.py +1 -3
- svc_infra/api/fastapi/db/sql/session.py +4 -5
- svc_infra/api/fastapi/db/sql/users.py +8 -11
- svc_infra/api/fastapi/dependencies/ratelimit.py +4 -6
- svc_infra/api/fastapi/docs/add.py +13 -23
- svc_infra/api/fastapi/docs/landing.py +6 -8
- svc_infra/api/fastapi/docs/scoped.py +34 -42
- svc_infra/api/fastapi/dual/dualize.py +1 -1
- svc_infra/api/fastapi/dual/protected.py +12 -21
- svc_infra/api/fastapi/dual/router.py +14 -31
- svc_infra/api/fastapi/ease.py +57 -13
- svc_infra/api/fastapi/http/conditional.py +3 -5
- svc_infra/api/fastapi/middleware/errors/catchall.py +2 -6
- svc_infra/api/fastapi/middleware/errors/exceptions.py +1 -4
- svc_infra/api/fastapi/middleware/errors/handlers.py +12 -18
- svc_infra/api/fastapi/middleware/graceful_shutdown.py +4 -13
- svc_infra/api/fastapi/middleware/idempotency.py +11 -16
- svc_infra/api/fastapi/middleware/idempotency_store.py +14 -14
- svc_infra/api/fastapi/middleware/optimistic_lock.py +5 -8
- svc_infra/api/fastapi/middleware/ratelimit.py +8 -8
- svc_infra/api/fastapi/middleware/ratelimit_store.py +7 -8
- svc_infra/api/fastapi/middleware/request_id.py +1 -3
- svc_infra/api/fastapi/middleware/timeout.py +9 -10
- svc_infra/api/fastapi/object_router.py +1060 -0
- svc_infra/api/fastapi/openapi/apply.py +5 -6
- svc_infra/api/fastapi/openapi/conventions.py +4 -4
- svc_infra/api/fastapi/openapi/mutators.py +13 -31
- svc_infra/api/fastapi/openapi/pipeline.py +2 -2
- svc_infra/api/fastapi/openapi/responses.py +4 -6
- svc_infra/api/fastapi/openapi/security.py +1 -3
- svc_infra/api/fastapi/ops/add.py +7 -9
- svc_infra/api/fastapi/pagination.py +25 -37
- svc_infra/api/fastapi/routers/__init__.py +16 -38
- svc_infra/api/fastapi/setup.py +13 -31
- svc_infra/api/fastapi/tenancy/add.py +3 -2
- svc_infra/api/fastapi/tenancy/context.py +8 -7
- svc_infra/api/fastapi/versioned.py +3 -2
- svc_infra/app/env.py +5 -7
- svc_infra/app/logging/add.py +2 -1
- svc_infra/app/logging/filter.py +1 -1
- svc_infra/app/logging/formats.py +3 -2
- svc_infra/app/root.py +3 -3
- svc_infra/billing/__init__.py +19 -2
- svc_infra/billing/async_service.py +27 -7
- svc_infra/billing/jobs.py +23 -33
- svc_infra/billing/models.py +21 -52
- svc_infra/billing/quotas.py +5 -7
- svc_infra/billing/schemas.py +4 -6
- svc_infra/cache/__init__.py +12 -5
- svc_infra/cache/add.py +6 -9
- svc_infra/cache/backend.py +6 -5
- svc_infra/cache/decorators.py +17 -28
- svc_infra/cache/keys.py +2 -2
- svc_infra/cache/recache.py +22 -35
- svc_infra/cache/resources.py +8 -16
- svc_infra/cache/ttl.py +2 -3
- svc_infra/cache/utils.py +5 -6
- svc_infra/cli/__init__.py +4 -12
- svc_infra/cli/cmds/db/nosql/mongo/mongo_cmds.py +11 -10
- svc_infra/cli/cmds/db/nosql/mongo/mongo_scaffold_cmds.py +6 -9
- svc_infra/cli/cmds/db/ops_cmds.py +3 -6
- svc_infra/cli/cmds/db/sql/alembic_cmds.py +24 -41
- svc_infra/cli/cmds/db/sql/sql_export_cmds.py +9 -17
- svc_infra/cli/cmds/db/sql/sql_scaffold_cmds.py +10 -10
- svc_infra/cli/cmds/docs/docs_cmds.py +7 -10
- svc_infra/cli/cmds/dx/dx_cmds.py +5 -11
- svc_infra/cli/cmds/jobs/jobs_cmds.py +2 -7
- svc_infra/cli/cmds/obs/obs_cmds.py +4 -7
- svc_infra/cli/cmds/sdk/sdk_cmds.py +5 -15
- svc_infra/cli/foundation/runner.py +6 -11
- svc_infra/cli/foundation/typer_bootstrap.py +1 -2
- svc_infra/data/__init__.py +83 -0
- svc_infra/data/add.py +5 -5
- svc_infra/data/backup.py +8 -10
- svc_infra/data/erasure.py +3 -2
- svc_infra/data/fixtures.py +3 -3
- svc_infra/data/retention.py +8 -13
- svc_infra/db/crud_schema.py +9 -8
- svc_infra/db/nosql/__init__.py +0 -1
- svc_infra/db/nosql/constants.py +1 -1
- svc_infra/db/nosql/core.py +7 -14
- svc_infra/db/nosql/indexes.py +11 -10
- svc_infra/db/nosql/management.py +3 -3
- svc_infra/db/nosql/mongo/client.py +3 -3
- svc_infra/db/nosql/mongo/settings.py +2 -6
- svc_infra/db/nosql/repository.py +27 -28
- svc_infra/db/nosql/resource.py +15 -20
- svc_infra/db/nosql/scaffold.py +13 -17
- svc_infra/db/nosql/service.py +3 -4
- svc_infra/db/nosql/service_with_hooks.py +4 -3
- svc_infra/db/nosql/types.py +2 -6
- svc_infra/db/nosql/utils.py +4 -4
- svc_infra/db/ops.py +14 -18
- svc_infra/db/outbox.py +15 -18
- svc_infra/db/sql/apikey.py +12 -21
- svc_infra/db/sql/authref.py +3 -7
- svc_infra/db/sql/constants.py +9 -9
- svc_infra/db/sql/core.py +11 -11
- svc_infra/db/sql/management.py +2 -6
- svc_infra/db/sql/repository.py +17 -24
- svc_infra/db/sql/resource.py +14 -13
- svc_infra/db/sql/scaffold.py +13 -17
- svc_infra/db/sql/service.py +7 -16
- svc_infra/db/sql/service_with_hooks.py +4 -3
- svc_infra/db/sql/tenant.py +6 -14
- svc_infra/db/sql/uniq.py +8 -7
- svc_infra/db/sql/uniq_hooks.py +14 -19
- svc_infra/db/sql/utils.py +24 -53
- svc_infra/db/utils.py +3 -3
- svc_infra/deploy/__init__.py +8 -15
- svc_infra/documents/add.py +7 -8
- svc_infra/documents/ease.py +8 -8
- svc_infra/documents/models.py +3 -3
- svc_infra/documents/storage.py +11 -13
- svc_infra/dx/__init__.py +58 -0
- svc_infra/dx/add.py +1 -3
- svc_infra/dx/changelog.py +2 -2
- svc_infra/dx/checks.py +1 -1
- svc_infra/health/__init__.py +15 -16
- svc_infra/http/client.py +10 -14
- svc_infra/jobs/__init__.py +79 -0
- svc_infra/jobs/builtins/outbox_processor.py +3 -5
- svc_infra/jobs/builtins/webhook_delivery.py +1 -3
- svc_infra/jobs/loader.py +4 -5
- svc_infra/jobs/queue.py +14 -24
- svc_infra/jobs/redis_queue.py +20 -34
- svc_infra/jobs/runner.py +7 -11
- svc_infra/jobs/scheduler.py +5 -5
- svc_infra/jobs/worker.py +1 -1
- svc_infra/loaders/base.py +5 -4
- svc_infra/loaders/github.py +1 -3
- svc_infra/loaders/url.py +3 -9
- svc_infra/logging/__init__.py +7 -6
- svc_infra/mcp/__init__.py +82 -0
- svc_infra/mcp/svc_infra_mcp.py +2 -2
- svc_infra/obs/add.py +4 -3
- svc_infra/obs/cloud_dash.py +1 -1
- svc_infra/obs/metrics/__init__.py +3 -3
- svc_infra/obs/metrics/asgi.py +9 -14
- svc_infra/obs/metrics/base.py +13 -13
- svc_infra/obs/metrics/http.py +5 -9
- svc_infra/obs/metrics/sqlalchemy.py +9 -12
- svc_infra/obs/metrics.py +3 -3
- svc_infra/obs/settings.py +2 -6
- svc_infra/resilience/__init__.py +44 -0
- svc_infra/resilience/circuit_breaker.py +328 -0
- svc_infra/resilience/retry.py +289 -0
- svc_infra/security/__init__.py +167 -0
- svc_infra/security/add.py +5 -9
- svc_infra/security/audit.py +14 -17
- svc_infra/security/audit_service.py +9 -9
- svc_infra/security/hibp.py +3 -6
- svc_infra/security/jwt_rotation.py +7 -10
- svc_infra/security/lockout.py +12 -11
- svc_infra/security/models.py +37 -46
- svc_infra/security/oauth_models.py +8 -8
- svc_infra/security/org_invites.py +11 -13
- svc_infra/security/passwords.py +4 -6
- svc_infra/security/permissions.py +8 -7
- svc_infra/security/session.py +6 -7
- svc_infra/security/signed_cookies.py +9 -9
- svc_infra/storage/add.py +5 -8
- svc_infra/storage/backends/local.py +13 -21
- svc_infra/storage/backends/memory.py +4 -7
- svc_infra/storage/backends/s3.py +17 -36
- svc_infra/storage/base.py +2 -2
- svc_infra/storage/easy.py +4 -8
- svc_infra/storage/settings.py +16 -18
- svc_infra/testing/__init__.py +36 -39
- svc_infra/utils.py +169 -8
- svc_infra/webhooks/__init__.py +1 -1
- svc_infra/webhooks/add.py +17 -29
- svc_infra/webhooks/encryption.py +2 -2
- svc_infra/webhooks/fastapi.py +2 -4
- svc_infra/webhooks/router.py +3 -3
- svc_infra/webhooks/service.py +5 -6
- svc_infra/webhooks/signing.py +5 -5
- svc_infra/websocket/add.py +2 -3
- svc_infra/websocket/client.py +3 -2
- svc_infra/websocket/config.py +6 -18
- svc_infra/websocket/manager.py +9 -10
- {svc_infra-0.1.706.dist-info → svc_infra-1.1.0.dist-info}/METADATA +11 -5
- svc_infra-1.1.0.dist-info/RECORD +364 -0
- svc_infra/billing/service.py +0 -123
- svc_infra-0.1.706.dist-info/RECORD +0 -357
- {svc_infra-0.1.706.dist-info → svc_infra-1.1.0.dist-info}/LICENSE +0 -0
- {svc_infra-0.1.706.dist-info → svc_infra-1.1.0.dist-info}/WHEEL +0 -0
- {svc_infra-0.1.706.dist-info → svc_infra-1.1.0.dist-info}/entry_points.txt +0 -0
svc_infra/apf_payments/models.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from datetime import datetime
|
|
4
|
-
from typing import Optional
|
|
5
4
|
|
|
6
5
|
from sqlalchemy import (
|
|
7
6
|
JSON,
|
|
@@ -27,14 +26,10 @@ class PayCustomer(ModelBase):
|
|
|
27
26
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
28
27
|
|
|
29
28
|
# Tenant scoping
|
|
30
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
31
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
32
|
-
)
|
|
29
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
33
30
|
|
|
34
31
|
# Always typed to match the actual auth PK; FK is enforced at table level
|
|
35
|
-
user_id: Mapped[
|
|
36
|
-
user_id_type(), index=True, nullable=True
|
|
37
|
-
)
|
|
32
|
+
user_id: Mapped[str | None] = mapped_column(user_id_type(), index=True, nullable=True)
|
|
38
33
|
|
|
39
34
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
40
35
|
provider_customer_id: Mapped[str] = mapped_column(
|
|
@@ -59,13 +54,9 @@ class PayIntent(ModelBase):
|
|
|
59
54
|
|
|
60
55
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
61
56
|
|
|
62
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
63
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
64
|
-
)
|
|
57
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
65
58
|
|
|
66
|
-
user_id: Mapped[
|
|
67
|
-
user_id_type(), index=True, nullable=True
|
|
68
|
-
)
|
|
59
|
+
user_id: Mapped[str | None] = mapped_column(user_id_type(), index=True, nullable=True)
|
|
69
60
|
|
|
70
61
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
71
62
|
provider_intent_id: Mapped[str] = mapped_column(
|
|
@@ -74,13 +65,13 @@ class PayIntent(ModelBase):
|
|
|
74
65
|
amount: Mapped[int] = mapped_column(Numeric(18, 0), nullable=False) # minor units
|
|
75
66
|
currency: Mapped[str] = mapped_column(String(8), nullable=False)
|
|
76
67
|
status: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
77
|
-
client_secret: Mapped[
|
|
68
|
+
client_secret: Mapped[str | None] = mapped_column(String(255))
|
|
78
69
|
created_at: Mapped[datetime] = mapped_column(
|
|
79
70
|
DateTime(timezone=True),
|
|
80
71
|
server_default=text("CURRENT_TIMESTAMP"),
|
|
81
72
|
nullable=False,
|
|
82
73
|
)
|
|
83
|
-
confirmed_at: Mapped[
|
|
74
|
+
confirmed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
|
84
75
|
captured: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
85
76
|
|
|
86
77
|
__table_args__ = (
|
|
@@ -95,9 +86,7 @@ class PayEvent(ModelBase):
|
|
|
95
86
|
|
|
96
87
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
97
88
|
|
|
98
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
99
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
100
|
-
)
|
|
89
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
101
90
|
|
|
102
91
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
103
92
|
provider_event_id: Mapped[str] = mapped_column(
|
|
@@ -109,9 +98,7 @@ class PayEvent(ModelBase):
|
|
|
109
98
|
server_default=text("CURRENT_TIMESTAMP"),
|
|
110
99
|
nullable=False,
|
|
111
100
|
)
|
|
112
|
-
payload_json: Mapped[dict] = mapped_column(
|
|
113
|
-
JSON, nullable=False
|
|
114
|
-
) # compact JSON string
|
|
101
|
+
payload_json: Mapped[dict] = mapped_column(JSON, nullable=False) # compact JSON string
|
|
115
102
|
|
|
116
103
|
|
|
117
104
|
class LedgerEntry(ModelBase):
|
|
@@ -119,9 +106,7 @@ class LedgerEntry(ModelBase):
|
|
|
119
106
|
|
|
120
107
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
121
108
|
|
|
122
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
123
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
124
|
-
)
|
|
109
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
125
110
|
|
|
126
111
|
ts: Mapped[datetime] = mapped_column(
|
|
127
112
|
DateTime(timezone=True),
|
|
@@ -131,18 +116,12 @@ class LedgerEntry(ModelBase):
|
|
|
131
116
|
)
|
|
132
117
|
|
|
133
118
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
134
|
-
provider_ref: Mapped[
|
|
135
|
-
user_id: Mapped[
|
|
136
|
-
user_id_type(), index=True, nullable=True
|
|
137
|
-
)
|
|
119
|
+
provider_ref: Mapped[str | None] = mapped_column(String(128), index=True)
|
|
120
|
+
user_id: Mapped[str | None] = mapped_column(user_id_type(), index=True, nullable=True)
|
|
138
121
|
amount: Mapped[int] = mapped_column(Numeric(18, 0), nullable=False)
|
|
139
122
|
currency: Mapped[str] = mapped_column(String(8), nullable=False)
|
|
140
|
-
kind: Mapped[str] = mapped_column(
|
|
141
|
-
|
|
142
|
-
) # payment|refund|fee|payout...
|
|
143
|
-
status: Mapped[str] = mapped_column(
|
|
144
|
-
String(24), nullable=False
|
|
145
|
-
) # pending|posted|void
|
|
123
|
+
kind: Mapped[str] = mapped_column(String(24), nullable=False) # payment|refund|fee|payout...
|
|
124
|
+
status: Mapped[str] = mapped_column(String(24), nullable=False) # pending|posted|void
|
|
146
125
|
|
|
147
126
|
__table_args__ = (
|
|
148
127
|
user_fk_constraint("user_id", ondelete="SET NULL"),
|
|
@@ -163,24 +142,18 @@ class PayPaymentMethod(ModelBase):
|
|
|
163
142
|
|
|
164
143
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
165
144
|
|
|
166
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
167
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
168
|
-
)
|
|
145
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
169
146
|
|
|
170
|
-
user_id: Mapped[
|
|
171
|
-
user_id_type(), index=True, nullable=True
|
|
172
|
-
)
|
|
147
|
+
user_id: Mapped[str | None] = mapped_column(user_id_type(), index=True, nullable=True)
|
|
173
148
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
174
|
-
provider_customer_id: Mapped[str] = mapped_column(
|
|
175
|
-
String(128), index=True, nullable=False
|
|
176
|
-
)
|
|
149
|
+
provider_customer_id: Mapped[str] = mapped_column(String(128), index=True, nullable=False)
|
|
177
150
|
provider_method_id: Mapped[str] = mapped_column(
|
|
178
151
|
String(128), unique=True, index=True, nullable=False
|
|
179
152
|
)
|
|
180
|
-
brand: Mapped[
|
|
181
|
-
last4: Mapped[
|
|
182
|
-
exp_month: Mapped[
|
|
183
|
-
exp_year: Mapped[
|
|
153
|
+
brand: Mapped[str | None] = mapped_column(String(32))
|
|
154
|
+
last4: Mapped[str | None] = mapped_column(String(8))
|
|
155
|
+
exp_month: Mapped[int | None] = mapped_column(Numeric(2, 0))
|
|
156
|
+
exp_year: Mapped[int | None] = mapped_column(Numeric(4, 0))
|
|
184
157
|
is_default: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
185
158
|
created_at: Mapped[datetime] = mapped_column(
|
|
186
159
|
DateTime(timezone=True),
|
|
@@ -204,9 +177,7 @@ class PayProduct(ModelBase):
|
|
|
204
177
|
|
|
205
178
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
206
179
|
|
|
207
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
208
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
209
|
-
)
|
|
180
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
210
181
|
|
|
211
182
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
212
183
|
provider_product_id: Mapped[str] = mapped_column(
|
|
@@ -226,23 +197,17 @@ class PayPrice(ModelBase):
|
|
|
226
197
|
|
|
227
198
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
228
199
|
|
|
229
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
230
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
231
|
-
)
|
|
200
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
232
201
|
|
|
233
202
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
234
203
|
provider_price_id: Mapped[str] = mapped_column(
|
|
235
204
|
String(128), unique=True, index=True, nullable=False
|
|
236
205
|
)
|
|
237
|
-
provider_product_id: Mapped[str] = mapped_column(
|
|
238
|
-
String(128), index=True, nullable=False
|
|
239
|
-
)
|
|
206
|
+
provider_product_id: Mapped[str] = mapped_column(String(128), index=True, nullable=False)
|
|
240
207
|
currency: Mapped[str] = mapped_column(String(8), nullable=False)
|
|
241
|
-
unit_amount: Mapped[int] = mapped_column(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
interval: Mapped[Optional[str]] = mapped_column(String(16)) # month|year|week|day
|
|
245
|
-
trial_days: Mapped[Optional[int]] = mapped_column(Numeric(5, 0))
|
|
208
|
+
unit_amount: Mapped[int] = mapped_column(Numeric(18, 0), nullable=False) # minor units
|
|
209
|
+
interval: Mapped[str | None] = mapped_column(String(16)) # month|year|week|day
|
|
210
|
+
trial_days: Mapped[int | None] = mapped_column(Numeric(5, 0))
|
|
246
211
|
active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
247
212
|
created_at: Mapped[datetime] = mapped_column(
|
|
248
213
|
DateTime(timezone=True),
|
|
@@ -256,33 +221,21 @@ class PaySubscription(ModelBase):
|
|
|
256
221
|
|
|
257
222
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
258
223
|
|
|
259
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
260
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
261
|
-
)
|
|
224
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
262
225
|
|
|
263
|
-
user_id: Mapped[
|
|
264
|
-
user_id_type(), index=True, nullable=True
|
|
265
|
-
)
|
|
226
|
+
user_id: Mapped[str | None] = mapped_column(user_id_type(), index=True, nullable=True)
|
|
266
227
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
267
|
-
provider_customer_id: Mapped[str] = mapped_column(
|
|
268
|
-
String(128), index=True, nullable=False
|
|
269
|
-
)
|
|
228
|
+
provider_customer_id: Mapped[str] = mapped_column(String(128), index=True, nullable=False)
|
|
270
229
|
provider_subscription_id: Mapped[str] = mapped_column(
|
|
271
230
|
String(128), unique=True, index=True, nullable=False
|
|
272
231
|
)
|
|
273
|
-
provider_price_id: Mapped[str] = mapped_column(
|
|
274
|
-
String(128), index=True, nullable=False
|
|
275
|
-
)
|
|
232
|
+
provider_price_id: Mapped[str] = mapped_column(String(128), index=True, nullable=False)
|
|
276
233
|
status: Mapped[str] = mapped_column(
|
|
277
234
|
String(32), index=True, nullable=False
|
|
278
235
|
) # active|trialing|canceled|past_due|incomplete
|
|
279
236
|
quantity: Mapped[int] = mapped_column(Numeric(10, 0), default=1, nullable=False)
|
|
280
|
-
cancel_at_period_end: Mapped[bool] = mapped_column(
|
|
281
|
-
|
|
282
|
-
)
|
|
283
|
-
current_period_end: Mapped[Optional[datetime]] = mapped_column(
|
|
284
|
-
DateTime(timezone=True)
|
|
285
|
-
)
|
|
237
|
+
cancel_at_period_end: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
238
|
+
current_period_end: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
|
286
239
|
created_at: Mapped[datetime] = mapped_column(
|
|
287
240
|
DateTime(timezone=True),
|
|
288
241
|
server_default=text("CURRENT_TIMESTAMP"),
|
|
@@ -305,27 +258,21 @@ class PayInvoice(ModelBase):
|
|
|
305
258
|
|
|
306
259
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
307
260
|
|
|
308
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
309
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
310
|
-
)
|
|
261
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
311
262
|
|
|
312
|
-
user_id: Mapped[
|
|
313
|
-
user_id_type(), index=True, nullable=True
|
|
314
|
-
)
|
|
263
|
+
user_id: Mapped[str | None] = mapped_column(user_id_type(), index=True, nullable=True)
|
|
315
264
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
316
265
|
provider_invoice_id: Mapped[str] = mapped_column(
|
|
317
266
|
String(128), unique=True, index=True, nullable=False
|
|
318
267
|
)
|
|
319
|
-
provider_customer_id: Mapped[str] = mapped_column(
|
|
320
|
-
String(128), index=True, nullable=False
|
|
321
|
-
)
|
|
268
|
+
provider_customer_id: Mapped[str] = mapped_column(String(128), index=True, nullable=False)
|
|
322
269
|
status: Mapped[str] = mapped_column(
|
|
323
270
|
String(24), index=True, nullable=False
|
|
324
271
|
) # draft|open|paid|void|uncollectible
|
|
325
272
|
amount_due: Mapped[int] = mapped_column(Numeric(18, 0), nullable=False)
|
|
326
273
|
currency: Mapped[str] = mapped_column(String(8), nullable=False)
|
|
327
|
-
hosted_invoice_url: Mapped[
|
|
328
|
-
pdf_url: Mapped[
|
|
274
|
+
hosted_invoice_url: Mapped[str | None] = mapped_column(String(255))
|
|
275
|
+
pdf_url: Mapped[str | None] = mapped_column(String(255))
|
|
329
276
|
created_at: Mapped[datetime] = mapped_column(
|
|
330
277
|
DateTime(timezone=True),
|
|
331
278
|
server_default=text("CURRENT_TIMESTAMP"),
|
|
@@ -348,13 +295,9 @@ class PaySetupIntent(ModelBase):
|
|
|
348
295
|
|
|
349
296
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
350
297
|
|
|
351
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
352
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
353
|
-
)
|
|
298
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
354
299
|
|
|
355
|
-
user_id: Mapped[
|
|
356
|
-
user_id_type(), index=True, nullable=True
|
|
357
|
-
)
|
|
300
|
+
user_id: Mapped[str | None] = mapped_column(user_id_type(), index=True, nullable=True)
|
|
358
301
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
359
302
|
provider_setup_intent_id: Mapped[str] = mapped_column(
|
|
360
303
|
String(128), unique=True, index=True, nullable=False
|
|
@@ -362,7 +305,7 @@ class PaySetupIntent(ModelBase):
|
|
|
362
305
|
status: Mapped[str] = mapped_column(
|
|
363
306
|
String(32), index=True, nullable=False
|
|
364
307
|
) # requires_action|succeeded|canceled|processing
|
|
365
|
-
client_secret: Mapped[
|
|
308
|
+
client_secret: Mapped[str | None] = mapped_column(String(255))
|
|
366
309
|
created_at: Mapped[datetime] = mapped_column(
|
|
367
310
|
DateTime(timezone=True),
|
|
368
311
|
server_default=text("CURRENT_TIMESTAMP"),
|
|
@@ -380,22 +323,20 @@ class PayDispute(ModelBase):
|
|
|
380
323
|
|
|
381
324
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
382
325
|
|
|
383
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
384
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
385
|
-
)
|
|
326
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
386
327
|
|
|
387
328
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
388
329
|
provider_dispute_id: Mapped[str] = mapped_column(
|
|
389
330
|
String(128), unique=True, index=True, nullable=False
|
|
390
331
|
)
|
|
391
|
-
provider_charge_id: Mapped[
|
|
332
|
+
provider_charge_id: Mapped[str | None] = mapped_column(String(128), index=True)
|
|
392
333
|
amount: Mapped[int] = mapped_column(Numeric(18, 0), nullable=False)
|
|
393
334
|
currency: Mapped[str] = mapped_column(String(8), nullable=False)
|
|
394
|
-
reason: Mapped[
|
|
335
|
+
reason: Mapped[str | None] = mapped_column(String(64))
|
|
395
336
|
status: Mapped[str] = mapped_column(
|
|
396
337
|
String(32), index=True, nullable=False
|
|
397
338
|
) # needs_response|under_review|won|lost|warning_closed
|
|
398
|
-
evidence_due_by: Mapped[
|
|
339
|
+
evidence_due_by: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
|
399
340
|
created_at: Mapped[datetime] = mapped_column(
|
|
400
341
|
DateTime(timezone=True),
|
|
401
342
|
server_default=text("CURRENT_TIMESTAMP"),
|
|
@@ -408,9 +349,7 @@ class PayPayout(ModelBase):
|
|
|
408
349
|
|
|
409
350
|
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
410
351
|
|
|
411
|
-
tenant_id: Mapped[str] = mapped_column(
|
|
412
|
-
String(TENANT_ID_LEN), index=True, nullable=False
|
|
413
|
-
)
|
|
352
|
+
tenant_id: Mapped[str] = mapped_column(String(TENANT_ID_LEN), index=True, nullable=False)
|
|
414
353
|
|
|
415
354
|
provider: Mapped[str] = mapped_column(String(32), index=True, nullable=False)
|
|
416
355
|
provider_payout_id: Mapped[str] = mapped_column(
|
|
@@ -421,8 +360,8 @@ class PayPayout(ModelBase):
|
|
|
421
360
|
status: Mapped[str] = mapped_column(
|
|
422
361
|
String(32), index=True, nullable=False
|
|
423
362
|
) # pending|in_transit|paid|canceled|failed
|
|
424
|
-
arrival_date: Mapped[
|
|
425
|
-
type: Mapped[
|
|
363
|
+
arrival_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
|
364
|
+
type: Mapped[str | None] = mapped_column(String(32)) # bank_account|card|...
|
|
426
365
|
created_at: Mapped[datetime] = mapped_column(
|
|
427
366
|
DateTime(timezone=True),
|
|
428
367
|
server_default=text("CURRENT_TIMESTAMP"),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
|
-
from
|
|
5
|
-
from
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from datetime import UTC, date, datetime
|
|
6
|
+
from typing import Any, Literal, cast
|
|
6
7
|
|
|
7
8
|
from svc_infra.apf_payments.schemas import (
|
|
8
9
|
BalanceAmount,
|
|
@@ -70,19 +71,17 @@ def _ensure_utc_isoformat(value: Any) -> str | None:
|
|
|
70
71
|
if isinstance(value, datetime):
|
|
71
72
|
dt: datetime = value
|
|
72
73
|
if dt.tzinfo is None:
|
|
73
|
-
dt = dt.replace(tzinfo=
|
|
74
|
-
return dt.astimezone(
|
|
74
|
+
dt = dt.replace(tzinfo=UTC)
|
|
75
|
+
return dt.astimezone(UTC).isoformat()
|
|
75
76
|
if isinstance(value, date):
|
|
76
|
-
return datetime(
|
|
77
|
-
value.year, value.month, value.day, tzinfo=timezone.utc
|
|
78
|
-
).isoformat()
|
|
77
|
+
return datetime(value.year, value.month, value.day, tzinfo=UTC).isoformat()
|
|
79
78
|
try:
|
|
80
79
|
parsed = datetime.fromisoformat(str(value))
|
|
81
80
|
if parsed.tzinfo is None:
|
|
82
|
-
parsed = parsed.replace(tzinfo=
|
|
83
|
-
return parsed.astimezone(
|
|
81
|
+
parsed = parsed.replace(tzinfo=UTC)
|
|
82
|
+
return parsed.astimezone(UTC).isoformat()
|
|
84
83
|
except Exception:
|
|
85
|
-
return cast(str, str(value)) # Cast needed since value is Any
|
|
84
|
+
return cast("str", str(value)) # Cast needed since value is Any
|
|
86
85
|
|
|
87
86
|
|
|
88
87
|
def _customer_to_out(data: dict[str, Any]) -> CustomerOut:
|
|
@@ -116,9 +115,7 @@ def _payment_method_to_out(data: dict[str, Any]) -> PaymentMethodOut:
|
|
|
116
115
|
return PaymentMethodOut(
|
|
117
116
|
id=method_id,
|
|
118
117
|
provider="aiydan",
|
|
119
|
-
provider_customer_id=str(
|
|
120
|
-
data.get("provider_customer_id") or data.get("customer_id") or ""
|
|
121
|
-
),
|
|
118
|
+
provider_customer_id=str(data.get("provider_customer_id") or data.get("customer_id") or ""),
|
|
122
119
|
provider_method_id=method_id,
|
|
123
120
|
brand=card.get("brand") or data.get("brand"),
|
|
124
121
|
last4=card.get("last4") or data.get("last4"),
|
|
@@ -199,9 +196,7 @@ def _invoice_to_out(data: dict[str, Any]) -> InvoiceOut:
|
|
|
199
196
|
id=invoice_id,
|
|
200
197
|
provider="aiydan",
|
|
201
198
|
provider_invoice_id=invoice_id,
|
|
202
|
-
provider_customer_id=str(
|
|
203
|
-
data.get("provider_customer_id") or data.get("customer_id") or ""
|
|
204
|
-
),
|
|
199
|
+
provider_customer_id=str(data.get("provider_customer_id") or data.get("customer_id") or ""),
|
|
205
200
|
status=str(data.get("status", "")),
|
|
206
201
|
amount_due=int(data.get("amount_due", data.get("amount") or 0) or 0),
|
|
207
202
|
currency=str(data.get("currency", "")).upper(),
|
|
@@ -235,9 +230,7 @@ def _refund_to_out(data: dict[str, Any]) -> RefundOut:
|
|
|
235
230
|
provider="aiydan",
|
|
236
231
|
provider_refund_id=refund_id,
|
|
237
232
|
provider_payment_intent_id=str(
|
|
238
|
-
data.get("provider_payment_intent_id")
|
|
239
|
-
or data.get("payment_intent_id")
|
|
240
|
-
or ""
|
|
233
|
+
data.get("provider_payment_intent_id") or data.get("payment_intent_id") or ""
|
|
241
234
|
),
|
|
242
235
|
amount=int(data.get("amount", 0) or 0),
|
|
243
236
|
currency=str(data.get("currency", "")).upper(),
|
|
@@ -283,20 +276,16 @@ def _usage_record_to_out(data: dict[str, Any]) -> UsageRecordOut:
|
|
|
283
276
|
action_raw = data.get("action")
|
|
284
277
|
action: Literal["increment", "set"] | None = None
|
|
285
278
|
if action_raw in ("increment", "set"):
|
|
286
|
-
action = cast(Literal[
|
|
279
|
+
action = cast("Literal['increment', 'set']", action_raw)
|
|
287
280
|
return UsageRecordOut(
|
|
288
281
|
id=str(data.get("id")),
|
|
289
282
|
quantity=int(data.get("quantity", 0) or 0),
|
|
290
283
|
timestamp=data.get("timestamp"),
|
|
291
284
|
subscription_item=(
|
|
292
|
-
str(data.get("subscription_item"))
|
|
293
|
-
if data.get("subscription_item")
|
|
294
|
-
else None
|
|
285
|
+
str(data.get("subscription_item")) if data.get("subscription_item") else None
|
|
295
286
|
),
|
|
296
287
|
provider_price_id=(
|
|
297
|
-
str(data.get("provider_price_id"))
|
|
298
|
-
if data.get("provider_price_id")
|
|
299
|
-
else None
|
|
288
|
+
str(data.get("provider_price_id")) if data.get("provider_price_id") else None
|
|
300
289
|
),
|
|
301
290
|
action=action,
|
|
302
291
|
)
|
|
@@ -317,8 +306,7 @@ def _balance_snapshot_to_out(data: dict[str, Any]) -> BalanceSnapshotOut:
|
|
|
317
306
|
return out
|
|
318
307
|
if isinstance(side, dict):
|
|
319
308
|
return [
|
|
320
|
-
{"currency": str(cur).upper(), "amount": int(amt or 0)}
|
|
321
|
-
for cur, amt in side.items()
|
|
309
|
+
{"currency": str(cur).upper(), "amount": int(amt or 0)} for cur, amt in side.items()
|
|
322
310
|
]
|
|
323
311
|
return []
|
|
324
312
|
|
|
@@ -346,7 +334,7 @@ def _ensure_sequence(result: Any) -> Sequence[dict[str, Any]]:
|
|
|
346
334
|
|
|
347
335
|
def _ensure_list_response(
|
|
348
336
|
result: Any,
|
|
349
|
-
) ->
|
|
337
|
+
) -> tuple[Sequence[dict[str, Any]], str | None]:
|
|
350
338
|
if isinstance(result, tuple) and len(result) == 2:
|
|
351
339
|
items, cursor = result
|
|
352
340
|
if isinstance(items, Sequence) or items is None:
|
|
@@ -364,15 +352,13 @@ def _ensure_list_response(
|
|
|
364
352
|
class AiydanAdapter(ProviderAdapter):
|
|
365
353
|
name = "aiydan"
|
|
366
354
|
|
|
367
|
-
def __init__(self, *, client:
|
|
355
|
+
def __init__(self, *, client: Any | None = None):
|
|
368
356
|
settings = get_payments_settings()
|
|
369
357
|
cfg = settings.aiydan
|
|
370
358
|
if client is not None:
|
|
371
359
|
self._client = client
|
|
372
360
|
self._webhook_secret = (
|
|
373
|
-
cfg.webhook_secret.get_secret_value()
|
|
374
|
-
if cfg and cfg.webhook_secret
|
|
375
|
-
else None
|
|
361
|
+
cfg.webhook_secret.get_secret_value() if cfg and cfg.webhook_secret else None
|
|
376
362
|
)
|
|
377
363
|
return
|
|
378
364
|
if cfg is None:
|
|
@@ -392,44 +378,32 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
392
378
|
if cfg.base_url:
|
|
393
379
|
kwargs["base_url"] = cfg.base_url
|
|
394
380
|
self._client = client_class(**kwargs)
|
|
395
|
-
self._webhook_secret = (
|
|
396
|
-
cfg.webhook_secret.get_secret_value() if cfg.webhook_secret else None
|
|
397
|
-
)
|
|
381
|
+
self._webhook_secret = cfg.webhook_secret.get_secret_value() if cfg.webhook_secret else None
|
|
398
382
|
|
|
399
383
|
async def ensure_customer(self, data: CustomerUpsertIn) -> CustomerOut:
|
|
400
384
|
payload = data.model_dump(exclude_none=True)
|
|
401
385
|
result = await _maybe_await(self._client.ensure_customer(payload))
|
|
402
386
|
return _customer_to_out(result)
|
|
403
387
|
|
|
404
|
-
async def attach_payment_method(
|
|
405
|
-
self, data: PaymentMethodAttachIn
|
|
406
|
-
) -> PaymentMethodOut:
|
|
388
|
+
async def attach_payment_method(self, data: PaymentMethodAttachIn) -> PaymentMethodOut:
|
|
407
389
|
payload = data.model_dump(exclude_none=True)
|
|
408
390
|
result = await _maybe_await(self._client.attach_payment_method(payload))
|
|
409
391
|
return _payment_method_to_out(result)
|
|
410
392
|
|
|
411
|
-
async def list_payment_methods(
|
|
412
|
-
self
|
|
413
|
-
) -> list[PaymentMethodOut]:
|
|
414
|
-
result = await _maybe_await(
|
|
415
|
-
self._client.list_payment_methods(provider_customer_id)
|
|
416
|
-
)
|
|
393
|
+
async def list_payment_methods(self, provider_customer_id: str) -> list[PaymentMethodOut]:
|
|
394
|
+
result = await _maybe_await(self._client.list_payment_methods(provider_customer_id))
|
|
417
395
|
methods = _ensure_sequence(result)
|
|
418
396
|
return [_payment_method_to_out(method) for method in methods]
|
|
419
397
|
|
|
420
398
|
async def detach_payment_method(self, provider_method_id: str) -> PaymentMethodOut:
|
|
421
|
-
result = await _maybe_await(
|
|
422
|
-
self._client.detach_payment_method(provider_method_id)
|
|
423
|
-
)
|
|
399
|
+
result = await _maybe_await(self._client.detach_payment_method(provider_method_id))
|
|
424
400
|
return _payment_method_to_out(result)
|
|
425
401
|
|
|
426
402
|
async def set_default_payment_method(
|
|
427
403
|
self, provider_customer_id: str, provider_method_id: str
|
|
428
404
|
) -> PaymentMethodOut:
|
|
429
405
|
result = await _maybe_await(
|
|
430
|
-
self._client.set_default_payment_method(
|
|
431
|
-
provider_customer_id, provider_method_id
|
|
432
|
-
)
|
|
406
|
+
self._client.set_default_payment_method(provider_customer_id, provider_method_id)
|
|
433
407
|
)
|
|
434
408
|
return _payment_method_to_out(result)
|
|
435
409
|
|
|
@@ -441,9 +415,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
441
415
|
self, provider_method_id: str, data: PaymentMethodUpdateIn
|
|
442
416
|
) -> PaymentMethodOut:
|
|
443
417
|
payload = data.model_dump(exclude_none=True)
|
|
444
|
-
result = await _maybe_await(
|
|
445
|
-
self._client.update_payment_method(provider_method_id, payload)
|
|
446
|
-
)
|
|
418
|
+
result = await _maybe_await(self._client.update_payment_method(provider_method_id, payload))
|
|
447
419
|
return _payment_method_to_out(result)
|
|
448
420
|
|
|
449
421
|
async def create_product(self, data: ProductCreateIn) -> ProductOut:
|
|
@@ -464,13 +436,9 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
464
436
|
items, next_cursor = _ensure_list_response(result)
|
|
465
437
|
return [_product_to_out(item) for item in items], next_cursor
|
|
466
438
|
|
|
467
|
-
async def update_product(
|
|
468
|
-
self, provider_product_id: str, data: ProductUpdateIn
|
|
469
|
-
) -> ProductOut:
|
|
439
|
+
async def update_product(self, provider_product_id: str, data: ProductUpdateIn) -> ProductOut:
|
|
470
440
|
payload = data.model_dump(exclude_none=True)
|
|
471
|
-
result = await _maybe_await(
|
|
472
|
-
self._client.update_product(provider_product_id, payload)
|
|
473
|
-
)
|
|
441
|
+
result = await _maybe_await(self._client.update_product(provider_product_id, payload))
|
|
474
442
|
return _product_to_out(result)
|
|
475
443
|
|
|
476
444
|
async def create_price(self, data: PriceCreateIn) -> PriceOut:
|
|
@@ -501,13 +469,9 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
501
469
|
items, next_cursor = _ensure_list_response(result)
|
|
502
470
|
return [_price_to_out(item) for item in items], next_cursor
|
|
503
471
|
|
|
504
|
-
async def update_price(
|
|
505
|
-
self, provider_price_id: str, data: PriceUpdateIn
|
|
506
|
-
) -> PriceOut:
|
|
472
|
+
async def update_price(self, provider_price_id: str, data: PriceUpdateIn) -> PriceOut:
|
|
507
473
|
payload = data.model_dump(exclude_none=True)
|
|
508
|
-
result = await _maybe_await(
|
|
509
|
-
self._client.update_price(provider_price_id, payload)
|
|
510
|
-
)
|
|
474
|
+
result = await _maybe_await(self._client.update_price(provider_price_id, payload))
|
|
511
475
|
return _price_to_out(result)
|
|
512
476
|
|
|
513
477
|
async def create_subscription(self, data: SubscriptionCreateIn) -> SubscriptionOut:
|
|
@@ -533,9 +497,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
533
497
|
return _subscription_to_out(result)
|
|
534
498
|
|
|
535
499
|
async def get_subscription(self, provider_subscription_id: str) -> SubscriptionOut:
|
|
536
|
-
result = await _maybe_await(
|
|
537
|
-
self._client.get_subscription(provider_subscription_id)
|
|
538
|
-
)
|
|
500
|
+
result = await _maybe_await(self._client.get_subscription(provider_subscription_id))
|
|
539
501
|
return _subscription_to_out(result)
|
|
540
502
|
|
|
541
503
|
async def list_subscriptions(
|
|
@@ -630,9 +592,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
630
592
|
items, next_cursor = _ensure_list_response(result)
|
|
631
593
|
return [_invoice_line_item_to_out(item) for item in items], next_cursor
|
|
632
594
|
|
|
633
|
-
async def create_intent(
|
|
634
|
-
self, data: IntentCreateIn, *, user_id: str | None
|
|
635
|
-
) -> IntentOut:
|
|
595
|
+
async def create_intent(self, data: IntentCreateIn, *, user_id: str | None) -> IntentOut:
|
|
636
596
|
payload = data.model_dump(exclude_none=True)
|
|
637
597
|
if user_id is not None:
|
|
638
598
|
payload["user_id"] = user_id
|
|
@@ -649,21 +609,15 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
649
609
|
|
|
650
610
|
async def refund(self, provider_intent_id: str, data: RefundIn) -> IntentOut:
|
|
651
611
|
payload = data.model_dump(exclude_none=True)
|
|
652
|
-
result = await _maybe_await(
|
|
653
|
-
self._client.refund_intent(provider_intent_id, payload)
|
|
654
|
-
)
|
|
612
|
+
result = await _maybe_await(self._client.refund_intent(provider_intent_id, payload))
|
|
655
613
|
return _intent_to_out(result)
|
|
656
614
|
|
|
657
615
|
async def hydrate_intent(self, provider_intent_id: str) -> IntentOut:
|
|
658
616
|
result = await _maybe_await(self._client.get_intent(provider_intent_id))
|
|
659
617
|
return _intent_to_out(result)
|
|
660
618
|
|
|
661
|
-
async def capture_intent(
|
|
662
|
-
self
|
|
663
|
-
) -> IntentOut:
|
|
664
|
-
result = await _maybe_await(
|
|
665
|
-
self._client.capture_intent(provider_intent_id, amount=amount)
|
|
666
|
-
)
|
|
619
|
+
async def capture_intent(self, provider_intent_id: str, *, amount: int | None) -> IntentOut:
|
|
620
|
+
result = await _maybe_await(self._client.capture_intent(provider_intent_id, amount=amount))
|
|
667
621
|
return _intent_to_out(result)
|
|
668
622
|
|
|
669
623
|
async def list_intents(
|
|
@@ -723,9 +677,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
723
677
|
result = await _maybe_await(self._client.get_dispute(provider_dispute_id))
|
|
724
678
|
return _dispute_to_out(result)
|
|
725
679
|
|
|
726
|
-
async def submit_dispute_evidence(
|
|
727
|
-
self, provider_dispute_id: str, evidence: dict
|
|
728
|
-
) -> DisputeOut:
|
|
680
|
+
async def submit_dispute_evidence(self, provider_dispute_id: str, evidence: dict) -> DisputeOut:
|
|
729
681
|
result = await _maybe_await(
|
|
730
682
|
self._client.submit_dispute_evidence(provider_dispute_id, evidence)
|
|
731
683
|
)
|
|
@@ -742,9 +694,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
742
694
|
async def list_payouts(
|
|
743
695
|
self, *, limit: int, cursor: str | None
|
|
744
696
|
) -> tuple[list[PayoutOut], str | None]:
|
|
745
|
-
result = await _maybe_await(
|
|
746
|
-
self._client.list_payouts(limit=limit, cursor=cursor)
|
|
747
|
-
)
|
|
697
|
+
result = await _maybe_await(self._client.list_payouts(limit=limit, cursor=cursor))
|
|
748
698
|
items, next_cursor = _ensure_list_response(result)
|
|
749
699
|
return [_payout_to_out(item) for item in items], next_cursor
|
|
750
700
|
|
|
@@ -804,12 +754,8 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
804
754
|
next_action=NextAction(type=(result.get("next_action") or {}).get("type")),
|
|
805
755
|
)
|
|
806
756
|
|
|
807
|
-
async def confirm_setup_intent(
|
|
808
|
-
self
|
|
809
|
-
) -> SetupIntentOut:
|
|
810
|
-
result = await _maybe_await(
|
|
811
|
-
self._client.confirm_setup_intent(provider_setup_intent_id)
|
|
812
|
-
)
|
|
757
|
+
async def confirm_setup_intent(self, provider_setup_intent_id: str) -> SetupIntentOut:
|
|
758
|
+
result = await _maybe_await(self._client.confirm_setup_intent(provider_setup_intent_id))
|
|
813
759
|
return SetupIntentOut(
|
|
814
760
|
id=_coerce_id(result, "provider_setup_intent_id", "setup_intent_id", "id"),
|
|
815
761
|
provider="aiydan",
|
|
@@ -822,9 +768,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
822
768
|
)
|
|
823
769
|
|
|
824
770
|
async def get_setup_intent(self, provider_setup_intent_id: str) -> SetupIntentOut:
|
|
825
|
-
result = await _maybe_await(
|
|
826
|
-
self._client.get_setup_intent(provider_setup_intent_id)
|
|
827
|
-
)
|
|
771
|
+
result = await _maybe_await(self._client.get_setup_intent(provider_setup_intent_id))
|
|
828
772
|
return SetupIntentOut(
|
|
829
773
|
id=_coerce_id(result, "provider_setup_intent_id", "setup_intent_id", "id"),
|
|
830
774
|
provider="aiydan",
|
|
@@ -838,9 +782,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
838
782
|
|
|
839
783
|
async def resume_intent_after_action(self, provider_intent_id: str) -> IntentOut:
|
|
840
784
|
if hasattr(self._client, "resume_intent_after_action"):
|
|
841
|
-
result = await _maybe_await(
|
|
842
|
-
self._client.resume_intent_after_action(provider_intent_id)
|
|
843
|
-
)
|
|
785
|
+
result = await _maybe_await(self._client.resume_intent_after_action(provider_intent_id))
|
|
844
786
|
else:
|
|
845
787
|
result = await _maybe_await(self._client.get_intent(provider_intent_id))
|
|
846
788
|
return _intent_to_out(result)
|
|
@@ -864,7 +806,7 @@ class AiydanAdapter(ProviderAdapter):
|
|
|
864
806
|
items, next_cursor = _ensure_list_response(result)
|
|
865
807
|
return [_customer_to_out(item) for item in items], next_cursor
|
|
866
808
|
|
|
867
|
-
async def get_customer(self, provider_customer_id: str) ->
|
|
809
|
+
async def get_customer(self, provider_customer_id: str) -> CustomerOut | None:
|
|
868
810
|
result = await _maybe_await(self._client.get_customer(provider_customer_id))
|
|
869
811
|
if result is None:
|
|
870
812
|
return None
|