Skip to content

Commit 72fb27f

Browse files
authored
Merge pull request #15 from nevermined-io/feat/support-more-methods
feat: support more methods
2 parents efd010f + 4b3040d commit 72fb27f

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nevermined-io/payments",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Typescript SDK to interact with the Nevermined Payments Protocol",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/payments.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,55 @@ export class Payments {
464464
return response.json()
465465
}
466466

467+
/**
468+
* Get the DDO for a given DID.
469+
*
470+
* @param did - The DID of the asset.
471+
* @returns A promise that resolves to the DDO.
472+
*/
473+
public async getAssetDDO(did: string) {
474+
const url = new URL(`/api/v1/payments/asset/ddo/${did}`, this.environment.backend)
475+
const response = await fetch(url)
476+
if (!response.ok) {
477+
throw Error(response.statusText)
478+
}
479+
480+
return response.json()
481+
}
482+
483+
/**
484+
* Get the balance of an account for a subscription.
485+
*
486+
* @param subscriptionDid - The subscription DID of the service to be published.
487+
* @param accountAddress - The address of the account to get the balance.
488+
* @returns A promise that resolves to the balance result.
489+
*/
490+
public async getSubscriptionBalance(
491+
subscriptionDid: string,
492+
accountAddress?: string,
493+
): Promise<{ subscriptionType: string; isOwner: boolean; balance: bigint }> {
494+
const body = {
495+
subscriptionDid,
496+
accountAddress,
497+
sessionKey: this.sessionKey,
498+
}
499+
const options = {
500+
method: 'POST',
501+
headers: {
502+
Accept: 'application/json',
503+
'Content-Type': 'application/json',
504+
},
505+
body: JSON.stringify(body),
506+
}
507+
const url = new URL('/api/v1/payments/subscription/balance', this.environment.backend)
508+
const response = await fetch(url, options)
509+
if (!response.ok) {
510+
throw Error(response.statusText)
511+
}
512+
513+
return response.json()
514+
}
515+
467516
/**
468517
* Get the service token for a given DID.
469518
*

0 commit comments

Comments
 (0)