DaisySDK

browser~ DaisySDK

Browser SDK class. This requires a module:common~SubscriptionManager object to be instantiated and a web3 instance. The web3 instance should come from react-metamask.

Constructor

new DaisySDK()

Source:
See:

Extends

Methods

(async) getData() → {Promise.<SubscriptionManager>}

Source:
Overrides:

Get Subscription Manager data and plans.

Example
const subscriptionProduct = new SubscriptionProductClient({
  identifier: process.env.DAISY_ID,
});
const { plans, ...manager } = await subscriptionProduct.getData();
Returns:
  • Subscription Manager and Plans given the manager in the constructor.
Type
Promise.<SubscriptionManager>

getPlans()

Source:
Overrides:
Deprecated:

(async) getReceipts(criteria) → {Promise.<Array.<Receipt>>}

Source:
Overrides:

Get receipts from single subscription.

Parameters:
Name Type Description
criteria Object

Filtering criteria, only one field is required.

Properties
Name Type Description
daisyId string

Find Subscription based on a Daisy ID.

onChainId string

Find Subscription based on a onChainId in the blockchain.

Returns:
  • Receipts.
Type
Promise.<Array.<Receipt>>

(async) getSubscription(criteria) → {Promise.<?Subscription>}

Source:
Overrides:

Get single subscription.

Example
const subscriptionProduct = new SubscriptionProductClient({
  identifier: process.env.DAISY_ID,
});
const subscription = await subscriptionProduct.getSubscription({ id: "" });
Parameters:
Name Type Description
criteria Object

Filtering criteria, only one field is required.

Properties
Name Type Description
daisyId string

Find Subscription based on a Daisy ID.

onChainId string

Find Subscription based on a onChainId in the blockchain.

Returns:
  • Subscription found.
Type
Promise.<?Subscription>

(async) getSubscriptions(filter) → {Promise.<Array.<Subscription>>}

Source:
Overrides:

Get subscriptions.

Example
const subscriptionProduct = new SubscriptionProductClient({
  identifier: process.env.DAISY_ID,
});
const subscriptions = await subscriptionProduct.getSubscriptions({ account: "0x0..." });
Parameters:
Name Type Description
filter Object

Filtering criteria.

Properties
Name Type Description
account string

Filter by Ethereum address.

state string

Filter by subscription state.

Returns:
  • Subscriptions based on the filtering criteria.
Type
Promise.<Array.<Subscription>>

loadToken(inputopt) → {external:"web3.eth.Contract"}

Source:

Load token's web3 contract as external:"web3.eth.Contract".

Example
const daisy = new DaisySDK({
  identifier: process.env.DAISY_ID,
}, web3);
await daisy.sync(); // load manager

const token = daisy.loadToken(); // the token is taken from the `manager`.
Parameters:
Name Type Attributes Default Description
input Object <optional>
{}

Optional input argument.

Properties
Name Type Attributes Description
symbol string <optional>

Load a ERC20 token with Web3 using its symbol.

address string <optional>

Load a ERC20 token with Web3 using its address.

Returns:
  • Ethereum contract.
Type
external:"web3.eth.Contract"

prepareToken(token) → {module:browser.DaisySDKToken}

Source:

Takes an Web3's contract instance and wraps it into a module:browser.DaisySDKToken.

Parameters:
Name Type Description
token external:"web3.eth.Contract"

Web3's contract instance from module:browser~DaisySDK#loadToken.

Returns:

Wrapped token.

Type
module:browser.DaisySDKToken

(async) submit(input) → {Promise.<Subscription>}

Source:
Overrides:

Create single subscription.

Example
const subscriptionProduct = new SubscriptionProductClient({
  identifier: process.env.DAISY_ID,
});
const subscription = await subscriptionProduct.submit({ });
Parameters:
Name Type Description
input Object

Input arguments

Properties
Name Type Attributes Description
agreement Object

The agreement is the return of module:browser.DaisySDKToken#sign.

receipt Object <optional>

Optional. The receipt is the return of module:browser.DaisySDKToken#approve.

signature string

The signature is the return of module:browser.DaisySDKToken#sign.

Returns:
Type
Promise.<Subscription>

(async) submitCancel(input) → {Promise.<Subscription>}

Source:
Overrides:

Submit signature and agreement from the beneficiary user to cancel a subscription.

Parameters:
Name Type Description
input Object

Input arguments

Properties
Name Type Description
agreement Object

The agreement is the return of module:browser.DaisySDKToken#signCancel.

signature string

The signature is the return of module:browser.DaisySDKToken#signCancel.

Returns:
Type
Promise.<Subscription>

(async) sync() → {this}

Source:

If this class is instantiated only with module:common~SubscriptionManager#identifier this call is necessary to fetch the subscription's manager data.

Examples
const daisy = new DaisySDK({ identifier: ... }, web3);
await daisy.sync() // required
const daisy = new DaisySDK(manager, web3); // not required here.
Returns:
  • Return self instance.
Type
this