Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support more methods #15

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/payments",
"version": "0.1.5",
"version": "0.1.6",
"description": "Typescript SDK to interact with the Nevermined Payments Protocol",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
49 changes: 49 additions & 0 deletions src/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,55 @@ export class Payments {
return response.json()
}

/**
* Get the DDO for a given DID.
*
* @param did - The DID of the asset.
* @returns A promise that resolves to the DDO.
*/
public async getAssetDDO(did: string) {
const url = new URL(`/api/v1/payments/asset/ddo/${did}`, this.environment.backend)
const response = await fetch(url)
if (!response.ok) {
throw Error(response.statusText)
}

return response.json()
}

/**
* Get the balance of an account for a subscription.
*
* @param subscriptionDid - The subscription DID of the service to be published.
* @param accountAddress - The address of the account to get the balance.
* @returns A promise that resolves to the balance result.
*/
public async getSubscriptionBalance(
subscriptionDid: string,
accountAddress?: string,
): Promise<{ subscriptionType: string; isOwner: boolean; balance: bigint }> {
const body = {
subscriptionDid,
accountAddress,
sessionKey: this.sessionKey,
}
const options = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
}
const url = new URL('/api/v1/payments/subscription/balance', this.environment.backend)
const response = await fetch(url, options)
if (!response.ok) {
throw Error(response.statusText)
}

return response.json()
}

/**
* Get the service token for a given DID.
*
Expand Down