Private
constructorInitialize the payments class.
The options to initialize the payments class.
An instance of Payments
Optional
accountOptional
appPrivate
Optional
nvmOptional
versionProperty to check if a user logged in.
True if the user is logged in.
payments.isLoggedIn
Burn credits for a given Payment Plan DID.
The DID (Decentralized Identifier) of the asset.
The amount of NFT (Non-Fungible Token) credits to burn.
A Promise that resolves to the JSON response from the server.
This method is only can be called by the owner of the Payment Plan.
Error if the server response is not successful.
It creates a new AI Agent on Nevermined. The agent must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent. Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits. When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.
Optional
amountOptional
apiOptional
authOptional
curation?: objectOptional
endpoints?: Endpoint[]Optional
implementsOptional
integration?: stringOptional
maxOptional
minOptional
openOptional
openOptional
password?: stringOptional
sampleOptional
tags?: string[]Optional
token?: stringOptional
username?: stringOptional
usesAIHub?: booleanA promise that resolves to the created agent DID.
This method is oriented to AI Builders
const agentDID = await paymentsBuilder.createService({
planDID,
name: 'E2E Payments Agent',
description: 'description',
serviceType: 'agent',
serviceChargeType: 'fixed',
authType: 'bearer',
token: 'changeme',
amountOfCredits: 1,
endpoints: agentEndpoints,
openEndpoints: ['https://example.com/api/v1/rest/docs-json']
})
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.
Optional
tags?: string[]The unique identifier of the plan (Plan DID) of the newly created plan.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/create-plan
const { did } = await payments.createCreditsPlan({
name: "My AI Payments Plan",
description: "AI stuff",
price: 10000000n,
tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
amountOfCredits: 30,
tags: ["test"]
})
It creates a new asset with file associated to it. The file asset must be associated to a Payment Plan. Users that are subscribers of a payment plan can download the files attached to it. Depending on the Payment Plan and the configuration of the file asset, the download will consume credits. When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue downloading the files.
Optional
amountOptional
curation?: objectOptional
dataOptional
filesOptional
fineOptional
framework?: stringOptional
maxOptional
minOptional
programmingOptional
sampleOptional
tags?: string[]Optional
task?: stringOptional
trainingOptional
usageOptional
variations?: stringThe promise that resolves to the created file's DID.
This method is oriented to AI Builders
It creates a new AI Agent or Service on Nevermined. The agent/service must be associated to a Payment Plan. Users that are subscribers of a payment plan can access the agent/service. Depending on the Payment Plan and the configuration of the agent/service, the usage of the agent/service will consume credits. When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent/service.
Optional
amountOptional
apiOptional
authOptional
curation?: objectOptional
endpoints?: Endpoint[]Optional
implementsOptional
integration?: stringOptional
maxOptional
minOptional
openOptional
openOptional
password?: stringOptional
sampleOptional
tags?: string[]Optional
token?: stringOptional
username?: stringOptional
usesAIHub?: booleanA promise that resolves to the created agent DID.
This method is oriented to AI Builders
const agentEndpoints: Endpoint[] = [
{ 'POST': `https://example.com/api/v1/agents/(.*)/tasks` },
{ 'GET': `https://example.com/api/v1/agents/(.*)/tasks/(.*)` }
]
const agentDID = await paymentsBuilder.createService({
planDID,
name: 'E2E Payments Agent',
description: 'description',
serviceType: 'agent',
serviceChargeType: 'fixed',
authType: 'bearer',
token: 'changeme',
amountOfCredits: 1,
endpoints: agentEndpoints,
openEndpoints: ['https://example.com/api/v1/rest/docs-json']
})
It allows to an AI Builder to create a Payment Plan on Nevermined based on Time. A Nevermined Time Plan limits the access by the a specific amount of time. With them, AI Builders can specify the duration of the Payment Plan (1 month, 1 year, etc.). When the time period is over, the plan automatically expires and the user needs to renew it.
Optional
duration?: numberOptional
tags?: string[]The unique identifier of the plan (Plan DID) of the newly created plan.
This method is oriented to AI Builders
https://docs.nevermined.app/docs/tutorials/builders/create-plan
const { did } = await payments.createTimePlan({
name: "My 1 Month Plan",
description: "test",
price: 10000000n,
tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
duration: 30,
tags: ["test"]
})
Get the balance of an account for a Payment Plan.
The Payment Plan DID of the service to be published.
Optional
accountAddress: stringThe address of the account to get the balance.
A promise that resolves to the balance result.
Get the required configuration for accessing a remote service agent. This configuration includes:
The DID of the agent/service.
A promise that resolves to the service token.
const accessConfig = await payments.getServiceAccessConfig(agentDID)
console.log(`Agent JWT Token: ${accessConfig.accessToken}`)
console.log(`Agent Proxy URL: ${accessConfig.neverminedProxyUri}`)
Method to initialize the class once the user has been logged in. This method should be called has soon as the user has been redirected back to the app (returnUrl).
This is a browser only function.
payments.init()
You may want to use useEffect
on the route that matches the passed
returnUrl
useEffect(() => {
payments.init()
})
Private
initializeMint credits for a given Payment Plan DID and transfer them to a receiver.
The DID (Decentralized Identifier) of the asset.
The amount of NFT (Non-Fungible Token) credits to mint.
The address of the receiver where the credits will be transferred.
A Promise that resolves to the JSON response from the server.
This method is only can be called by the owner of the Payment Plan.
Error if the server response is not successful.
Orders a Payment Plan. The user needs to have enough balance in the token selected by the owner of the Payment Plan.
The Payment Plan DID of the service to be published.
Optional
agreementId: stringThe unique identifier of the purchase transaction (aka agreement ID). When this parameter is given, it assumes there is a previous payment step and will request the payment plan.
A promise that resolves to the agreement ID and a boolean indicating if the operation was successful.
The payment is done using Crypto. Payments using Fiat can be done via the Nevermined App.
Private
parseStatic
getThe options get's an instance of the payments class to be used in the browser.
The options to initialize the payments class.
An instance of Payments
This is a browser only function.
const payments = Payments.getBrowserInstance({
returnUrl: 'https://mysite.example',
environment: 'testing',
appId: 'my-app-id',
version: '1.0.0'
})
Static
getThe options get's an instance of the payments class.
The options to initialize the payments class.
An instance of Payments
const payments = Payments.getInstance({
nvmApiKey: 'kjdfaofakdoasdkoas',
environment: 'testing'
})
Main class that interacts with the Nevermined payments API. To get an instance of this class use the
getInstance
method.