Class: ProviderProfile

ProviderProfile()

A service provider profile containing all the plans and discounts for a service provider.

Constructor

new ProviderProfile()

This class is meant to be instantiated from within the SubscriptionPlans service, not directly.
See:

Members

discounts

Map of DiscountId to Discount object.
See:

plans

Map of planId to Plan object.
See:

Methods

asProfileObject() → {Object}

Convert the profile into an Object suitable for serializing to IPFS.
Returns:
Type
Object

getDiscount(args) → {Plan}

Get a discount from the provider profile.
Parameters:
Name Type Description
args Object Function arguments
Properties
Name Type Attributes Default Description
discountId string Discount ID
units string <optional>
Units of output
unitOptions Object <optional>
{} Options passed to unit formatter.
See:
Returns:
Type
Plan

getPlan(args) → {Plan}

Get a plan from the provider profile.
Parameters:
Name Type Description
args Object Function arguments
Properties
Name Type Attributes Default Description
planId number Plan ID
units string <optional>
Units of output
unitOptions Object <optional>
{} Options passed to unit formatter.
See:
Returns:
Type
Plan

incrementNonce()

Increment the internal nonce of the profile.

(async) loadFromIPFS(cid)

Load a profile from a given IPFS CID.
Parameters:
Name Type Description
cid IPFS CID.

merkleCommitment() → {string}

Merkle commitment of profile.
Returns:
Type
string

needsPublish() → {boolean}

Check if the profile has unpublished changes.
Returns:
Type
boolean

removeDiscount(discountId)

Remove a discount from the profile.
Parameters:
Name Type Description
discountId Discount ID

removePlan(planId)

Remove a plan from the provider profile.
Parameters:
Name Type Description
planId Plan ID

(async) saveToIPFS()

Saves current profile data to IPFS.

setDiscount(args)

Add/update a discount in the profile. Specify either the discountId or raw discountCode for the new discount. Must specify the discount identified as one of `discountId`, `discountCode`, 'discountNFTAddress' or `discountERC20Address`.
Parameters:
Name Type Description
args Object Function arguments
Properties
Name Type Attributes Default Description
discountId string <optional>
Discount ID of the new or existing discount
discountCode string <optional>
Specify the raw Discount Code for discount instead of discountId
discountNFTAddress string <optional>
Contract address of token for NFT discount
discountERC20Address string <optional>
Contract address of token for ERC20 balance discount
discountERC20Decimals number <optional>
0 Number of decimals of token for ERC20 balance discount
discountERC20MinBalance number <optional>
1 Min number of tokens required to be held for ERC20 balance discount
discountCode string <optional>
Specify the raw Discount Code for discount instead of discountId
description string <optional>
Human readable description of the discount to be displayed to end users
value number <optional>
Either the BPS (basis points) or fixed value of the discount, depending on isFixed parameter
valueSimple number <optional>
If using fixed discount, amount can be alternatively specified using valueSimple or valueAsset
valueAsset number <optional>
If using fixed discount, amount can be alternatively specified using valueSimple or valueAsset
validAfter number <optional>
0 Timestamp at which point discount becomes redeemable. Use 0 to allow immediate redemption.
expiresAt number <optional>
0 Timestamp at which point discount becomes non-redeemable. Use 0 for no expiration.
maxRedemptions number <optional>
0 Max number of redemptions (per chain). 0 allows unlimited redemptions.
planId number <optional>
0 Limit discount to a specific plan ID. 0 allows redemption from any plan.
applyPeriods number <optional>
0 Number of periods discount applies for. Use 0 to set a discount that applies for the lifetime of the subscription.
discountType number <optional>
1 Discount type - 1 = code discount, 2 = ERC20 balance discount.
isFixed bool <optional>
false Set to true for value to be a fixed amount discount, false for value to represent a basis point percentage.
metadata Object <optional>
Optional metadata object to attach to the discount definition.

setMetadata(metadata)

Set metadata for provider profile
Parameters:
Name Type Description
metadata Metadata object

setPaymentAddress(paymentAddress)

Set payment address of provider profile
Parameters:
Name Type Description
paymentAddress Address to receive subscription payments

setPlan(args)

Add/update a plan to the provider profile.
Parameters:
Name Type Description
args Object Function arguments
Properties
Name Type Attributes Default Description
planId number Plan ID of the new or existing plan
name string Name of plan
price string <optional>
Alias for `priceAsset`
priceSimple float <optional>
Price of new plan denominated in vault baseAsset value (simple format)
priceAsset string <optional>
Price of new plan denominated in vault baseAsset value (asset format)
period number Plan period, in seconds
freeTrial number <optional>
0 Free trial length, in seconds. Use 0 for no free trial.
maxActive number <optional>
0 Maximum number of active subscriptions for the plan. Use 0 for unlimited.
minPeriods number <optional>
0 Minimum number of periods before subscription can be canceled. Use 0 for no minimum period.
gracePeriod number <optional>
Number of days for non-payment grace period, before canceling past due subscription
canPause boolean <optional>
true Can the consumer pause an active subscription
canTransfer boolean <optional>
false Can the consumer transfer the subscription NFT to another party
metadata Object <optional>
{} Optional metadata object to attach to the subscription

setSignedRoots(signedRoots)

Update the signed roots data of the provider profile.
Parameters:
Name Type Description
signedRoots Signed message data of the merkleroots representing the provider profile

(async) signMerkleRoots(signer) → {Promise.<string>}

Sign the profile merkleroots using the provided signer.
Parameters:
Name Type Description
signer Signer to use
Returns:
Type
Promise.<string>

updateMerkleRoots()

Update profile merkleroots using current profile plans/discounts.