Create and manage payment plans with the TypeScript SDK
plans
const { planId } = await payments.plans.createPlan({ agentId, name, description, priceConfig, creditsConfig, accessLimit })
import { getERC20PriceConfig, getFixedCreditsConfig } from '@nevermined-io/payments' const { planId } = await payments.plans.createPlan({ agentId: 'did:nv:agent-123', name: 'Pro Plan', description: '100 queries for $10', priceConfig: getERC20PriceConfig(10_000_000n, usdcAddress, builderAddress), creditsConfig: getFixedCreditsConfig(100n, 1n), accessLimit: 'credits' })
const result = await payments.plans.orderPlan(planId)
interface OrderResult { transactionHash: string agreementId: string success: boolean }
const { sessionId, url } = await payments.plans.orderFiatPlan(planId) // Redirect user to Stripe window.location.href = url
const balance = await payments.plans.getPlanBalance(planId)
interface PlanBalance { credits: number expiresAt?: Date isActive: boolean }
const { planId } = await payments.plans.registerCreditsTrialPlan({ agentId, name: 'Free Trial', description: '10 free queries', credits: 10n, creditsPerRequest: 1n })
const { planId } = await payments.plans.registerTimeTrialPlan({ agentId, name: '7-Day Trial', description: 'Full access for 7 days', duration: 7 * 24 * 60 * 60 // seconds })
import { getERC20PriceConfig } from '@nevermined-io/payments' const config = getERC20PriceConfig( 10_000_000n, // amount (with decimals) '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // token address '0xYour...Address' // receiver address )
import { getNativePriceConfig } from '@nevermined-io/payments' const config = getNativePriceConfig( 1_000_000_000_000_000n, // 0.001 ETH '0xYour...Address' )
import { getFixedCreditsConfig } from '@nevermined-io/payments' const config = getFixedCreditsConfig( 100n, // total credits 1n // credits per request )
import { getDynamicCreditsConfig } from '@nevermined-io/payments' const config = getDynamicCreditsConfig( 1n, // minimum per request 10n // maximum per request )
import { getTimeBasedConfig } from '@nevermined-io/payments' const config = getTimeBasedConfig( 30 * 24 * 60 * 60 // 30 days in seconds )
interface CreatePlanParams { agentId: string name: string description?: string priceConfig: PriceConfig creditsConfig?: CreditsConfig timeConfig?: TimeConfig accessLimit: 'credits' | 'time' } interface PriceConfig { tokenAddress: string amount: bigint receiver: string } interface CreditsConfig { totalCredits: bigint creditsPerRequest: bigint }