Skip to content

Commit 56dda80

Browse files
docs: update Python SDK documentation for v1.4.0 (#144)
- Updated from nevermined-io/payments-py@e01517e - SDK version: v1.4.0 - Target branch: main - Generated documentation from tagged release - Converted to Mintlify MDX format Co-authored-by: nevermined-release-bot[bot] <245387585+nevermined-release-bot[bot]@users.noreply.github.com>
1 parent 4218cc9 commit 56dda80

File tree

3 files changed

+127
-24
lines changed

3 files changed

+127
-24
lines changed

docs/api-reference/python/plans-module.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,40 @@ price_config = get_fiat_price_config(
155155
)
156156
```
157157

158+
### Fiat Price (EUR)
159+
160+
```python
161+
from payments_py.plans import get_fiat_price_config
162+
from payments_py.common.types import Currency
163+
164+
price_config = get_fiat_price_config(
165+
amount=2900, # €29.00 in euro cents
166+
receiver="0xBuilderAddress",
167+
currency=Currency.EUR
168+
)
169+
```
170+
171+
### EURC Token Price (Euro Stablecoin)
172+
173+
```python
174+
from payments_py.plans import get_eurc_price_config
175+
176+
# EURC pricing (Euro stablecoin on Base, 6 decimals)
177+
price_config = get_eurc_price_config(
178+
amount=29_000_000, # €29.00 in smallest unit (6 decimals)
179+
receiver="0xBuilderAddress"
180+
)
181+
182+
# Or use a custom EURC address (e.g., testnet)
183+
from payments_py.common.types import EURC_TOKEN_ADDRESS_TESTNET
184+
185+
testnet_config = get_eurc_price_config(
186+
amount=29_000_000,
187+
receiver="0xBuilderAddress",
188+
eurc_address=EURC_TOKEN_ADDRESS_TESTNET
189+
)
190+
```
191+
158192
### Free Price
159193

160194
```python

docs/api-reference/python/requests-module.mdx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ payments = Payments.get_instance(
2525
PaymentOptions(nvm_api_key="nvm:subscriber-key", environment="sandbox")
2626
)
2727

28-
# Generate access token
28+
# Generate access token (basic — auto-creates delegation)
2929
result = payments.x402.get_x402_access_token(
3030
plan_id="your-plan-id",
3131
agent_id="agent-id" # Optional but recommended
@@ -41,22 +41,44 @@ print(f"Access Token: {access_token[:50]}...")
4141
|-----------|------|----------|-------------|
4242
| `plan_id` | `str` | Yes | The payment plan ID |
4343
| `agent_id` | `str` | No | Target agent ID (recommended) |
44-
| `redemption_limit` | `int` | No | Max number of redemptions |
45-
| `order_limit` | `str` | No | Max spend in wei |
46-
| `expiration` | `str` | No | ISO 8601 expiration date |
44+
| `token_options` | `X402TokenOptions` | No | Scheme and delegation configuration |
4745

48-
### Advanced Token Options
46+
### Token Generation with Delegation
47+
48+
For erc4337 (crypto) plans, token generation now uses delegations. Two patterns are supported:
4949

5050
```python
51-
from datetime import datetime, timedelta
51+
from payments_py.x402 import X402TokenOptions, DelegationConfig, CreateDelegationPayload
52+
53+
# Pattern A — Auto-create delegation (simple)
54+
result = payments.x402.get_x402_access_token(
55+
plan_id="your-plan-id",
56+
agent_id="agent-id",
57+
token_options=X402TokenOptions(
58+
delegation_config=DelegationConfig(
59+
spending_limit_cents=10000, # $100
60+
duration_secs=604800 # 1 week
61+
)
62+
)
63+
)
64+
65+
# Pattern B — Explicit create + reuse (for sharing across plans)
66+
delegation = payments.delegation.create_delegation(
67+
CreateDelegationPayload(
68+
provider="erc4337",
69+
spending_limit_cents=10000,
70+
duration_secs=604800
71+
)
72+
)
5273

53-
# Token with limits and expiration
5474
result = payments.x402.get_x402_access_token(
5575
plan_id="your-plan-id",
5676
agent_id="agent-id",
57-
redemption_limit=10, # Max 10 requests
58-
order_limit="1000000000000000000", # Max 1 token in wei
59-
expiration=(datetime.now() + timedelta(hours=24)).isoformat()
77+
token_options=X402TokenOptions(
78+
delegation_config=DelegationConfig(
79+
delegation_id=delegation.delegation_id
80+
)
81+
)
6082
)
6183
```
6284

@@ -209,7 +231,7 @@ except requests.HTTPError as e:
209231
if e.response.status_code == 401:
210232
print("Token expired or invalid - generate a new token")
211233
# Regenerate token
212-
new_token = payments.x402.get_x402_access_token(plan_id, agent_id)
234+
new_token = payments.x402.get_x402_access_token(plan_id, agent_id, token_options=token_options)
213235
```
214236

215237
## Request Flow Diagram

docs/api-reference/python/x402-module.mdx

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,52 @@ result = payments.x402.get_x402_access_token(
5454
)
5555
access_token = result['accessToken']
5656

57-
# Advanced: with limits
57+
# With delegation config (crypto — erc4337)
58+
from payments_py.x402 import X402TokenOptions, DelegationConfig, CreateDelegationPayload
59+
60+
# Pattern A — auto-create delegation
61+
result = payments.x402.get_x402_access_token(
62+
plan_id="your-plan-id",
63+
agent_id="agent-id",
64+
token_options=X402TokenOptions(
65+
delegation_config=DelegationConfig(
66+
spending_limit_cents=10000, # $100
67+
duration_secs=604800 # 1 week
68+
)
69+
)
70+
)
71+
72+
# Pattern B — explicit create + reuse across plans
73+
delegation = payments.delegation.create_delegation(
74+
CreateDelegationPayload(
75+
provider="erc4337",
76+
spending_limit_cents=10000,
77+
duration_secs=604800
78+
)
79+
)
5880
result = payments.x402.get_x402_access_token(
5981
plan_id="your-plan-id",
6082
agent_id="agent-id",
61-
redemption_limit=100, # Max 100 requests
62-
order_limit="1000000000000000000", # Max 1 token spend
63-
expiration="2025-12-31T23:59:59Z" # Expires end of year
83+
token_options=X402TokenOptions(
84+
delegation_config=DelegationConfig(delegation_id=delegation.delegation_id)
85+
)
6486
)
6587
```
6688

6789
### Card-Delegation Token Generation
6890

69-
For fiat plans using `nvm:card-delegation`, pass `X402TokenOptions` with a `CardDelegationConfig`:
91+
For fiat plans using `nvm:card-delegation`, pass `X402TokenOptions` with a `DelegationConfig`:
7092

7193
```python
72-
from payments_py.x402.types import X402TokenOptions, CardDelegationConfig
94+
from payments_py.x402 import X402TokenOptions, DelegationConfig
7395

74-
# Generate a card-delegation token
96+
# USD card delegation
7597
result = payments.x402.get_x402_access_token(
7698
plan_id="your-plan-id",
7799
agent_id="agent-id",
78100
token_options=X402TokenOptions(
79101
scheme="nvm:card-delegation",
80-
delegation_config=CardDelegationConfig(
102+
delegation_config=DelegationConfig(
81103
provider_payment_method_id="pm_1AbCdEfGhIjKlM",
82104
spending_limit_cents=10000, # $100.00
83105
duration_secs=2592000, # 30 days
@@ -87,6 +109,22 @@ result = payments.x402.get_x402_access_token(
87109
)
88110
)
89111
access_token = result['accessToken']
112+
113+
# EUR card delegation
114+
eur_result = payments.x402.get_x402_access_token(
115+
plan_id="your-plan-id",
116+
agent_id="agent-id",
117+
token_options=X402TokenOptions(
118+
scheme="nvm:card-delegation",
119+
delegation_config=DelegationConfig(
120+
provider_payment_method_id="pm_1AbCdEfGhIjKlM",
121+
spending_limit_cents=10000, # €100.00 (in euro cents)
122+
duration_secs=2592000, # 30 days
123+
currency="eur",
124+
max_transactions=100
125+
)
126+
)
127+
)
90128
```
91129

92130
### Auto Scheme Resolution
@@ -106,14 +144,23 @@ scheme = resolve_scheme(payments, plan_id="your-plan-id", explicit_scheme="nvm:c
106144

107145
### DelegationAPI
108146

109-
List enrolled payment methods for card delegation:
147+
Create delegations and list enrolled payment methods:
110148

111149
```python
112-
from payments_py.x402.delegation_api import DelegationAPI, PaymentMethodSummary
113-
114-
delegation_api = DelegationAPI.get_instance(payments.options)
115-
methods: list[PaymentMethodSummary] = delegation_api.list_payment_methods()
150+
from payments_py.x402 import CreateDelegationPayload
151+
152+
# Create a crypto delegation
153+
delegation = payments.delegation.create_delegation(
154+
CreateDelegationPayload(
155+
provider="erc4337",
156+
spending_limit_cents=10000,
157+
duration_secs=604800
158+
)
159+
)
160+
print(f"Delegation ID: {delegation.delegation_id}")
116161

162+
# List enrolled payment methods (for card delegation)
163+
methods = payments.delegation.list_payment_methods()
117164
for method in methods:
118165
print(f"{method.brand} ****{method.last4} (expires {method.exp_month}/{method.exp_year})")
119166
# e.g., "visa ****4242 (expires 12/2027)"

0 commit comments

Comments
 (0)