t402 1.6.0__tar.gz → 1.7.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.
- {t402-1.6.0 → t402-1.7.1}/PKG-INFO +1 -1
- {t402-1.6.0 → t402-1.7.1}/pyproject.toml +2 -1
- {t402-1.6.0 → t402-1.7.1}/src/t402/__init__.py +233 -3
- {t402-1.6.0 → t402-1.7.1}/src/t402/common.py +37 -8
- t402-1.7.1/src/t402/encoding.py +325 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/facilitator.py +1 -1
- t402-1.7.1/src/t402/fastapi/__init__.py +79 -0
- t402-1.7.1/src/t402/fastapi/dependencies.py +398 -0
- t402-1.7.1/src/t402/fastapi/middleware.py +754 -0
- t402-1.7.1/src/t402/schemes/__init__.py +125 -0
- t402-1.7.1/src/t402/schemes/evm/__init__.py +25 -0
- t402-1.7.1/src/t402/schemes/evm/exact/__init__.py +29 -0
- t402-1.7.1/src/t402/schemes/evm/exact/client.py +265 -0
- t402-1.7.1/src/t402/schemes/evm/exact/server.py +181 -0
- t402-1.7.1/src/t402/schemes/interfaces.py +401 -0
- t402-1.7.1/src/t402/schemes/registry.py +477 -0
- t402-1.7.1/src/t402/schemes/ton/__init__.py +22 -0
- t402-1.7.1/src/t402/schemes/ton/exact/__init__.py +27 -0
- t402-1.7.1/src/t402/schemes/ton/exact/client.py +343 -0
- t402-1.7.1/src/t402/schemes/ton/exact/server.py +201 -0
- t402-1.7.1/src/t402/schemes/tron/__init__.py +22 -0
- t402-1.7.1/src/t402/schemes/tron/exact/__init__.py +27 -0
- t402-1.7.1/src/t402/schemes/tron/exact/client.py +260 -0
- t402-1.7.1/src/t402/schemes/tron/exact/server.py +192 -0
- t402-1.7.1/src/t402/svm.py +1562 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/types.py +178 -8
- t402-1.7.1/tests/test_fastapi.py +430 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_paywall.py +1 -1
- t402-1.7.1/tests/test_schemes.py +1115 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_svm.py +438 -0
- t402-1.7.1/tests/test_v2_types.py +419 -0
- {t402-1.6.0 → t402-1.7.1}/uv.lock +1497 -1291
- t402-1.6.0/src/t402/encoding.py +0 -28
- t402-1.6.0/src/t402/fastapi/middleware.py +0 -219
- t402-1.6.0/src/t402/svm.py +0 -566
- t402-1.6.0/tests/flask_tests/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/.gitignore +0 -0
- {t402-1.6.0 → t402-1.7.1}/.python-version +0 -0
- {t402-1.6.0 → t402-1.7.1}/README.md +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/bridge/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/bridge/client.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/bridge/constants.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/bridge/router.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/bridge/scan.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/bridge/types.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/chains.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/cli.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/clients/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/clients/base.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/clients/httpx.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/clients/requests.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/erc4337/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/erc4337/accounts.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/erc4337/bundlers.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/erc4337/paymasters.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/erc4337/types.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/evm_paywall_template.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/exact.py +0 -0
- {t402-1.6.0/src/t402/fastapi → t402-1.7.1/src/t402/flask}/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/flask/middleware.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/mcp/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/mcp/constants.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/mcp/server.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/mcp/tools.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/mcp/types.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/networks.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/path.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/paywall.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/py.typed +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/svm_paywall_template.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/ton.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/ton_paywall_template.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/tron.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/wdk/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/wdk/chains.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/wdk/errors.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/wdk/signer.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/src/t402/wdk/types.py +0 -0
- {t402-1.6.0/src/t402/flask → t402-1.7.1/tests/clients}/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/clients/test_base.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/clients/test_httpx.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/clients/test_requests.py +0 -0
- {t402-1.6.0/tests/clients → t402-1.7.1/tests/fastapi_tests}/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/fastapi_tests/test_middleware.py +0 -0
- {t402-1.6.0/tests/fastapi_tests → t402-1.7.1/tests/flask_tests}/__init__.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/flask_tests/test_middleware.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_bridge.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_common.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_encoding.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_exact.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_mcp.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_ton.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_tron.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_types.py +0 -0
- {t402-1.6.0 → t402-1.7.1}/tests/test_wdk.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "t402"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "1.7.1"
|
|
4
4
|
description = "t402: An internet native payments protocol"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = { text = "Apache-2.0" }
|
|
@@ -42,6 +42,7 @@ build-backend = "hatchling.build"
|
|
|
42
42
|
dev = [
|
|
43
43
|
"pytest>=8.3.5",
|
|
44
44
|
"pytest-asyncio>=1.0.0",
|
|
45
|
+
"pytest-cov>=6.0.0",
|
|
45
46
|
"ruff>=0.11.9",
|
|
46
47
|
"solana>=0.35.0",
|
|
47
48
|
"solders>=0.21.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Package version
|
|
2
|
-
__version__ = "1.
|
|
2
|
+
__version__ = "1.6.2"
|
|
3
3
|
|
|
4
4
|
# Re-export commonly used items for convenience
|
|
5
5
|
from t402.common import (
|
|
@@ -16,8 +16,28 @@ from t402.networks import (
|
|
|
16
16
|
get_network_type,
|
|
17
17
|
)
|
|
18
18
|
from t402.types import (
|
|
19
|
+
# Protocol version constants
|
|
20
|
+
T402_VERSION,
|
|
21
|
+
T402_VERSION_V1,
|
|
22
|
+
T402_VERSION_V2,
|
|
23
|
+
Network,
|
|
24
|
+
# V1 Types (Legacy)
|
|
19
25
|
PaymentRequirements,
|
|
26
|
+
PaymentRequirementsV1,
|
|
20
27
|
PaymentPayload,
|
|
28
|
+
PaymentPayloadV1,
|
|
29
|
+
t402PaymentRequiredResponse,
|
|
30
|
+
t402PaymentRequiredResponseV1,
|
|
31
|
+
# V2 Types (Current)
|
|
32
|
+
ResourceInfo,
|
|
33
|
+
PaymentRequirementsV2,
|
|
34
|
+
PaymentRequiredV2,
|
|
35
|
+
PaymentPayloadV2,
|
|
36
|
+
PaymentResponseV2,
|
|
37
|
+
# Facilitator Types
|
|
38
|
+
SupportedKind,
|
|
39
|
+
SupportedResponse,
|
|
40
|
+
# Common Types
|
|
21
41
|
VerifyResponse,
|
|
22
42
|
SettleResponse,
|
|
23
43
|
TonAuthorization,
|
|
@@ -25,6 +45,31 @@ from t402.types import (
|
|
|
25
45
|
TronAuthorization,
|
|
26
46
|
TronPaymentPayload,
|
|
27
47
|
)
|
|
48
|
+
from t402.encoding import (
|
|
49
|
+
# Base64 utilities
|
|
50
|
+
safe_base64_encode,
|
|
51
|
+
safe_base64_decode,
|
|
52
|
+
is_valid_base64,
|
|
53
|
+
# Header name constants
|
|
54
|
+
HEADER_PAYMENT_SIGNATURE,
|
|
55
|
+
HEADER_PAYMENT_REQUIRED,
|
|
56
|
+
HEADER_PAYMENT_RESPONSE,
|
|
57
|
+
HEADER_X_PAYMENT,
|
|
58
|
+
HEADER_X_PAYMENT_RESPONSE,
|
|
59
|
+
# Encoding/Decoding functions
|
|
60
|
+
encode_payment_signature_header,
|
|
61
|
+
decode_payment_signature_header,
|
|
62
|
+
encode_payment_required_header,
|
|
63
|
+
decode_payment_required_header,
|
|
64
|
+
encode_payment_response_header,
|
|
65
|
+
decode_payment_response_header,
|
|
66
|
+
# Header detection utilities
|
|
67
|
+
get_payment_header_name,
|
|
68
|
+
get_payment_response_header_name,
|
|
69
|
+
detect_protocol_version_from_headers,
|
|
70
|
+
extract_payment_from_headers,
|
|
71
|
+
extract_payment_required_from_response,
|
|
72
|
+
)
|
|
28
73
|
from t402.facilitator import FacilitatorClient, FacilitatorConfig
|
|
29
74
|
from t402.exact import (
|
|
30
75
|
prepare_payment_header,
|
|
@@ -64,11 +109,15 @@ from t402.tron import (
|
|
|
64
109
|
is_testnet as is_tron_testnet,
|
|
65
110
|
)
|
|
66
111
|
from t402.svm import (
|
|
112
|
+
# Constants
|
|
67
113
|
SOLANA_MAINNET,
|
|
68
114
|
SOLANA_DEVNET,
|
|
69
115
|
SOLANA_TESTNET,
|
|
70
116
|
USDC_MAINNET_ADDRESS as SVM_USDC_MAINNET_ADDRESS,
|
|
71
117
|
USDC_DEVNET_ADDRESS as SVM_USDC_DEVNET_ADDRESS,
|
|
118
|
+
TOKEN_PROGRAM_ADDRESS as SVM_TOKEN_PROGRAM_ADDRESS,
|
|
119
|
+
TOKEN_2022_PROGRAM_ADDRESS as SVM_TOKEN_2022_PROGRAM_ADDRESS,
|
|
120
|
+
# Address/Network utilities
|
|
72
121
|
validate_svm_address,
|
|
73
122
|
get_usdc_address as get_svm_usdc_address,
|
|
74
123
|
get_network_config as get_svm_network_config,
|
|
@@ -80,6 +129,34 @@ from t402.svm import (
|
|
|
80
129
|
validate_transaction as validate_svm_transaction,
|
|
81
130
|
normalize_network as normalize_svm_network,
|
|
82
131
|
get_rpc_url as get_svm_rpc_url,
|
|
132
|
+
# Transaction utilities
|
|
133
|
+
decode_transaction as decode_svm_transaction,
|
|
134
|
+
decode_versioned_transaction,
|
|
135
|
+
encode_transaction as encode_svm_transaction,
|
|
136
|
+
get_transaction_fee_payer as get_svm_fee_payer,
|
|
137
|
+
get_token_payer_from_transaction as get_svm_token_payer,
|
|
138
|
+
parse_transfer_checked_instruction,
|
|
139
|
+
TransferDetails as SvmTransferDetails,
|
|
140
|
+
# Signer interfaces and implementations
|
|
141
|
+
ClientSvmSigner,
|
|
142
|
+
FacilitatorSvmSigner,
|
|
143
|
+
KeypairSvmSigner,
|
|
144
|
+
RpcSvmSigner,
|
|
145
|
+
# Scheme implementations
|
|
146
|
+
ExactSvmClientScheme,
|
|
147
|
+
ExactSvmServerScheme,
|
|
148
|
+
ExactSvmFacilitatorScheme,
|
|
149
|
+
# Factory functions
|
|
150
|
+
create_client_scheme as create_svm_client_scheme,
|
|
151
|
+
create_server_scheme as create_svm_server_scheme,
|
|
152
|
+
create_facilitator_scheme as create_svm_facilitator_scheme,
|
|
153
|
+
check_solana_available,
|
|
154
|
+
# Types
|
|
155
|
+
SvmAuthorization,
|
|
156
|
+
SvmPaymentPayload,
|
|
157
|
+
SvmVerifyMessageResult,
|
|
158
|
+
SvmTransactionConfirmation,
|
|
159
|
+
ExactSvmPayloadV2,
|
|
83
160
|
)
|
|
84
161
|
from t402.paywall import (
|
|
85
162
|
get_paywall_html,
|
|
@@ -168,6 +245,50 @@ from t402.wdk import (
|
|
|
168
245
|
BalanceError as WDKBalanceError,
|
|
169
246
|
WDKErrorCode,
|
|
170
247
|
)
|
|
248
|
+
from t402.schemes import (
|
|
249
|
+
# Interfaces
|
|
250
|
+
SchemeNetworkClient,
|
|
251
|
+
SchemeNetworkServer,
|
|
252
|
+
SchemeNetworkFacilitator,
|
|
253
|
+
BaseSchemeNetworkClient,
|
|
254
|
+
BaseSchemeNetworkServer,
|
|
255
|
+
BaseSchemeNetworkFacilitator,
|
|
256
|
+
# Registry
|
|
257
|
+
SchemeRegistry,
|
|
258
|
+
ClientSchemeRegistry,
|
|
259
|
+
ServerSchemeRegistry,
|
|
260
|
+
FacilitatorSchemeRegistry,
|
|
261
|
+
get_client_registry,
|
|
262
|
+
get_server_registry,
|
|
263
|
+
get_facilitator_registry,
|
|
264
|
+
reset_global_registries,
|
|
265
|
+
)
|
|
266
|
+
from t402.schemes.evm import (
|
|
267
|
+
ExactEvmClientScheme,
|
|
268
|
+
ExactEvmServerScheme,
|
|
269
|
+
EvmSigner,
|
|
270
|
+
)
|
|
271
|
+
from t402.schemes.ton import (
|
|
272
|
+
ExactTonClientScheme,
|
|
273
|
+
ExactTonServerScheme,
|
|
274
|
+
TonSigner,
|
|
275
|
+
)
|
|
276
|
+
from t402.schemes.tron import (
|
|
277
|
+
ExactTronClientScheme,
|
|
278
|
+
ExactTronServerScheme,
|
|
279
|
+
TronSigner,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
# FastAPI Integration
|
|
283
|
+
from t402.fastapi import (
|
|
284
|
+
PaymentMiddleware as FastAPIPaymentMiddleware,
|
|
285
|
+
PaymentConfig as FastAPIPaymentConfig,
|
|
286
|
+
PaymentDetails as FastAPIPaymentDetails,
|
|
287
|
+
PaymentRequired,
|
|
288
|
+
require_payment as fastapi_require_payment,
|
|
289
|
+
get_payment_details,
|
|
290
|
+
settle_payment,
|
|
291
|
+
)
|
|
171
292
|
|
|
172
293
|
def hello() -> str:
|
|
173
294
|
return "Hello from t402!"
|
|
@@ -179,6 +300,11 @@ __all__ = [
|
|
|
179
300
|
# Core
|
|
180
301
|
"hello",
|
|
181
302
|
"t402_VERSION",
|
|
303
|
+
# Protocol Version Constants
|
|
304
|
+
"T402_VERSION",
|
|
305
|
+
"T402_VERSION_V1",
|
|
306
|
+
"T402_VERSION_V2",
|
|
307
|
+
"Network",
|
|
182
308
|
# Common utilities
|
|
183
309
|
"parse_money",
|
|
184
310
|
"process_price_to_atomic_amount",
|
|
@@ -189,15 +315,52 @@ __all__ = [
|
|
|
189
315
|
"is_evm_network",
|
|
190
316
|
"is_svm_network",
|
|
191
317
|
"get_network_type",
|
|
192
|
-
# Types
|
|
318
|
+
# V1 Types (Legacy)
|
|
193
319
|
"PaymentRequirements",
|
|
320
|
+
"PaymentRequirementsV1",
|
|
194
321
|
"PaymentPayload",
|
|
322
|
+
"PaymentPayloadV1",
|
|
323
|
+
"t402PaymentRequiredResponse",
|
|
324
|
+
"t402PaymentRequiredResponseV1",
|
|
325
|
+
# V2 Types (Current)
|
|
326
|
+
"ResourceInfo",
|
|
327
|
+
"PaymentRequirementsV2",
|
|
328
|
+
"PaymentRequiredV2",
|
|
329
|
+
"PaymentPayloadV2",
|
|
330
|
+
"PaymentResponseV2",
|
|
331
|
+
# Facilitator Types
|
|
332
|
+
"SupportedKind",
|
|
333
|
+
"SupportedResponse",
|
|
334
|
+
# Common Types
|
|
195
335
|
"VerifyResponse",
|
|
196
336
|
"SettleResponse",
|
|
197
337
|
"TonAuthorization",
|
|
198
338
|
"TonPaymentPayload",
|
|
199
339
|
"TronAuthorization",
|
|
200
340
|
"TronPaymentPayload",
|
|
341
|
+
# Encoding utilities
|
|
342
|
+
"safe_base64_encode",
|
|
343
|
+
"safe_base64_decode",
|
|
344
|
+
"is_valid_base64",
|
|
345
|
+
# Header constants
|
|
346
|
+
"HEADER_PAYMENT_SIGNATURE",
|
|
347
|
+
"HEADER_PAYMENT_REQUIRED",
|
|
348
|
+
"HEADER_PAYMENT_RESPONSE",
|
|
349
|
+
"HEADER_X_PAYMENT",
|
|
350
|
+
"HEADER_X_PAYMENT_RESPONSE",
|
|
351
|
+
# Header encoding/decoding
|
|
352
|
+
"encode_payment_signature_header",
|
|
353
|
+
"decode_payment_signature_header",
|
|
354
|
+
"encode_payment_required_header",
|
|
355
|
+
"decode_payment_required_header",
|
|
356
|
+
"encode_payment_response_header",
|
|
357
|
+
"decode_payment_response_header",
|
|
358
|
+
# Header detection
|
|
359
|
+
"get_payment_header_name",
|
|
360
|
+
"get_payment_response_header_name",
|
|
361
|
+
"detect_protocol_version_from_headers",
|
|
362
|
+
"extract_payment_from_headers",
|
|
363
|
+
"extract_payment_required_from_response",
|
|
201
364
|
# Facilitator
|
|
202
365
|
"FacilitatorClient",
|
|
203
366
|
"FacilitatorConfig",
|
|
@@ -235,12 +398,15 @@ __all__ = [
|
|
|
235
398
|
"parse_tron_amount",
|
|
236
399
|
"format_tron_amount",
|
|
237
400
|
"is_tron_testnet",
|
|
238
|
-
# SVM (Solana) utilities
|
|
401
|
+
# SVM (Solana) utilities - Constants
|
|
239
402
|
"SOLANA_MAINNET",
|
|
240
403
|
"SOLANA_DEVNET",
|
|
241
404
|
"SOLANA_TESTNET",
|
|
242
405
|
"SVM_USDC_MAINNET_ADDRESS",
|
|
243
406
|
"SVM_USDC_DEVNET_ADDRESS",
|
|
407
|
+
"SVM_TOKEN_PROGRAM_ADDRESS",
|
|
408
|
+
"SVM_TOKEN_2022_PROGRAM_ADDRESS",
|
|
409
|
+
# SVM - Address/Network utilities
|
|
244
410
|
"validate_svm_address",
|
|
245
411
|
"get_svm_usdc_address",
|
|
246
412
|
"get_svm_network_config",
|
|
@@ -252,6 +418,34 @@ __all__ = [
|
|
|
252
418
|
"validate_svm_transaction",
|
|
253
419
|
"normalize_svm_network",
|
|
254
420
|
"get_svm_rpc_url",
|
|
421
|
+
# SVM - Transaction utilities
|
|
422
|
+
"decode_svm_transaction",
|
|
423
|
+
"decode_versioned_transaction",
|
|
424
|
+
"encode_svm_transaction",
|
|
425
|
+
"get_svm_fee_payer",
|
|
426
|
+
"get_svm_token_payer",
|
|
427
|
+
"parse_transfer_checked_instruction",
|
|
428
|
+
"SvmTransferDetails",
|
|
429
|
+
# SVM - Signer interfaces
|
|
430
|
+
"ClientSvmSigner",
|
|
431
|
+
"FacilitatorSvmSigner",
|
|
432
|
+
"KeypairSvmSigner",
|
|
433
|
+
"RpcSvmSigner",
|
|
434
|
+
# SVM - Scheme implementations
|
|
435
|
+
"ExactSvmClientScheme",
|
|
436
|
+
"ExactSvmServerScheme",
|
|
437
|
+
"ExactSvmFacilitatorScheme",
|
|
438
|
+
# SVM - Factory functions
|
|
439
|
+
"create_svm_client_scheme",
|
|
440
|
+
"create_svm_server_scheme",
|
|
441
|
+
"create_svm_facilitator_scheme",
|
|
442
|
+
"check_solana_available",
|
|
443
|
+
# SVM - Types
|
|
444
|
+
"SvmAuthorization",
|
|
445
|
+
"SvmPaymentPayload",
|
|
446
|
+
"SvmVerifyMessageResult",
|
|
447
|
+
"SvmTransactionConfirmation",
|
|
448
|
+
"ExactSvmPayloadV2",
|
|
255
449
|
# Paywall
|
|
256
450
|
"get_paywall_html",
|
|
257
451
|
"get_paywall_template",
|
|
@@ -324,4 +518,40 @@ __all__ = [
|
|
|
324
518
|
"SigningError",
|
|
325
519
|
"WDKBalanceError",
|
|
326
520
|
"WDKErrorCode",
|
|
521
|
+
# Scheme Interfaces
|
|
522
|
+
"SchemeNetworkClient",
|
|
523
|
+
"SchemeNetworkServer",
|
|
524
|
+
"SchemeNetworkFacilitator",
|
|
525
|
+
"BaseSchemeNetworkClient",
|
|
526
|
+
"BaseSchemeNetworkServer",
|
|
527
|
+
"BaseSchemeNetworkFacilitator",
|
|
528
|
+
# Scheme Registry
|
|
529
|
+
"SchemeRegistry",
|
|
530
|
+
"ClientSchemeRegistry",
|
|
531
|
+
"ServerSchemeRegistry",
|
|
532
|
+
"FacilitatorSchemeRegistry",
|
|
533
|
+
"get_client_registry",
|
|
534
|
+
"get_server_registry",
|
|
535
|
+
"get_facilitator_registry",
|
|
536
|
+
"reset_global_registries",
|
|
537
|
+
# EVM Schemes
|
|
538
|
+
"ExactEvmClientScheme",
|
|
539
|
+
"ExactEvmServerScheme",
|
|
540
|
+
"EvmSigner",
|
|
541
|
+
# TON Schemes
|
|
542
|
+
"ExactTonClientScheme",
|
|
543
|
+
"ExactTonServerScheme",
|
|
544
|
+
"TonSigner",
|
|
545
|
+
# TRON Schemes
|
|
546
|
+
"ExactTronClientScheme",
|
|
547
|
+
"ExactTronServerScheme",
|
|
548
|
+
"TronSigner",
|
|
549
|
+
# FastAPI Integration
|
|
550
|
+
"FastAPIPaymentMiddleware",
|
|
551
|
+
"FastAPIPaymentConfig",
|
|
552
|
+
"FastAPIPaymentDetails",
|
|
553
|
+
"PaymentRequired",
|
|
554
|
+
"fastapi_require_payment",
|
|
555
|
+
"get_payment_details",
|
|
556
|
+
"settle_payment",
|
|
327
557
|
]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from decimal import Decimal
|
|
2
|
-
from typing import List, Optional
|
|
2
|
+
from typing import List, Optional, Union
|
|
3
3
|
|
|
4
4
|
from t402.chains import (
|
|
5
5
|
get_chain_id,
|
|
@@ -9,7 +9,15 @@ from t402.chains import (
|
|
|
9
9
|
get_default_token_address,
|
|
10
10
|
)
|
|
11
11
|
from t402.networks import is_ton_network, is_tron_network
|
|
12
|
-
from t402.types import
|
|
12
|
+
from t402.types import (
|
|
13
|
+
Price,
|
|
14
|
+
TokenAmount,
|
|
15
|
+
PaymentRequirementsV1,
|
|
16
|
+
PaymentRequirementsV2,
|
|
17
|
+
PaymentPayloadV1,
|
|
18
|
+
PaymentPayloadV2,
|
|
19
|
+
T402_VERSION,
|
|
20
|
+
)
|
|
13
21
|
|
|
14
22
|
|
|
15
23
|
def parse_money(amount: str | int, address: str, network: str) -> int:
|
|
@@ -147,23 +155,44 @@ def get_usdc_address(chain_id: int | str) -> str:
|
|
|
147
155
|
|
|
148
156
|
|
|
149
157
|
def find_matching_payment_requirements(
|
|
150
|
-
payment_requirements: List[
|
|
151
|
-
payment:
|
|
152
|
-
) -> Optional[
|
|
158
|
+
payment_requirements: List[Union[PaymentRequirementsV1, PaymentRequirementsV2]],
|
|
159
|
+
payment: Union[PaymentPayloadV1, PaymentPayloadV2, dict],
|
|
160
|
+
) -> Optional[Union[PaymentRequirementsV1, PaymentRequirementsV2]]:
|
|
153
161
|
"""
|
|
154
162
|
Finds the matching payment requirements for the given payment.
|
|
155
163
|
|
|
164
|
+
Supports both V1 and V2 payment formats.
|
|
165
|
+
|
|
156
166
|
Args:
|
|
157
167
|
payment_requirements: The payment requirements to search through
|
|
158
|
-
payment: The payment to match against
|
|
168
|
+
payment: The payment to match against (V1, V2, or dict)
|
|
159
169
|
|
|
160
170
|
Returns:
|
|
161
171
|
The matching payment requirements or None if no match is found
|
|
162
172
|
"""
|
|
173
|
+
# Handle dict input
|
|
174
|
+
if isinstance(payment, dict):
|
|
175
|
+
payment_scheme = payment.get("scheme")
|
|
176
|
+
payment_network = payment.get("network")
|
|
177
|
+
# V2 format uses "accepted" field
|
|
178
|
+
if "accepted" in payment:
|
|
179
|
+
accepted = payment["accepted"]
|
|
180
|
+
payment_scheme = accepted.get("scheme")
|
|
181
|
+
payment_network = accepted.get("network")
|
|
182
|
+
elif hasattr(payment, "accepted"):
|
|
183
|
+
# V2 PaymentPayload
|
|
184
|
+
payment_scheme = payment.accepted.scheme
|
|
185
|
+
payment_network = payment.accepted.network
|
|
186
|
+
else:
|
|
187
|
+
# V1 PaymentPayload
|
|
188
|
+
payment_scheme = payment.scheme
|
|
189
|
+
payment_network = payment.network
|
|
190
|
+
|
|
163
191
|
for req in payment_requirements:
|
|
164
|
-
if req.scheme ==
|
|
192
|
+
if req.scheme == payment_scheme and req.network == payment_network:
|
|
165
193
|
return req
|
|
166
194
|
return None
|
|
167
195
|
|
|
168
196
|
|
|
169
|
-
|
|
197
|
+
# Re-export version constant for backward compatibility
|
|
198
|
+
t402_VERSION = T402_VERSION
|