Skip to content

Commit

Permalink
feat: support order and download calls to the backend2
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed May 6, 2024
1 parent 9ca3748 commit 67d64e3
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,52 @@ export class Payments {
return response.json()
}

/**
* Orders a subscription.
*
* @param subscriptionDid - The subscription DID.
* @param agreementId - The agreement ID.
* @returns A promise that resolves to the agreement ID and a boolean indicating if the operation was successful.
*/
public async orderSubscription(subscriptionDid: string, agreementId?: string): Promise<{ agreementId: string, success: boolean }> {

const body = { subscriptionDid, agreementId, 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/order', this.environment.backend)
const response = await fetch(url, options)
if (!response.ok) {
throw Error(response.statusText)
}

return response.json()
}

public async downloadFiles(did: string) {
const body = { did, 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/file/download', this.environment.backend)
const response = await fetch(url, options)
if (!response.ok) {
throw Error(response.statusText)
}

return response.json()
}

/**
* Redirects the user to the subscription details for a given DID.
* @param did - The DID (Decentralized Identifier) of the subscription.
Expand Down

0 comments on commit 67d64e3

Please sign in to comment.