The Problem
When a subscriber has multiple active mandates or delegations across their enrolled cards, the agent needs to know which one to use. Should it charge the 10 delegation on Card B? NVM Pay solves this with a three-tier selection algorithm that automatically resolves the right authorization based on priority rules.The three-tier selection is currently implemented for Visa mandates via the
POST /access-token/from-nvm-key endpoint. Stripe delegations use the separate delegation API (POST /api/v1/delegation/create) with explicit delegation IDs. The same API key linking and selection concepts apply to both providers.Three-Tier Resolution
When an agent callsPOST /access-token/from-nvm-key, NVM Pay resolves the mandate in this order:
Mode 1: Explicit Mandate ID
If the agent passes a NVM Pay validates:
mandateId in the request body, NVM Pay uses that mandate directly. No ambiguity, the agent knows exactly which mandate it wants.- The mandate exists and is
active - The mandate has remaining usage (
usageCount < maxUsage) - The mandate amount covers the requested amount
- If the mandate is linked to an API key, it must match the calling key
- The associated card is active and belongs to the authenticated user
Mode 2: Key-Linked Mandate
If no NVM Pay collects all mandates where
mandateId is passed, NVM Pay checks if any mandate is linked to the calling API key. If exactly one key-linked mandate matches, it’s selected automatically.This is the recommended approach for production setups with multiple mandates. Link each API key to a specific mandate and the routing is deterministic.mandate.apiKeyId === calling_key.skId, then filters for active, valid, and unused mandates.Key-linked mandates always take priority over unlinked ones.Decision Flowchart
When to Use Each Mode
Explicit ID
Multiple mandates, full control. Pass
mandateId per request.Key-Linked
One mandate per API key. Set it once, forget it.
Unlinked
Single mandate, zero config. Just create and go.
Linking an API Key
API key linking works the same way for both Visa mandates and Stripe delegations.When Creating
In the Nevermined Pay dashboard, open the Create Mandate or Create Delegation dialog and select an API key from the dropdown. Only active, non-browser API keys that aren’t already linked to another authorization are shown.When Updating
Use the Update dialog in the dashboard to change or remove the linked API key. You can:- Link to a different API key
- Unlink (set to “none”) to make the authorization available as a fallback
Linking an API key is optional but recommended when you have two or more active mandates or delegations. Without it, NVM Pay can’t automatically determine which one to use and will return an error.
Error Handling
Multiple Mandates Found
mandateId explicitly, or link one of the mandates to your API key in the dashboard.
No Active Mandate Found
- All mandates are exhausted (usage limit reached)
- All mandates have expired
- Mandate amount is less than the requested amount
- Mandates are linked to a different API key
Mandate Linked to Different Key
mandateId you passed is linked to a different API key than the one you’re authenticating with. Use the correct API key, or update the mandate’s key link.
Amount Insufficient
API Reference
Generate Token from NVM Key (Visa)
| Field | Required | Description |
|---|---|---|
amount | Yes | Payment amount in USD |
mandateId | No | Explicit mandate ID (Mode 1). If omitted, auto-resolution is used. |
resource | No | Resource URL for the x402 payload |
payTo | No | Merchant/payee identifier |
payloadEncoded value goes in the payment-signature HTTP header when calling a protected resource.
Error responses:
| Status | Reason |
|---|---|
| 400 | Multiple mandates, mandate exhausted, amount insufficient, invalid request |
| 403 | Mandate linked to a different API key, mandate doesn’t belong to user |
| 404 | No active mandate found, mandate ID not found |
Stripe Delegation Flow
For Stripe, the delegation is selected explicitly when creating it. Use the delegation API:Best Practices
- Start simple. If you have one mandate or delegation, you don’t need to link API keys or pass explicit IDs. Just create the authorization and call the API.
- Link keys for production. When you add a second authorization, link each API key to a specific mandate or delegation. This gives you deterministic routing without code changes.
-
Use explicit IDs for complex setups. If an agent works with multiple mandates dynamically (e.g., different mandates for different pricing tiers), pass the
mandateIdin each request. - Monitor usage. Check usage counts against limits to know when authorizations are close to exhaustion. Create new ones before the old ones run out.
- Set reasonable expiration times. Don’t create authorizations that last indefinitely. Set expiration aligned with your billing cycles.