solana-pay-kit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- solana_pay_kit-0.1.0/.gitignore +42 -0
- solana_pay_kit-0.1.0/Justfile +31 -0
- solana_pay_kit-0.1.0/PKG-INFO +542 -0
- solana_pay_kit-0.1.0/README.md +510 -0
- solana_pay_kit-0.1.0/conformance_runner.py +682 -0
- solana_pay_kit-0.1.0/docs/snippets/charge.client.py +22 -0
- solana_pay_kit-0.1.0/docs/snippets/charge.server.py +33 -0
- solana_pay_kit-0.1.0/docs/snippets/session.server.py +59 -0
- solana_pay_kit-0.1.0/docs/snippets/upto.server.py +37 -0
- solana_pay_kit-0.1.0/examples/django/views.py +61 -0
- solana_pay_kit-0.1.0/examples/fastapi/app.py +68 -0
- solana_pay_kit-0.1.0/examples/flask/app.py +84 -0
- solana_pay_kit-0.1.0/examples/playground_api/README.md +41 -0
- solana_pay_kit-0.1.0/examples/playground_api/__init__.py +0 -0
- solana_pay_kit-0.1.0/examples/playground_api/app.py +245 -0
- solana_pay_kit-0.1.0/examples/playground_api/discovery.py +196 -0
- solana_pay_kit-0.1.0/examples/playground_api/docs.py +82 -0
- solana_pay_kit-0.1.0/examples/playground_api/sandbox.py +114 -0
- solana_pay_kit-0.1.0/examples/playground_api/sessions.py +160 -0
- solana_pay_kit-0.1.0/examples/simple-server/README.md +24 -0
- solana_pay_kit-0.1.0/examples/simple-server/server.py +81 -0
- solana_pay_kit-0.1.0/examples/x402-client/main.py +54 -0
- solana_pay_kit-0.1.0/protocol_conformance_runner.py +284 -0
- solana_pay_kit-0.1.0/pydoc-markdown.yml +32 -0
- solana_pay_kit-0.1.0/pyproject.toml +134 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/__init__.py +135 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_middleware.py +417 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/__init__.py +48 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/currency.py +82 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/errors.py +178 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/mints.py +80 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/network.py +67 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/network_check.py +55 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/paymentchannels.py +554 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/protocol.py +19 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/rpc.py +204 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/solana.py +406 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/stablecoin.py +17 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/store.py +189 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/_paycore/transaction.py +52 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/config.py +433 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/django.py +369 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/errors.py +94 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/fastapi.py +389 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/fee.py +43 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/flask.py +292 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/gate.py +332 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/kms.py +40 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/operator.py +81 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/payment.py +28 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/preflight.py +226 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/price.py +127 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/pricing.py +123 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/__init__.py +7 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/__init__.py +426 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/_paymentchannels.py +51 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/client/__init__.py +86 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/client/charge.py +424 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/client/http_stream.py +371 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/client/payment_channels.py +491 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/client/session.py +447 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/client/session_consumer.py +153 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/client/transport.py +90 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/core/__init__.py +3 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/core/base64url.py +40 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/core/challenge.py +32 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/core/expires.py +35 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/core/headers.py +411 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/core/json.py +200 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/core/types.py +204 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/intents/__init__.py +69 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/intents/charge.py +67 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/intents/session.py +997 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/__init__.py +76 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/_tx_decode.py +545 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/_verify.py +666 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/charge.py +678 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/defaults.py +39 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/html/__init__.py +3 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/html/service_worker.gen.js +1 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/html/template.gen.html +173 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/middleware.py +83 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/payment_page.py +139 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session.py +743 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session_lifecycle.py +106 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session_method.py +940 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session_onchain.py +578 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session_routes.py +218 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session_store.py +382 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session_stream.py +136 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/mpp/server/session_voucher.py +379 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/__init__.py +7 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/__init__.py +7 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/accounts/__init__.py +11 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/accounts/channel.py +194 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/accounts/closedChannel.py +88 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/errors/__init__.py +23 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/errors/paymentChannels.py +693 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/__init__.py +8 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/distribute.py +81 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/emitEvent.py +46 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/finalize.py +34 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/open.py +89 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/requestClose.py +36 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/settle.py +36 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/settleAndFinalize.py +51 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/topUp.py +57 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/instructions/withdrawPayer.py +44 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/pdas/index.py +25 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/program_id.py +11 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/shared/__init__.py +8 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/shared/extension.py +280 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/__init__.py +33 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/accountDiscriminator.py +87 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/channelStatus.py +115 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/distributeArgs.py +51 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/distributionEntry.py +59 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/openArgs.py +72 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/opened.py +52 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/payoutBeneficiary.py +115 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/payoutRedirected.py +81 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/redirectReason.py +143 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/settleAndFinalizeArgs.py +50 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/settlementWatermarks.py +57 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/topUpArgs.py +50 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/programs/paymentchannels/types/voucherArgs.py +66 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/__init__.py +545 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/client/__init__.py +28 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/client/exact/__init__.py +29 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/client/exact/payment.py +728 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/client/exact/transport.py +141 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/client/upto/__init__.py +21 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/client/upto/payment.py +199 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/exact/__init__.py +1 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/exact/extensions.py +185 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/exact/legacy.py +89 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/exact/types.py +113 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/exact/verify.py +348 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/upto/__init__.py +624 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/upto/types.py +154 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/protocols/x402/upto/verify.py +187 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/signer.py +364 -0
- solana_pay_kit-0.1.0/src/solana_pay_kit/usage.py +182 -0
- solana_pay_kit-0.1.0/tests/__init__.py +0 -0
- solana_pay_kit-0.1.0/tests/conftest.py +48 -0
- solana_pay_kit-0.1.0/tests/test_base64url.py +57 -0
- solana_pay_kit-0.1.0/tests/test_canonical_json.py +150 -0
- solana_pay_kit-0.1.0/tests/test_challenge.py +73 -0
- solana_pay_kit-0.1.0/tests/test_client_charge.py +596 -0
- solana_pay_kit-0.1.0/tests/test_client_transport.py +148 -0
- solana_pay_kit-0.1.0/tests/test_cross_route_replay.py +211 -0
- solana_pay_kit-0.1.0/tests/test_errors.py +147 -0
- solana_pay_kit-0.1.0/tests/test_expires.py +132 -0
- solana_pay_kit-0.1.0/tests/test_headers.py +519 -0
- solana_pay_kit-0.1.0/tests/test_http_stream.py +343 -0
- solana_pay_kit-0.1.0/tests/test_intents.py +134 -0
- solana_pay_kit-0.1.0/tests/test_middleware.py +185 -0
- solana_pay_kit-0.1.0/tests/test_mpp_helpers.py +478 -0
- solana_pay_kit-0.1.0/tests/test_network_check.py +75 -0
- solana_pay_kit-0.1.0/tests/test_paymentchannels.py +306 -0
- solana_pay_kit-0.1.0/tests/test_pk_config.py +368 -0
- solana_pay_kit-0.1.0/tests/test_pk_frameworks.py +371 -0
- solana_pay_kit-0.1.0/tests/test_pk_middleware.py +442 -0
- solana_pay_kit-0.1.0/tests/test_pk_mpp_adapter.py +337 -0
- solana_pay_kit-0.1.0/tests/test_pk_pricing_helpers.py +227 -0
- solana_pay_kit-0.1.0/tests/test_pk_signer_operator.py +291 -0
- solana_pay_kit-0.1.0/tests/test_pk_value_objects.py +381 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_client.py +906 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_extensions.py +274 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_legacy.py +409 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_settle.py +468 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_upto_django.py +110 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_upto_fastapi.py +117 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_upto_flask.py +87 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_upto_settle.py +483 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_upto_usage.py +128 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_upto_verifier.py +293 -0
- solana_pay_kit-0.1.0/tests/test_pk_x402_verifier.py +569 -0
- solana_pay_kit-0.1.0/tests/test_playground_api.py +77 -0
- solana_pay_kit-0.1.0/tests/test_rpc_contract.py +27 -0
- solana_pay_kit-0.1.0/tests/test_rpc_methods.py +216 -0
- solana_pay_kit-0.1.0/tests/test_rpc_send_validation.py +72 -0
- solana_pay_kit-0.1.0/tests/test_server.py +2455 -0
- solana_pay_kit-0.1.0/tests/test_server_defaults.py +49 -0
- solana_pay_kit-0.1.0/tests/test_server_html.py +244 -0
- solana_pay_kit-0.1.0/tests/test_server_v0_transactions.py +255 -0
- solana_pay_kit-0.1.0/tests/test_session_client.py +481 -0
- solana_pay_kit-0.1.0/tests/test_session_consumer.py +258 -0
- solana_pay_kit-0.1.0/tests/test_session_e2e_surfnet.py +142 -0
- solana_pay_kit-0.1.0/tests/test_session_intent.py +653 -0
- solana_pay_kit-0.1.0/tests/test_session_lifecycle.py +103 -0
- solana_pay_kit-0.1.0/tests/test_session_method.py +931 -0
- solana_pay_kit-0.1.0/tests/test_session_onchain.py +581 -0
- solana_pay_kit-0.1.0/tests/test_session_payment_channels.py +409 -0
- solana_pay_kit-0.1.0/tests/test_session_routes.py +322 -0
- solana_pay_kit-0.1.0/tests/test_session_server.py +752 -0
- solana_pay_kit-0.1.0/tests/test_session_settlement.py +666 -0
- solana_pay_kit-0.1.0/tests/test_session_store.py +310 -0
- solana_pay_kit-0.1.0/tests/test_session_stream.py +139 -0
- solana_pay_kit-0.1.0/tests/test_session_voucher.py +514 -0
- solana_pay_kit-0.1.0/tests/test_solana_protocol.py +376 -0
- solana_pay_kit-0.1.0/tests/test_store.py +176 -0
- solana_pay_kit-0.1.0/tests/test_types.py +163 -0
- solana_pay_kit-0.1.0/uv.lock +2004 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
.env
|
|
4
|
+
*.tsbuildinfo
|
|
5
|
+
|
|
6
|
+
# Coverage
|
|
7
|
+
coverage/
|
|
8
|
+
*.lcov
|
|
9
|
+
go/coverage.out
|
|
10
|
+
luacov.stats.out
|
|
11
|
+
luacov.report.out
|
|
12
|
+
|
|
13
|
+
# Generated HTML payment link assets (built from html/)
|
|
14
|
+
# Rust/Go/Lua gen files are committed (needed for cargo publish / go get).
|
|
15
|
+
# TypeScript gen file is gitignored (npm publishes dist/).
|
|
16
|
+
typescript/packages/mpp/src/server/html-assets.gen.ts
|
|
17
|
+
|
|
18
|
+
# Rust
|
|
19
|
+
target/
|
|
20
|
+
Cargo.lock
|
|
21
|
+
.surfpool
|
|
22
|
+
.DS_Store
|
|
23
|
+
.npm-pack/
|
|
24
|
+
DUMP.md
|
|
25
|
+
package/
|
|
26
|
+
__pycache__/
|
|
27
|
+
.coverage
|
|
28
|
+
.venv/
|
|
29
|
+
*.pyc
|
|
30
|
+
.claude/
|
|
31
|
+
.gocache
|
|
32
|
+
.build/
|
|
33
|
+
go/build/
|
|
34
|
+
go/playground-api
|
|
35
|
+
|
|
36
|
+
# Generated API docs — see `just docs`. Single tree at the repo root;
|
|
37
|
+
# each language emits markdown into `docs/api/<lang>/`.
|
|
38
|
+
docs/api/
|
|
39
|
+
rust/target/doc-json/
|
|
40
|
+
*.xcuserstate
|
|
41
|
+
*.xcuserstate
|
|
42
|
+
coverage.out
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
set shell := ["bash", "-uc"]
|
|
2
|
+
|
|
3
|
+
default:
|
|
4
|
+
@just --list
|
|
5
|
+
|
|
6
|
+
# Install the Python SDK with dev + framework extras.
|
|
7
|
+
install:
|
|
8
|
+
pip install -e '.[dev,fastapi,flask,django]'
|
|
9
|
+
|
|
10
|
+
# Run the Python unit test suite.
|
|
11
|
+
test:
|
|
12
|
+
pytest
|
|
13
|
+
|
|
14
|
+
# Lint with ruff.
|
|
15
|
+
lint:
|
|
16
|
+
ruff check src tests
|
|
17
|
+
|
|
18
|
+
# Format with ruff.
|
|
19
|
+
fmt:
|
|
20
|
+
ruff format src tests
|
|
21
|
+
|
|
22
|
+
# Type-check with pyright.
|
|
23
|
+
typecheck:
|
|
24
|
+
pyright
|
|
25
|
+
|
|
26
|
+
# Run tests with the 90% line-coverage gate.
|
|
27
|
+
test-cover:
|
|
28
|
+
pytest --cov=pay_kit --cov-report=term-missing --cov-fail-under=90 --ignore=tests/test_server_html.py
|
|
29
|
+
|
|
30
|
+
# Run all local Python gates.
|
|
31
|
+
check: lint typecheck test-cover
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: solana-pay-kit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Solana payment method for the Machine Payments Protocol
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: anchorpy>=0.21
|
|
8
|
+
Requires-Dist: borsh-construct>=0.1
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Requires-Dist: pydantic-settings>=2
|
|
11
|
+
Requires-Dist: pydantic>=2
|
|
12
|
+
Requires-Dist: solana>=0.35
|
|
13
|
+
Requires-Dist: solders>=0.22
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pydoc-markdown>=4.8; extra == 'dev'
|
|
16
|
+
Requires-Dist: pyright>=1.1; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
20
|
+
Requires-Dist: ruff>=0.8; extra == 'dev'
|
|
21
|
+
Provides-Extra: django
|
|
22
|
+
Requires-Dist: django>=4.2; extra == 'django'
|
|
23
|
+
Provides-Extra: fastapi
|
|
24
|
+
Requires-Dist: fastapi>=0.110; extra == 'fastapi'
|
|
25
|
+
Provides-Extra: flask
|
|
26
|
+
Requires-Dist: flask>=3; extra == 'flask'
|
|
27
|
+
Provides-Extra: playground
|
|
28
|
+
Requires-Dist: fastapi>=0.110; extra == 'playground'
|
|
29
|
+
Requires-Dist: uvicorn>=0.30; extra == 'playground'
|
|
30
|
+
Requires-Dist: yfinance>=0.2.40; extra == 'playground'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
<div align="center">
|
|
34
|
+
<picture>
|
|
35
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/solana-foundation/pay-kit/raw/main/docs/assets/banner-python-dark.png">
|
|
36
|
+
<source media="(prefers-color-scheme: light)" srcset="https://github.com/solana-foundation/pay-kit/raw/main/docs/assets/banner-python-light.png">
|
|
37
|
+
<img alt="Solana pay-kit — Python" width="100%" style="border-top-left-radius: 8px; border-top-right-radius: 8px; margin-bottom: 16px;" src="https://github.com/solana-foundation/pay-kit/raw/main/docs/assets/banner-python-light.png">
|
|
38
|
+
</picture>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
# solana-pay-kit
|
|
42
|
+
|
|
43
|
+
Charge stablecoins (USDC, USDT, PYUSD, ...) for any HTTP endpoint, in Python.
|
|
44
|
+
One package, one surface, two protocols underneath:
|
|
45
|
+
[x402](https://x402.org) and the
|
|
46
|
+
[Machine Payments Protocol](https://paymentauth.org). FastAPI, Flask, and
|
|
47
|
+
Django ride on top of a framework-agnostic core.
|
|
48
|
+
|
|
49
|
+
You do not need to know anything about Solana to use this. Pick a currency,
|
|
50
|
+
give it your wallet address, gate a route in two lines. The SDK handles the
|
|
51
|
+
challenge, the on-chain verification, the broadcast, and the settlement.
|
|
52
|
+
|
|
53
|
+
[]()
|
|
54
|
+
[]()
|
|
55
|
+
[]()
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Quick start
|
|
60
|
+
|
|
61
|
+
Three progressively-realistic snippets. Each one runs as-is, copy, paste,
|
|
62
|
+
hit the URL. Flask is the framework here; the same surface works in FastAPI
|
|
63
|
+
and Django (see [Examples](#examples)).
|
|
64
|
+
|
|
65
|
+
### 1. Smallest possible app
|
|
66
|
+
|
|
67
|
+
Gate one route with an inline price. Save the snippet as `app.py` and boot
|
|
68
|
+
with `python app.py`. Zero-config: the package uses a published demo
|
|
69
|
+
keypair as the recipient and the hosted Surfpool sandbox at
|
|
70
|
+
`https://402.surfnet.dev:8899` as the RPC.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
# app.py
|
|
74
|
+
from flask import Flask, jsonify
|
|
75
|
+
|
|
76
|
+
import solana_pay_kit
|
|
77
|
+
from solana_pay_kit import usd
|
|
78
|
+
from solana_pay_kit.flask import require_payment
|
|
79
|
+
|
|
80
|
+
solana_pay_kit.configure(network="solana_localnet")
|
|
81
|
+
|
|
82
|
+
app = Flask(__name__)
|
|
83
|
+
|
|
84
|
+
@app.get("/report")
|
|
85
|
+
@require_payment(usd("0.10"))
|
|
86
|
+
def report():
|
|
87
|
+
return jsonify(content="premium content")
|
|
88
|
+
|
|
89
|
+
app.run(host="127.0.0.1", port=8000)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`solana_pay_kit.configure(...)` builds the process-wide config once at boot.
|
|
93
|
+
`@require_payment(usd("0.10"))` answers a 402 with a payment challenge when
|
|
94
|
+
no valid proof was sent, or runs the view if one was.
|
|
95
|
+
|
|
96
|
+
Hit `/report` with [`pay curl`](#run-the-example) and the customer walks
|
|
97
|
+
through a USDC payment.
|
|
98
|
+
|
|
99
|
+
### 2. Multiple gates via a registry
|
|
100
|
+
|
|
101
|
+
When more than one route is paid, lift the prices into a single
|
|
102
|
+
:class:`Pricing` registry. Routes reference gates by string handle.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
# app.py
|
|
106
|
+
from flask import Flask, jsonify
|
|
107
|
+
|
|
108
|
+
import solana_pay_kit
|
|
109
|
+
from solana_pay_kit import Gate, Protocol, Pricing, usd
|
|
110
|
+
from solana_pay_kit.flask import require_payment
|
|
111
|
+
|
|
112
|
+
solana_pay_kit.configure(network="solana_localnet")
|
|
113
|
+
|
|
114
|
+
class Catalog(Pricing):
|
|
115
|
+
def __init__(self):
|
|
116
|
+
defaults = {
|
|
117
|
+
"default_pay_to": solana_pay_kit.config().effective_recipient(),
|
|
118
|
+
"accept_default": solana_pay_kit.config().accept,
|
|
119
|
+
}
|
|
120
|
+
self.report = Gate.build(name="report", amount=usd("0.10"),
|
|
121
|
+
description="Premium report", **defaults)
|
|
122
|
+
self.api_call = Gate.build(name="api_call", amount=usd("0.001"),
|
|
123
|
+
accept=(Protocol.X402,), **defaults)
|
|
124
|
+
|
|
125
|
+
catalog = Catalog()
|
|
126
|
+
app = Flask(__name__)
|
|
127
|
+
|
|
128
|
+
@app.get("/report")
|
|
129
|
+
@require_payment("report", pricing=catalog)
|
|
130
|
+
def report():
|
|
131
|
+
return jsonify(content="premium content")
|
|
132
|
+
|
|
133
|
+
@app.get("/api/data")
|
|
134
|
+
@require_payment("api_call", pricing=catalog)
|
|
135
|
+
def api_data():
|
|
136
|
+
return jsonify(data=[])
|
|
137
|
+
|
|
138
|
+
app.run(host="127.0.0.1", port=8000)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Gates are validated in `Gate.build` at boot, wrong currency, missing
|
|
142
|
+
recipient, fee math that doesn't add up, so configuration errors surface
|
|
143
|
+
before any traffic. `accept=` is an allowlist; the `api_call` gate here
|
|
144
|
+
refuses to settle over MPP.
|
|
145
|
+
|
|
146
|
+
### 3. Production-shape config
|
|
147
|
+
|
|
148
|
+
Snippet 2's demo recipient and public sandbox are fine for poking around.
|
|
149
|
+
Production wants explicit keys, a dedicated RPC, and a list of accepted
|
|
150
|
+
stablecoins. The Flask app is unchanged, only the `configure` call grows.
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
# app.py, same routes as snippet 2.
|
|
154
|
+
import solana_pay_kit
|
|
155
|
+
from solana_pay_kit import Gate, Operator, Pricing, Signer, Stablecoin, usd
|
|
156
|
+
|
|
157
|
+
PLATFORM = "CXhrFZJLKqjzmP3sjYLcF4dTeXWKCy9e2SXXZ2Yo6MPY"
|
|
158
|
+
|
|
159
|
+
solana_pay_kit.configure(
|
|
160
|
+
network="solana_mainnet",
|
|
161
|
+
stablecoins=(Stablecoin.USDC, Stablecoin.PYUSD),
|
|
162
|
+
operator=Operator(signer=Signer.file("operator.json")),
|
|
163
|
+
rpc_url="https://mainnet.helius-rpc.com/?api-key=YOUR_HELIUS_KEY",
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
class Catalog(Pricing):
|
|
167
|
+
def __init__(self):
|
|
168
|
+
defaults = {"default_pay_to": solana_pay_kit.config().effective_recipient()}
|
|
169
|
+
self.report = Gate.build(name="report", amount=usd("0.10"),
|
|
170
|
+
description="Premium report", **defaults)
|
|
171
|
+
# Platform-fee pattern: customer pays $10.00,
|
|
172
|
+
# operator nets $9.70, PLATFORM nets $0.30. x402 auto-disabled.
|
|
173
|
+
self.marketplace_sale = Gate.build(
|
|
174
|
+
name="marketplace_sale",
|
|
175
|
+
amount=usd("10.00"),
|
|
176
|
+
fee_within={PLATFORM: usd("0.30")},
|
|
177
|
+
**defaults,
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`configure` reads literal values here; in real deployments pull the signer
|
|
182
|
+
and RPC URL from your environment (`Signer.env("OPERATOR_KEY")`,
|
|
183
|
+
`os.getenv("RPC_URL")`) or drive the whole thing from env vars with
|
|
184
|
+
`solana_pay_kit.configure_from()`.
|
|
185
|
+
|
|
186
|
+
Two safety rails fire at boot:
|
|
187
|
+
|
|
188
|
+
- `network="solana_mainnet"` plus the published demo signer raises
|
|
189
|
+
`DemoSignerOnMainnetError`, no real funds get routed to a publicly known
|
|
190
|
+
address by accident.
|
|
191
|
+
- Missing `mpp.challenge_binding_secret`? Preflight resolves one from the
|
|
192
|
+
environment, falling back to `./.env`, generating and persisting one if
|
|
193
|
+
neither exists, so the HMAC stays stable across restarts. Override via
|
|
194
|
+
`PAY_KIT_MPP_CHALLENGE_BINDING_SECRET` to control it from your secret
|
|
195
|
+
manager.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Run the example
|
|
200
|
+
|
|
201
|
+
Three runnable examples ship with this package, one per framework. Each one
|
|
202
|
+
boots zero-config against the Surfpool sandbox.
|
|
203
|
+
|
|
204
|
+
**Boot the server:**
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
git clone https://github.com/solana-foundation/pay-kit
|
|
208
|
+
cd pay-kit/python
|
|
209
|
+
pip install -e ".[flask]"
|
|
210
|
+
python examples/flask/app.py
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Consume with `pay curl`:**
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Install the pay CLI:
|
|
217
|
+
brew install pay
|
|
218
|
+
# or npm install -g @solana/pay
|
|
219
|
+
|
|
220
|
+
# Fail with 402, payment required
|
|
221
|
+
curl -i http://127.0.0.1:8000/report
|
|
222
|
+
|
|
223
|
+
# Succeed with 200, payment provided
|
|
224
|
+
pay curl -i http://127.0.0.1:8000/report
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## x402
|
|
230
|
+
|
|
231
|
+
[x402](https://x402.org) revives HTTP `402 Payment Required` as a
|
|
232
|
+
client-server payment handshake. Your server gates a route; a paying client
|
|
233
|
+
receives the 402 with payment instructions, signs a Solana transaction
|
|
234
|
+
off-chain, and replays the same request with a `PAYMENT-SIGNATURE` header.
|
|
235
|
+
The server verifies the signature, broadcasts the transaction, and returns
|
|
236
|
+
the original response with a `PAYMENT-RESPONSE` header carrying the on-chain
|
|
237
|
+
settlement signature.
|
|
238
|
+
|
|
239
|
+
x402 is single-recipient by design: the server's facilitator pays the
|
|
240
|
+
network fees, the customer's signed transaction settles funds to `pay_to`.
|
|
241
|
+
Gates with `fee_within` or `fee_on_top` recipients auto-disable x402,
|
|
242
|
+
because stock x402 facilitators settle to one address.
|
|
243
|
+
|
|
244
|
+
| Scheme | Client | Server |
|
|
245
|
+
|--------------------|:------:|:------:|
|
|
246
|
+
| `exact` | ✅ | ✅ |
|
|
247
|
+
| `upto` | ✅ | ✅ |
|
|
248
|
+
| `batch-settlement` | — | — |
|
|
249
|
+
|
|
250
|
+
`upto` charges for actual usage up to a ceiling: the client opens a payment
|
|
251
|
+
channel depositing the authorized maximum, the handler meters the response and
|
|
252
|
+
reports it via the `Charge` dependency, then the gate settles the actual amount
|
|
253
|
+
and refunds the remainder. It is gated with `require_usage` / `RequireUsage`
|
|
254
|
+
(rather than `require_payment`) and needs an operator signer.
|
|
255
|
+
|
|
256
|
+
### Client
|
|
257
|
+
|
|
258
|
+
Pay an x402-gated endpoint with the auto-pay transport (the Go `NewClient`
|
|
259
|
+
ergonomics): hand it a signer and an RPC and you get back an
|
|
260
|
+
`httpx.AsyncClient` that replays any `402` with a signed `PAYMENT-SIGNATURE`
|
|
261
|
+
payment, then returns the paid response.
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
import asyncio
|
|
265
|
+
|
|
266
|
+
from solana_pay_kit import Signer
|
|
267
|
+
from solana_pay_kit._paycore.rpc import SolanaRpc
|
|
268
|
+
from solana_pay_kit.protocols.x402.client import x402_async_client
|
|
269
|
+
|
|
270
|
+
async def main():
|
|
271
|
+
signer = Signer.file("payer.json") # the payer's keypair
|
|
272
|
+
rpc = SolanaRpc("https://api.devnet.solana.com")
|
|
273
|
+
async with x402_async_client(signer, rpc) as http:
|
|
274
|
+
resp = await http.get("https://api.example/report") # 402 -> pay -> 200
|
|
275
|
+
print(resp.status_code, resp.headers.get("payment-response"))
|
|
276
|
+
|
|
277
|
+
asyncio.run(main())
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The low-level building blocks are exposed too, mirroring the Rust/Go client:
|
|
281
|
+
`parse_x402_challenge(headers, body, selection)` selects an offer, and
|
|
282
|
+
`build_payment_header(signer, rpc, offer)` returns the base64 `PAYMENT-SIGNATURE`
|
|
283
|
+
value for callers that drive their own HTTP. See
|
|
284
|
+
[`examples/x402-client/`](examples/x402-client).
|
|
285
|
+
|
|
286
|
+
## MPP
|
|
287
|
+
|
|
288
|
+
The [Machine Payments Protocol](https://paymentauth.org) is the broader HTTP
|
|
289
|
+
Payment Authentication scheme, the same 402 handshake, but the challenge
|
|
290
|
+
carries a richer intent shape that supports multi-recipient splits,
|
|
291
|
+
server-side fee accounting, and a separate fee-payer signer.
|
|
292
|
+
|
|
293
|
+
Use MPP when:
|
|
294
|
+
|
|
295
|
+
- Your gate has a platform or gateway fee (the Stripe-Connect "application
|
|
296
|
+
fee" pattern).
|
|
297
|
+
- You want the server to subsidize the customer's network fee.
|
|
298
|
+
- You want one challenge per gate instead of per-mint-quoted offers.
|
|
299
|
+
|
|
300
|
+
| Intent | Client | Server |
|
|
301
|
+
|----------------|:------:|:------:|
|
|
302
|
+
| `charge/pull` | ✅ | ✅ |
|
|
303
|
+
| `charge/push` | — | ✅ |
|
|
304
|
+
| `session` | ✅ | ✅ |
|
|
305
|
+
| `subscription` | — | — |
|
|
306
|
+
|
|
307
|
+
`session` ships both sides. Client: `ActiveSession` voucher signing, the
|
|
308
|
+
challenge-driven pull/clientVoucher payment-channel openers (fee payer =
|
|
309
|
+
challenge operator, pending-server-signature placeholder), the metered
|
|
310
|
+
`SessionConsumer`, and the SSE streaming helpers (`MeteredSseSession`,
|
|
311
|
+
`MeteredSseStream`, `HttpCommitTransport`). Server: the session method
|
|
312
|
+
(`new_session`) issuing challenges and verifying credentials/vouchers, the
|
|
313
|
+
server-broadcast open path (`openTxSubmitter=server`, the operator co-signs and
|
|
314
|
+
broadcasts the open), the reserve/commit metering side channel
|
|
315
|
+
(`session_routes`), the shared channel store, the idle-close watchdog, and
|
|
316
|
+
on-chain settle-at-close (when a signer and RPC are configured, a closed
|
|
317
|
+
channel's `settledSignature` carries the real on-chain signature; without them
|
|
318
|
+
the close is a state-flip and the signature stays `null`). Not yet ported:
|
|
319
|
+
pull/operatedVoucher (multi-delegate) opens.
|
|
320
|
+
|
|
321
|
+
The MPP server owns the full lifecycle: it issues signed challenges with a
|
|
322
|
+
fresh `recentBlockhash`, parses and validates the `Authorization: Payment`
|
|
323
|
+
credential, pins the echoed charge request, decodes the client-signed
|
|
324
|
+
transaction and checks recipient, amount, mint, splits, ATA, memos, and
|
|
325
|
+
compute budget, rejects Surfpool-signed transactions on non-localnet
|
|
326
|
+
networks, optionally fee-payer co-signs (legacy + v0), broadcasts via
|
|
327
|
+
`sendTransaction`, consumes the signature in the replay store, awaits
|
|
328
|
+
confirmation, and emits `payment-receipt` with the on-chain signature.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Vocabulary
|
|
333
|
+
|
|
334
|
+
| Term | Meaning |
|
|
335
|
+
|--------------|---------|
|
|
336
|
+
| **gate** | A protected unit. Has an amount, optional fees, accepted protocols. |
|
|
337
|
+
| **amount** | The base amount a gate charges, before any `fee_on_top`. |
|
|
338
|
+
| **total** | What the customer pays: `amount + sum(fee_on_top)`. Derived via `Gate.total()`. |
|
|
339
|
+
| **price** | Value object returned by `usd(...)`: number + currency + settlement. |
|
|
340
|
+
| **fee_within** | Fee taken out of the amount. `pay_to` nets less. |
|
|
341
|
+
| **fee_on_top** | Fee added to the amount. Customer pays more; `pay_to` nets full. |
|
|
342
|
+
| **payment** | Proof submitted by the client to pass a gate. |
|
|
343
|
+
| **protocol** | `Protocol.X402` or `Protocol.MPP` (top-level dispatch). |
|
|
344
|
+
| **scheme** | x402 sub-form: `exact`. MPP sub-form: `charge`. |
|
|
345
|
+
| **currency** | Fiat unit a price is quoted in (`USD`, `EUR`, `GBP`). |
|
|
346
|
+
| **accept** | Ordered preference list (protocols and stablecoins both). |
|
|
347
|
+
| **settlement** | On-chain asset that actually transfers (`USDC`, `USDT`). |
|
|
348
|
+
|
|
349
|
+
## Three primitives
|
|
350
|
+
|
|
351
|
+
The framework-agnostic trio, importable from the top level for imperative
|
|
352
|
+
gating inside a handler, mirrored by the per-framework shims:
|
|
353
|
+
|
|
354
|
+
| Function | Purpose |
|
|
355
|
+
|----------|---------|
|
|
356
|
+
| `require_payment(request)` | Returns the verified `Payment`, raises `PaymentRequiredError` if unpaid |
|
|
357
|
+
| `is_paid(request)` | Predicate, never raises |
|
|
358
|
+
| `get_payment(request)` | The verified `Payment`, `None` until paid |
|
|
359
|
+
|
|
360
|
+
Each framework shim also exposes its own decorator/dependency form:
|
|
361
|
+
`solana_pay_kit.flask.require_payment`, `solana_pay_kit.fastapi.RequirePayment`, and
|
|
362
|
+
`solana_pay_kit.django.require_payment`.
|
|
363
|
+
|
|
364
|
+
## Inline pricing
|
|
365
|
+
|
|
366
|
+
For one-off endpoints that don't warrant a registry entry, skip the gate
|
|
367
|
+
name and pass a price directly:
|
|
368
|
+
|
|
369
|
+
```python
|
|
370
|
+
@app.get("/oneoff")
|
|
371
|
+
@require_payment(usd("0.25"))
|
|
372
|
+
def oneoff():
|
|
373
|
+
return jsonify(ok=True)
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
The bare `Price` is wrapped into an inline `Gate` using the configured
|
|
377
|
+
default recipient and accept list.
|
|
378
|
+
|
|
379
|
+
## Gate DSL
|
|
380
|
+
|
|
381
|
+
Each gate is a frozen value object built via `Gate.build` with an amount, an
|
|
382
|
+
ordered list of accepted protocols, and zero or more named fees.
|
|
383
|
+
|
|
384
|
+
```python
|
|
385
|
+
SELLER = "Ay..."
|
|
386
|
+
PLATFORM = "CX..."
|
|
387
|
+
|
|
388
|
+
# Simple. Customer pays $0.10, pay_to nets $0.10.
|
|
389
|
+
Gate.build(name="report", amount=usd("0.10"), description="Premium report")
|
|
390
|
+
|
|
391
|
+
# x402-only.
|
|
392
|
+
Gate.build(name="api_call", amount=usd("0.001"), accept=(Protocol.X402,))
|
|
393
|
+
|
|
394
|
+
# Stripe-Connect "application fee". Customer pays $10.00,
|
|
395
|
+
# SELLER nets $9.70, PLATFORM nets $0.30. x402 auto-disabled.
|
|
396
|
+
Gate.build(name="marketplace_sale", amount=usd("10.00"),
|
|
397
|
+
pay_to=SELLER, fee_within={PLATFORM: usd("0.30")})
|
|
398
|
+
|
|
399
|
+
# Surcharge. Customer pays $10.50, SELLER nets $10.00, PLATFORM nets $0.50.
|
|
400
|
+
Gate.build(name="ticket", amount=usd("10.00"),
|
|
401
|
+
pay_to=SELLER, fee_on_top={PLATFORM: usd("0.50")})
|
|
402
|
+
|
|
403
|
+
# Dynamic per-request pricing.
|
|
404
|
+
@gate("tiered")
|
|
405
|
+
def tiered(request):
|
|
406
|
+
tier = request.args.get("tier")
|
|
407
|
+
return usd("5.00") if tier == "premium" else usd("0.10")
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Boot-time validations (all raise `ConfigurationError` or a subclass):
|
|
411
|
+
|
|
412
|
+
- `pay_to` is required (gate kwarg or a configured operator recipient).
|
|
413
|
+
- Fee recipient must differ from `pay_to`. Fold the fee into the amount instead.
|
|
414
|
+
- All fee prices share one denomination with the amount.
|
|
415
|
+
- `sum(fee_within) <= amount`.
|
|
416
|
+
- `accept=(Protocol.X402,)` on a fee-bearing gate raises `ProtocolIncompatibleError`.
|
|
417
|
+
|
|
418
|
+
## Framework-first
|
|
419
|
+
|
|
420
|
+
`solana_pay_kit` carries no web-framework dependency in the base install. The
|
|
421
|
+
framework shims live in optional submodules imported on demand:
|
|
422
|
+
|
|
423
|
+
- `solana_pay_kit.flask` (install `solana_pay_kit[flask]`), a `@require_payment` view
|
|
424
|
+
decorator plus `is_paid` / `payment` request accessors.
|
|
425
|
+
- `solana_pay_kit.fastapi` (install `solana_pay_kit[fastapi]`), a `RequirePayment`
|
|
426
|
+
dependency for `Depends(...)` plus `install_exception_handler(app)`.
|
|
427
|
+
- `solana_pay_kit.django` (install `solana_pay_kit[django]`), a `require_payment` view
|
|
428
|
+
decorator and an optional `PaymentMiddleware` stack form.
|
|
429
|
+
|
|
430
|
+
Every shim delegates protocol/scheme dispatch and 402-challenge assembly to
|
|
431
|
+
the host-neutral `PayCore`; the shim only translates the outcome into its
|
|
432
|
+
framework's response idioms. A verified `Payment` is attached to the request
|
|
433
|
+
(`request.state` on FastAPI, `flask.g` on Flask, `request.payment` on
|
|
434
|
+
Django) and its settlement headers are merged onto the success response.
|
|
435
|
+
|
|
436
|
+
```python
|
|
437
|
+
# Imperative gating, no decorator, any framework:
|
|
438
|
+
from solana_pay_kit import require_payment
|
|
439
|
+
|
|
440
|
+
def view(request):
|
|
441
|
+
payment = require_payment(request) # raises PaymentRequiredError if unpaid
|
|
442
|
+
...
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
## Examples
|
|
448
|
+
|
|
449
|
+
Runnable examples ship with this package:
|
|
450
|
+
|
|
451
|
+
- [`examples/simple-server/server.py`](examples/simple-server/server.py), the
|
|
452
|
+
smallest solana_pay_kit server: stdlib `http.server` with one gated endpoint over
|
|
453
|
+
the unified `solana_pay_kit` surface, no web framework.
|
|
454
|
+
- [`examples/fastapi/app.py`](examples/fastapi/app.py), FastAPI server using
|
|
455
|
+
the `RequirePayment` dependency and `install_exception_handler`.
|
|
456
|
+
- [`examples/flask/app.py`](examples/flask/app.py), Flask server gated with
|
|
457
|
+
the unified `solana_pay_kit` surface (`@require_payment` decorator and the
|
|
458
|
+
`Pricing` registry).
|
|
459
|
+
- [`examples/django/views.py`](examples/django/views.py), Django views +
|
|
460
|
+
URLconf snippet using the `@require_payment` decorator.
|
|
461
|
+
|
|
462
|
+
All examples default to `solana_localnet`, `USDC`, and the demo recipient.
|
|
463
|
+
Override the RPC with `rpc_url=` / `PAY_KIT_RPC_URL`.
|
|
464
|
+
|
|
465
|
+
## Coverage
|
|
466
|
+
|
|
467
|
+
```bash
|
|
468
|
+
cd python
|
|
469
|
+
pip install -e ".[dev]"
|
|
470
|
+
ruff check src tests
|
|
471
|
+
ruff format --check src tests
|
|
472
|
+
pyright
|
|
473
|
+
pytest --cov=solana_pay_kit --cov-fail-under=90
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
The `solana_pay_kit` surface is gated at 90 percent line coverage in CI. The
|
|
477
|
+
`solana_pay_kit.preflight` module is omitted from the gate: it wraps live Solana
|
|
478
|
+
RPC + Surfnet cheatcodes that cannot run inside the offline unit suite, and
|
|
479
|
+
its two opt-out knobs are covered separately against a stubbed run/RPC.
|
|
480
|
+
|
|
481
|
+
## Harness
|
|
482
|
+
|
|
483
|
+
The Python server has a direct harness adapter at
|
|
484
|
+
[`harness/python-server/server.py`](../harness/python-server/server.py), a
|
|
485
|
+
dual-protocol server that settles both MPP charge and x402-exact. Focused
|
|
486
|
+
harness commands:
|
|
487
|
+
|
|
488
|
+
```bash
|
|
489
|
+
cd harness
|
|
490
|
+
MPP_HARNESS_CLIENTS=typescript MPP_HARNESS_SERVERS=python pnpm test
|
|
491
|
+
MPP_HARNESS_CLIENTS=rust MPP_HARNESS_SERVERS=python pnpm test
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## Spec
|
|
495
|
+
|
|
496
|
+
This SDK implements the
|
|
497
|
+
[Solana Charge Intent](https://paymentauth.org/draft-solana-charge-00.html) for
|
|
498
|
+
the [HTTP Payment Authentication Scheme](https://paymentauth.org), plus the
|
|
499
|
+
x402 exact scheme on Solana. The wire format, error grammar, and challenge /
|
|
500
|
+
credential shape are all defined at [paymentauth.org](https://paymentauth.org).
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## Repo layout
|
|
505
|
+
|
|
506
|
+
```text
|
|
507
|
+
python/
|
|
508
|
+
├── src/solana_pay_kit/ unified surface over x402 + MPP
|
|
509
|
+
│ ├── config.py, operator.py, signer.py, price.py, fee.py, gate.py,
|
|
510
|
+
│ │ pricing.py, payment.py, preflight.py, errors.py # umbrella surface
|
|
511
|
+
│ ├── _paycore/ Currency / Network / Protocol / Stablecoin / Mints / Solana
|
|
512
|
+
│ ├── _middleware.py host-neutral resolver + require_payment/is_paid/get_payment
|
|
513
|
+
│ ├── fastapi.py, flask.py, django.py framework shims
|
|
514
|
+
│ ├── kms.py reserved remote-enclave signer namespace
|
|
515
|
+
│ └── protocols/
|
|
516
|
+
│ ├── x402/ x402-exact adapter (__init__) + verifier/wire shapes (verify.py)
|
|
517
|
+
│ └── mpp/ MPP-charge adapter (__init__) over the consolidated wire layer
|
|
518
|
+
│ ├── core/ canonical JSON, headers, challenge, types, errors, RPC, store
|
|
519
|
+
│ ├── intents/charge.py charge intent
|
|
520
|
+
│ ├── server/ charge handler, middleware, network check, defaults, payment page
|
|
521
|
+
│ └── client/ charge + transport
|
|
522
|
+
├── examples/simple-server/ stdlib http.server, one gated endpoint
|
|
523
|
+
├── examples/{fastapi,flask,django}/ solana_pay_kit framework examples
|
|
524
|
+
├── tests/ pytest suite
|
|
525
|
+
└── pyproject.toml
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
## Coding convention
|
|
529
|
+
|
|
530
|
+
This SDK follows the
|
|
531
|
+
[`skills.sh/mindrally/skills/python`](https://skills.sh/mindrally/skills/python)
|
|
532
|
+
best-practice skill. Small modules, frozen pydantic value objects, explicit
|
|
533
|
+
error types with canonical codes, deterministic wire serialization (RFC 8785
|
|
534
|
+
canonical JSON), defensive payment verification, and branch tests on
|
|
535
|
+
security-sensitive paths.
|
|
536
|
+
|
|
537
|
+
The repo-level `pay-sdk-implementation` skill remains the protocol source of
|
|
538
|
+
truth: Rust spec wire format first, Python idioms second.
|
|
539
|
+
|
|
540
|
+
## License
|
|
541
|
+
|
|
542
|
+
MIT
|