import { Address, Currency, NvmAPIResult, PaginationOptions, PaymentOptions, PlanBalance, PlanCreditsConfig, PlanRedemptionType, PlanMetadata, PlanPriceConfig, StripeCheckoutResult } from '../common/types.js'; import { BasePaymentsAPI, PublicationOptions } from './base-payments.js'; /** * The PlansAPI class provides methods to register and interact with payment plans on Nevermined. */ export declare class PlansAPI extends BasePaymentsAPI { private contractsApi; constructor(options: PaymentOptions); /** Price helpers */ /** * Builds a Fiat price configuration for a plan. * * `amount` is in **6-decimal units** (USDC convention, NOT cents). To * charge $2.00, pass `2_000_000n`. Minimum is `1_000_000n` ($1.00) — * lower values are rejected server-side with `BCK.PROTOCOL.0047`. * * @param amount - Amount to charge in 6-decimal units (e.g. `2_000_000n` for $2.00) as bigint. * @param receiver - Wallet address that will receive the payment. * @param currency - Fiat currency code (default: 'USD'). Any ISO 4217 code accepted by Stripe. * @returns The PlanPriceConfig representing a fiat price. */ getFiatPriceConfig(amount: bigint, receiver: Address, currency?: Currency | string): PlanPriceConfig; /** * Builds a Pay-As-You-Go price configuration using the template address from the API. */ getPayAsYouGoPriceConfig(amount: bigint, receiver: Address, tokenAddress?: Address): Promise; /** * Builds a Pay-As-You-Go credits configuration. */ getPayAsYouGoCreditsConfig(): PlanCreditsConfig; /** * Builds a crypto price configuration for a plan. * * @param amount - Amount to charge in token minor units as bigint. * @param receiver - Wallet address that will receive the payment. * @param tokenAddress - Optional ERC20 token address. If omitted, native token is assumed. * @returns The PlanPriceConfig representing a crypto price. */ getCryptoPriceConfig(amount: bigint, receiver: Address, tokenAddress?: Address): PlanPriceConfig; /** * Builds an ERC20 price configuration for a plan. * * @param amount - Amount to charge in token minor units as bigint. * @param tokenAddress - ERC20 token contract address. * @param receiver - Wallet address that will receive the payment. * @returns The PlanPriceConfig representing an ERC20 price. */ getERC20PriceConfig(amount: bigint, tokenAddress: Address, receiver: Address): PlanPriceConfig; /** * Builds an EURC (Euro stablecoin) price configuration for a plan. * * @param amount - Amount to charge in EURC minor units (6 decimals) as bigint. * @param receiver - Wallet address that will receive the payment. * @param eurcAddress - Optional EURC token address. Defaults to Base Mainnet EURC. * @returns The PlanPriceConfig representing an EURC price. */ getEURCPriceConfig(amount: bigint, receiver: Address, eurcAddress?: Address): PlanPriceConfig; /** * Builds a FREE price configuration (no payment required). * @returns The PlanPriceConfig representing a free plan. */ getFreePriceConfig(): PlanPriceConfig; /** * Builds a native token price configuration for a plan. * * @param amount - Amount to charge in native token minor units as bigint. * @param receiver - Wallet address that will receive the payment. * @returns The PlanPriceConfig representing a native token price. */ getNativeTokenPriceConfig(amount: bigint, receiver: Address): PlanPriceConfig; /** Credits helpers */ /** * Builds an EXPIRABLE credits configuration (time-based access). * * @param durationOfPlan - Duration in seconds. * @returns The PlanCreditsConfig representing expirable credits. */ getExpirableDurationConfig(durationOfPlan: bigint): PlanCreditsConfig; /** * Builds a NON-EXPIRABLE credits configuration (no expiration). * @returns The PlanCreditsConfig representing non-expirable credits. */ getNonExpirableDurationConfig(): PlanCreditsConfig; /** * Builds a FIXED credits configuration. * * @param creditsGranted - Total credits granted by the plan. * @param creditsPerRequest - Credits spent per request (default 1n). * @returns The PlanCreditsConfig representing fixed credits. */ getFixedCreditsConfig(creditsGranted: bigint, creditsPerRequest?: bigint): PlanCreditsConfig; /** * Builds a DYNAMIC credits configuration (range-limited per request). * * @param creditsGranted - Total credits granted by the plan. * @param minCreditsPerRequest - Minimum credits per request. * @param maxCreditsPerRequest - Maximum credits per request. * @returns The PlanCreditsConfig representing dynamic credits. */ getDynamicCreditsConfig(creditsGranted: bigint, minCreditsPerRequest?: bigint, maxCreditsPerRequest?: bigint): PlanCreditsConfig; /** * Sets the redemption type in a credits configuration. * * @param creditsConfig - Credits configuration to modify. * @param redemptionType - Redemption type to set. * @returns The updated PlanCreditsConfig. */ setRedemptionType(creditsConfig: PlanCreditsConfig, redemptionType: PlanRedemptionType): PlanCreditsConfig; /** * Marks whether burns of these credits are mirrored on-chain. * * @param creditsConfig - Credits configuration to modify. * @param onchainMirror - Whether on-chain mirroring is enabled. Defaults * to `true` so calling `setOnchainMirror(config)` enables the mirror; * pass `false` explicitly to disable it. The `PlanCreditsConfig` * field itself defaults to `false` (set by all credits-config * builders) — when `false` the credits ledger lives in the API's * Postgres and burns are recorded off-chain only; when `true`, an * on-chain audit mirror replays each burn to `NFT1155Credits`. * @returns The updated PlanCreditsConfig. */ setOnchainMirror(creditsConfig: PlanCreditsConfig, onchainMirror?: boolean): PlanCreditsConfig; /** * This method is used to create a singleton instance of the PlansAPI class. * * @param options - The options to initialize the payments class. * @returns The instance of the PlansAPI class. */ static getInstance(options: PaymentOptions): PlansAPI; /** * * It allows to an AI Builder to register a Payment Plan on Nevermined in a flexible manner. * A Payment Plan defines 2 main aspects: * 1. What a subscriber needs to pay to get the plan (i.e. 100 USDC, 5 USD, etc). * 2. What the subscriber gets in return to access the AI agents associated to the plan (i.e. 100 credits, 1 week of usage, etc). * * With Payment Plans, AI Builders control the usage to their AI Agents. * * Every time a user accesses an AI Agent to the Payment Plan, the usage consumes from a capped amount of credits (or when the plan duration expires). * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service. * * @remarks * This method is oriented to AI Builders. * The NVM API Key must have publication permissions. * * @see https://nevermined.ai/docs/tutorials/builders/create-plan * * @param planMetadata - @see {@link PlanMetadata} * @param priceConfig - @see {@link PlanPriceConfig} * @param creditsConfig - @see {@link PlanCreditsConfig} * @param nonce - Optional nonce to prevent replay attacks. Default is a random BigInt. * @example * ``` * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress) * const creditsConfig = getFixedCreditsConfig(100n) * const { planId } = await payments.plans.registerPlan({ name: 'AI Assistants Plan'}, cryptoPriceConfig, creditsConfig) * ``` * * @returns The unique identifier of the plan (Plan ID) of the newly created plan. */ registerPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, nonce?: bigint, accessLimit?: 'credits' | 'time', publicationOptions?: PublicationOptions): Promise<{ planId: string; }>; /** * * It allows to an AI Builder to create a Payment Plan on Nevermined based on Credits. * A Nevermined Credits Plan limits the access by the access/usage of the Plan. * With them, AI Builders control the number of requests that can be made to an agent or service. * Every time a user accesses any resouce associated to the Payment Plan, the usage consumes from a capped amount of credits. * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service. * * @remarks This method is oriented to AI Builders * @remarks To call this method, the NVM API Key must have publication permissions * * @see https://nevermined.ai/docs/tutorials/builders/create-plan * * @param planMetadata - @see {@link PlanMetadata} * @param priceConfig - @see {@link PlanPriceConfig} * @param creditsConfig - @see {@link PlanCreditsConfig} * * @example * ``` * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress) * const creditsConfig = getFixedCreditsConfig(100n) * const { planId } = await payments.plans.registerCreditsPlan( * { name: 'AI Credits Plan'}, * cryptoPriceConfig, * creditsConfig * ) * ``` * * @returns The unique identifier of the plan (Plan ID) of the newly created plan. */ registerCreditsPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{ planId: string; }>; /** * * It allows to an AI Builder to create a Payment Plan on Nevermined limited by duration. * A Nevermined Credits Plan limits the access by the access/usage of the Plan. * With them, AI Builders control the number of requests that can be made to an agent or service. * Every time a user accesses any resouce associated to the Payment Plan, the usage consumes from a capped amount of credits. * When the user consumes all the credits, the plan automatically expires and the user needs to top up to continue using the service. * * @remarks This method is oriented to AI Builders * @remarks To call this method, the NVM API Key must have publication permissions * * @see https://nevermined.ai/docs/tutorials/builders/create-plan * * @param planMetadata - @see {@link PlanMetadata} * @param priceConfig - @see {@link PlanPriceConfig} * @param creditsConfig - @see {@link PlanCreditsConfig} * * @example * ``` * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress) * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION) * const { planId } = await payments.plans.registerTimePlan( * { name: 'Just for today plan'}, * cryptoPriceConfig, * 1dayDurationPlan * ) * ``` * * @returns The unique identifier of the plan (Plan ID) of the newly created plan. */ registerTimePlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{ planId: string; }>; /** * * It allows to an AI Builder to create a Trial Payment Plan on Nevermined limited by duration. * A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it. * A Trial plan is a plan that only can be purchased once by a user. * Trial plans, as regular plans, can be limited by duration (i.e 1 week of usage) or by credits (i.e 100 credits to use the agent). * @remarks This method is oriented to AI Builders * @remarks To call this method, the NVM API Key must have publication permissions * * @see https://nevermined.ai/docs/tutorials/builders/create-plan * * @param planMetadata - @see {@link PlanMetadata} * @param priceConfig - @see {@link PlanPriceConfig} * @param creditsConfig - @see {@link PlanCreditsConfig} * * @example * ``` * const freePriceConfig = getFreePriceConfig() * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION) * const { planId } = await payments.plans.registerCreditsTrialPlan( * {name: 'Trial plan'}, * freePriceConfig, * 1dayDurationPlan * ) * ``` * * @returns The unique identifier of the plan (Plan ID) of the newly created plan. */ registerCreditsTrialPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{ planId: string; }>; /** * * It allows to an AI Builder to create a Trial Payment Plan on Nevermined limited by duration. * A Nevermined Trial Plan allow subscribers of that plan to test the Agents associated to it. * A Trial plan is a plan that only can be purchased once by a user. * Trial plans, as regular plans, can be limited by duration (i.e 1 week of usage) or by credits (i.e 100 credits to use the agent). * @remarks This method is oriented to AI Builders * @remarks To call this method, the NVM API Key must have publication permissions * * @see https://nevermined.ai/docs/tutorials/builders/create-plan * * @param planMetadata - @see {@link PlanMetadata} * @param priceConfig - @see {@link PlanPriceConfig} * @param creditsConfig - @see {@link PlanCreditsConfig} * * @example * ``` * const freePriceConfig = getFreePriceConfig() * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION) * const { planId } = await payments.plans.registerTimeTrialPlan( * {name: '1 day Trial plan'}, * freePriceConfig, * 1dayDurationPlan * ) * ``` * * @returns The unique identifier of the plan (Plan ID) of the newly created plan. */ registerTimeTrialPlan(planMetadata: PlanMetadata, priceConfig: PlanPriceConfig, creditsConfig: PlanCreditsConfig, publicationOptions?: PublicationOptions): Promise<{ planId: string; }>; /** * Gets the information about a Payment Plan by its identifier. * * @param planId - The unique identifier of the plan. * @returns A promise that resolves to the plan's description. * @throws PaymentsError if the plan is not found. * @example * ``` * const plan = payments.plans.getPlan(planId) * ``` */ getPlan(planId: string): Promise; /** * Lists the payment plans **you** published (the authenticated caller's own * plans). This is account management, not a marketplace search — it never * returns other users' plans. * * @param page - The page number to retrieve. * @param offset - The number of items per page. * @param sortBy - The field to sort the results by. * @param sortOrder - The order in which to sort the results. * @param orgId - Optional organization id. When set, returns every plan in * that organization (requires active membership) instead of the caller's. * @returns A promise that resolves to the paginated list of your plans. */ getPlans(page?: number, offset?: number, sortBy?: string, sortOrder?: 'asc' | 'desc', orgId?: string): Promise<{ total: number; page: number; offset: number; plans: any[]; }>; /** * Gets the list of Agents that have associated a specific Payment Plan. * All the agents returned can be accessed by the users that are subscribed to the Payment Plan. * * @param planId - The unique identifier of the plan. * @param pagination - Optional pagination options to control the number of results returned. * @returns A promise that resolves to the list of agents associated with the plan. * @throws PaymentsError if the plan is not found. * * @example * ``` * const result = payments.plans.getAgentsAssociatedToAPlan(planId) * // { * // total: 10, * // page: 1, * // offset: 5, * // agents: [ ..] * // } * ``` */ getAgentsAssociatedToAPlan(planId: string, pagination?: PaginationOptions): Promise; /** * Gets the balance of an account for a Payment Plan. * * @param planId - The identifier of the Payment Plan. * @param accountAddress - The address of the account to get the balance for. * @returns @see {@link PlanBalance} A promise that resolves to the balance result. * @throws PaymentsError if unable to get the balance. * * ``` * const balance = payments.plans.getPlanBalance(planId) * // { * // planId: '105906633592154016712415751065660953070604027297000423385655551747721326921578', * // planType: 'credits', * // holderAddress: '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359', * // creditsContract: '0xdd0240858fE744C3BF245DD377abBC04d1FDA443', * // balance: '100', * // isSubscriber: true * // } * ``` * */ getPlanBalance(planId: string, accountAddress?: Address): Promise; /** * Orders a Payment Plan requiring the payment in crypto. The user must have enough balance in the selected token. * * @remarks * The payment is done using crypto in the token (ERC20 or native) defined in the plan. * * @param planId - The unique identifier of the plan. * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful. * @throws PaymentsError if unable to order the plan. * * @example * ``` * const result = await payments.plans.orderPlan(planId) * // { * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535', * // success: true * // } * ``` */ orderPlan(planId: string): Promise; /** * Initiates the purchase of a Plan requiring the payment in Fiat. This method will return a URL where the user can complete the payment. * * @remarks * The payment is completed using a credit card in a external website (Stripe). * @remarks * This method is only valid for plans with price in Fiat. * * @param planId - The unique identifier of the plan. * @returns A promise that resolves indicating the URL to complete the payment. * @throws PaymentsError if unable to order the plan. * * @example * ``` * const result = await payments.plans.orderFiatPlan(planId) * ``` */ orderFiatPlan(planId: string): Promise<{ result: StripeCheckoutResult; }>; /** * Mints credits for a given Payment Plan and transfers them to a receiver. * * @remarks * Only the owner of the Payment Plan can call this method. * * @param planId - The unique identifier of the Payment Plan. * @param creditsAmount - The number of credits to mint. * @param creditsReceiver - The address of the receiver. * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation. * @throws PaymentsError if unable to mint credits. * * @example * ``` * const result = await payments.plans.mintPlanCredits(planId, 5n, '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359') * // { * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535', * // success: true * // } * ``` */ mintPlanCredits(planId: string, creditsAmount: bigint, creditsReceiver: Address): Promise; /** * Mints expirable credits for a given Payment Plan and transfers them to a receiver. * * @remarks * Only the owner of the Payment Plan can call this method. * * @param planId - The unique identifier of the Payment Plan. * @param creditsAmount - The number of credits to mint. * @param creditsReceiver - The address of the receiver. * @param creditsDuration - The duration of the credits in seconds. Default is 0 (no expiration). * @returns @see {@link NvmAPIResult} A promise that resolves to the result of the operation. * @throws PaymentsError if unable to mint expirable credits. * * @example * ``` * const result = await payments.plans.mintPlanExpirable( * planId, * 1n, * '0x505384192Ba6a4D4b50EAB846ee67db3b9A93359', * 86_400n // 1 day in seconds * ) * // { * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535', * // success: true * // } * ``` */ mintPlanExpirable(planId: string, creditsAmount: bigint, creditsReceiver: Address, creditsDuration?: bigint): Promise; } //# sourceMappingURL=plans-api.d.ts.map