Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/api-reference/python/plans-module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
icon: "credit-card"
---

This guide covers how to create and manage payment plans using the Nevermined Payments Python SDK.

Check warning on line 7 in docs/api-reference/python/plans-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Nevermined'?

## Overview

Payment Plans define how users pay to access your AI agents and services. Nevermined supports two types of plans:

Check warning on line 11 in docs/api-reference/python/plans-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Nevermined'?

- **Credits Plans**: Users purchase a fixed number of credits that are consumed with each request
- **Time Plans**: Users purchase access for a specific duration (e.g., 1 day, 1 month)
Expand Down Expand Up @@ -155,6 +155,40 @@
)
```

### Fiat Price (EUR)

```python
from payments_py.plans import get_fiat_price_config
from payments_py.common.types import Currency

price_config = get_fiat_price_config(
amount=2900, # €29.00 in euro cents
receiver="0xBuilderAddress",
currency=Currency.EUR
)
```

### EURC Token Price (Euro Stablecoin)

Check warning on line 171 in docs/api-reference/python/plans-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Stablecoin'?

```python
from payments_py.plans import get_eurc_price_config

# EURC pricing (Euro stablecoin on Base, 6 decimals)
price_config = get_eurc_price_config(
amount=29_000_000, # €29.00 in smallest unit (6 decimals)
receiver="0xBuilderAddress"
)

# Or use a custom EURC address (e.g., testnet)
from payments_py.common.types import EURC_TOKEN_ADDRESS_TESTNET

testnet_config = get_eurc_price_config(
amount=29_000_000,
receiver="0xBuilderAddress",
eurc_address=EURC_TOKEN_ADDRESS_TESTNET
)
```

### Free Price

```python
Expand Down
44 changes: 33 additions & 11 deletions docs/api-reference/python/requests-module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
PaymentOptions(nvm_api_key="nvm:subscriber-key", environment="sandbox")
)

