# Class: SubscriptionPlans

## SubscriptionPlans(options)

Service class to handle interacting with the Cask subscription plans system

## Constructor

#### new SubscriptionPlans(options)

Create an instance of the SubscriptionPlans service.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` |  | See CaskSDK configuration.

See:
  - CaskSDK

### Methods

#### (async) disablePlan(planId) → {Promise.<{tx: *}>}

Disable a plan from accepting any new subscriptions. No existing subscriptions are canceled.

##### Parameters:

Name | Type | Description
--- | --- | ---
`planId` |  | Plan ID

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) enablePlan(planId) → {Promise.<{tx: *}>}

Re-enable a previously disabled plan to be able to accept new subscriptions again.

##### Parameters:

Name | Type | Description
--- | --- | ---
`planId` |  | Plan ID

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) getDiscountRedemptions(discountId) → {Promise.<string>}

Get the number of redemptions a specific plan/discountId has already had.

##### Parameters:

Name | Type | Description
--- | --- | ---
`discountId` |  | Discount ID

##### Returns:

Type
  Promise.<string>

#### (async) getProfile(address, options) → {Promise.<(ProviderProfile|null)>}

Get the provider profile for an address.

##### Parameters:

Name | Type | Description
--- | --- | ---
`address` |  | Provider address
`options` | Object | Options ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`force` |  | <optional> | false | Force re-fetching profile even if it was previously loaded

##### Returns:

Type
  Promise.<(ProviderProfile|null)>

#### (async) hasProviderProfile(address) → {Promise.<boolean>}

Check if a given address is registered as a service provider.

##### Parameters:

Name | Type | Description
--- | --- | ---
`address` |  |

##### Returns:

Type
  Promise.<boolean>

#### (async) history(provider, planId)

Get history for a provider and optionally a specific plan

##### Parameters:

Name | Type | Description
--- | --- | ---
`provider` | string | Provider address
`planId` | number | Plan ID

#### (async) init(args)

Initialize the subscription plans service.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | Object | Function arguments ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`ethersConnection` | EthersConnection | <optional> | EthersConnection instance

#### (async) loadProfile(addressopt, forceopt) → {Promise.<ProviderProfile>}

Load the (or create a new non-published) service provider profile for an address.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`address` |  | <optional> | ethersConnection.address | Provider address or attempts to use the blockchain connection address
`force` |  | <optional> | false | Force reloading profile even if it was previously loaded

##### Returns:

Type
  Promise.<ProviderProfile>

#### (async) planStatus(planId) → {Promise.<number>}

Get the current plan status of a specific plan.

##### Parameters:

Name | Type | Description
--- | --- | ---
`planId` |  | Plan ID

##### Returns:

Type
  Promise.<number>

#### (async) publishProfile() → {Promise.<{tx: *}>}

Publish a provider profile. Uploads profile to IPFS and performs a blockchain transaction to store the new provider CID on-chain.

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) retirePlan(planId, retireAtopt) → {Promise.<{tx: *}>}

Permanently retire a specific plan. Any active subscriptions to the plan will be canceled at their next renewal date. This cannot be undone.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`planId` |  |  |  | Plan ID
`retireAt` |  | <optional> | now | Unix timestamp of when to retire plan, defaults to now.

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) verifyDiscount(planId, discountId) → {Promise.<boolean>}

Verify the given plan/discountId is currently valid. Throws an error if is not currently valid that includes the reason.

##### Parameters:

Name | Type | Description
--- | --- | ---
`planId` |  | Plan ID
`discountId` |  | Discount ID

##### Returns:

Type
  Promise.<boolean>