Function buildPaymentRequired

  • Build an X402PaymentRequired object for verify/settle operations.

    This helper simplifies the creation of payment requirement objects that are needed for the facilitator API.

    Parameters

    • planId: string

      The Nevermined plan identifier (required)

    • Optional options: {
          agentId?: string;
          description?: string;
          endpoint?: string;
          httpVerb?: string;
          network?: string;
      }

      Optional configuration with endpoint, agentId, httpVerb, network, description

      • Optional agentId?: string
      • Optional description?: string
      • Optional endpoint?: string
      • Optional httpVerb?: string
      • Optional network?: string

    Returns X402PaymentRequired

    X402PaymentRequired object ready to use with verifyPermissions/settlePermissions

    Example

    import { buildPaymentRequired } from '@nevermined-io/payments'

    const paymentRequired = buildPaymentRequired('123456789', {
    endpoint: '/api/v1/agents/task',
    agentId: '987654321',
    httpVerb: 'POST'
    })

    const result = await payments.facilitator.verifyPermissions({
    paymentRequired,
    x402AccessToken: token,
    maxAmount: 2n
    })