# Generate access token
# Generate access token (basic — auto-creates delegation)
result = payments.x402.get_x402_access_token(
plan_id="your-plan-id",
agent_id="agent-id" # Optional but recommended
Expand All @@ -41,22 +41,44 @@
|-----------|------|----------|-------------|
| `plan_id` | `str` | Yes | The payment plan ID |
| `agent_id` | `str` | No | Target agent ID (recommended) |
| `redemption_limit` | `int` | No | Max number of redemptions |
| `order_limit` | `str` | No | Max spend in wei |
| `expiration` | `str` | No | ISO 8601 expiration date |
| `token_options` | `X402TokenOptions` | No | Scheme and delegation configuration |

### Advanced Token Options
### Token Generation with Delegation

For erc4337 (crypto) plans, token generation now uses delegations. Two patterns are supported:

Check warning on line 48 in docs/api-reference/python/requests-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'crypto'?

```python
from datetime import datetime, timedelta
from payments_py.x402 import X402TokenOptions, DelegationConfig, CreateDelegationPayload

# Pattern A — Auto-create delegation (simple)
result = payments.x402.get_x402_access_token(
plan_id="your-plan-id",
agent_id="agent-id",
token_options=X402TokenOptions(
delegation_config=DelegationConfig(
spending_limit_cents=10000, # $100
duration_secs=604800 # 1 week
)
)
)

# Pattern B — Explicit create + reuse (for sharing across plans)
delegation = payments.delegation.create_delegation(
CreateDelegationPayload(
provider="erc4337",
spending_limit_cents=10000,
duration_secs=604800
)
)

# Token with limits and expiration
result = payments.x402.get_x402_access_token(
plan_id="your-plan-id",
agent_id="agent-id",
redemption_limit=10, # Max 10 requests
order_limit="1000000000000000000", # Max 1 token in wei
expiration=(datetime.now() + timedelta(hours=24)).isoformat()
token_options=X402TokenOptions(
delegation_config=DelegationConfig(
delegation_id=delegation.delegation_id
)
)
)
```

Expand Down Expand Up @@ -209,7 +231,7 @@
if e.response.status_code == 401:
print("Token expired or invalid - generate a new token")
# Regenerate token
new_token = payments.x402.get_x402_access_token(plan_id, agent_id)
new_token = payments.x402.get_x402_access_token(plan_id, agent_id, token_options=token_options)
```

## Request Flow Diagram
Expand Down
73 changes: 60 additions & 13 deletions docs/api-reference/python/x402-module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

## Supported Schemes

Nevermined supports two x402 payment schemes:

Check warning on line 21 in docs/api-reference/python/x402-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Nevermined'?

| Scheme | Network | Use Case | Settlement |
|--------|---------|----------|------------|
| `nvm:erc4337` | `eip155:84532` | Crypto payments | ERC-4337 UserOps + session keys |

Check warning on line 25 in docs/api-reference/python/x402-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Crypto'?
| `nvm:card-delegation` | `stripe` | Fiat/credit card | Stripe PaymentIntent + credit burn |

The scheme is determined by the plan's pricing configuration. Plans with `isCrypto: false` use `nvm:card-delegation`; all others use `nvm:erc4337`. The SDK auto-detects the scheme via `resolve_scheme()`.

## Generate Payment Permissions

### From Nevermined App

Check warning on line 32 in docs/api-reference/python/x402-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Nevermined'?

The easiest way to generate permissions is through the [Nevermined App Permissions page](https://nevermined.app/permissions/agent-permissions):

Expand All @@ -54,30 +54,52 @@
)
access_token = result['accessToken']

# Advanced: with limits
# With delegation config (crypto — erc4337)
from payments_py.x402 import X402TokenOptions, DelegationConfig, CreateDelegationPayload

# Pattern A — auto-create delegation
result = payments.x402.get_x402_access_token(
plan_id="your-plan-id",
agent_id="agent-id",
token_options=X402TokenOptions(
delegation_config=DelegationConfig(
spending_limit_cents=10000, # $100
duration_secs=604800 # 1 week
)
)
)

# Pattern B — explicit create + reuse across plans
delegation = payments.delegation.create_delegation(
CreateDelegationPayload(
provider="erc4337",
spending_limit_cents=10000,
duration_secs=604800
)
)
result = payments.x402.get_x402_access_token(
plan_id="your-plan-id",
agent_id="agent-id",
redemption_limit=100, # Max 100 requests
order_limit="1000000000000000000", # Max 1 token spend
expiration="2025-12-31T23:59:59Z" # Expires end of year
token_options=X402TokenOptions(
delegation_config=DelegationConfig(delegation_id=delegation.delegation_id)
)
)
```

### Card-Delegation Token Generation

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

```python
from payments_py.x402.types import X402TokenOptions, CardDelegationConfig
from payments_py.x402 import X402TokenOptions, DelegationConfig

# Generate a card-delegation token
# USD card delegation
result = payments.x402.get_x402_access_token(
plan_id="your-plan-id",
agent_id="agent-id",
token_options=X402TokenOptions(
scheme="nvm:card-delegation",
delegation_config=CardDelegationConfig(
delegation_config=DelegationConfig(
provider_payment_method_id="pm_1AbCdEfGhIjKlM",
spending_limit_cents=10000, # $100.00
duration_secs=2592000, # 30 days
Expand All @@ -87,6 +109,22 @@
)
)
access_token = result['accessToken']

# EUR card delegation
eur_result = payments.x402.get_x402_access_token(
plan_id="your-plan-id",
agent_id="agent-id",
token_options=X402TokenOptions(
scheme="nvm:card-delegation",
delegation_config=DelegationConfig(
provider_payment_method_id="pm_1AbCdEfGhIjKlM",
spending_limit_cents=10000, # €100.00 (in euro cents)
duration_secs=2592000, # 30 days
currency="eur",
max_transactions=100
)
)
)
```

### Auto Scheme Resolution
Expand All @@ -106,14 +144,23 @@

### DelegationAPI

List enrolled payment methods for card delegation:
Create delegations and list enrolled payment methods:

```python
from payments_py.x402.delegation_api import DelegationAPI, PaymentMethodSummary

delegation_api = DelegationAPI.get_instance(payments.options)
methods: list[PaymentMethodSummary] = delegation_api.list_payment_methods()
from payments_py.x402 import CreateDelegationPayload

# Create a crypto delegation
delegation = payments.delegation.create_delegation(
CreateDelegationPayload(
provider="erc4337",
spending_limit_cents=10000,
duration_secs=604800
)
)
print(f"Delegation ID: {delegation.delegation_id}")

# List enrolled payment methods (for card delegation)
methods = payments.delegation.list_payment_methods()
for method in methods:
print(f"{method.brand} ****{method.last4} (expires {method.exp_month}/{method.exp_year})")
# e.g., "visa ****4242 (expires 12/2027)"
Expand Down Expand Up @@ -141,7 +188,7 @@
"planId": "plan-123",
"agentId": "agent-456"
},
"sessionKey": {

Check warning on line 191 in docs/api-reference/python/x402-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'sessionKey'?
"address": "0xSessionKeyAddress",
"permissions": ["order", "burn"],
"limits": {
Expand Down Expand Up @@ -224,7 +271,7 @@
| `success` | `bool` | Whether settlement succeeded |
| `error_reason` | `str` | Reason for failure (if `success` is false) |
| `payer` | `str` | Payer's wallet address |
| `transaction` | `str` | Blockchain transaction hash |

Check warning on line 274 in docs/api-reference/python/x402-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Blockchain'?
| `credits_redeemed` | `str` | Credits that were burned |
| `remaining_balance` | `str` | Credits remaining |

Expand Down Expand Up @@ -309,7 +356,7 @@
)
```

For a single plan, `build_payment_required_for_plans` delegates to `build_payment_required` internally. When `scheme` is omitted, the network defaults to `eip155:84532` (Base Sepolia). When `scheme="nvm:card-delegation"`, the network is automatically set to `stripe`.

Check warning on line 359 in docs/api-reference/python/x402-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'Sepolia'?

## Complete Workflow Example

Expand Down Expand Up @@ -417,7 +464,7 @@

2. **Only settle on success**: Don't burn credits if processing fails

3. **Use agent_request_id**: Include request IDs for tracking and debugging

Check warning on line 467 in docs/api-reference/python/x402-module.mdx

View check run for this annotation

Mintlify / Mintlify Validation (neverminedag) - vale-spellcheck

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

Did you really mean 'agent_request_id'?

4. **Handle 402 responses**: Return proper payment required responses with scheme info

Expand Down