# User Subscription Model

## Table of Contents

* [Initiate UserSubscription Class](#initiate-usersubscription-class)
* [Properties of UserSubscription  response](#properties-of-the-usersubscription-response)
* [Prototypes](#prototypes)
* [Membership subscription Response](#membership-subscription-response)

### Initiate UserSubscription Class

```javascript
 const userSubscriptionInstance = new UserSubscription(subscription);
```
| Parameters   | Required | Type   | Description                              |
| -----------  | -------- | ------ | ---------------------------------------- |
| subscription | Yes      | Object | Membership [getUserDetails graphQl](../services/GRAPHQL.md#getUserDetails) subscription response |

### Properties of the UserSubscription Response

| Properties  | Type   | Description           | Example                                   |
| ----------  | ------ | --------------------- | -----------------------------------------
| status    | boolean | Indicates whether a subscription is currently active | true |
| fulfilmentOption | String | Type of delivery | HD  |
| productCodes  | Array<string> | The product codes that make up the product of the subscription | ['P1', 'N6D'] |
| productName | String | Name of the product | Standard Digital |
| reference   | String | The subscription number | A-XXXXXXXXXXX |
| renewalDate | String | The date the subscription will be renewed. Date of next payment | '2020-08-16T00:00:00.000Z' |
| createdDate | String | The date the subscription was created | '2020-08-16T00:00:00.000Z' |
| startDate | String | The date the subscription became active (for print subscribers, this will be the date of their first delivery) | '2020-08-16T00:00:00.000Z' |
| endDate | String | The date the subscription will end(useful for single term users) | '2020-08-16T00:00:00.000Z' |
| price | [Amount](../../src/types/offer.ts)  | Value, currency, symbol and nativeSymbol for the product price | { currency: 'GBR', nativeSymbol: '£', symbol: '£', value: '500.00' } |
| trialEndDate | String  | Last day of the trial   | '2020-08-15T00:00:00.000Z' |
| trialPrice  | [Amount](../../src/types/offer.ts)  | Value, currency, symbol and nativeSymbol for the product price | { currency: 'GBR', nativeSymbol: '£', symbol: '£', value: '1.00' } |
| availableActions | Array[String] | The available actions which can be made on the subscription | Renew, Cancel, UndoCancel, UndoTransition, UndoStepUp |

### Prototypes

* [isDigitalProduct](#isDigitalProduct)
* [isStandardProduct](#isStandardProduct)
* [isPremiumProduct](#isPremiumProduct)
* [isWeekendOnlyProduct](#isWeekendOnlyProduct)
* [isWeekdayOnlyProduct](#isWeekdayOnlyProduct)
* [isWeekdayWeekendProduct](#isWeekdayWeekendProduct)
* [isPrintTypeProduct](#isPrintTypeProduct)
* [isPrintProduct](#isPrintProduct)
* [isBundleProduct](#isBundleProduct)
* [isEpaperProduct](#isEpaperProduct)
* [isEpaperBundleProduct](#isEpaperBundleProduct)
* [isHomeDelivery](#isHomeDelivery)
* [isPaperVoucher](#isPaperVoucher)
* [isNewsletterOnlyProduct](#isNewsletterOnlyProduct)


#### isDigitalProduct

```javascript
const isDigitalProduct = userSubscriptionInstance.isDigitalProduct();
```

- Returns true if the product of the subscription is only digital.
- This does not include bundles.

```
	Parameters: none
	Response: boolean
```

#### isStandardProduct

```javascript
const isStandardProduct = userSubscriptionInstance.isStandardProduct();
```

- Returns true if the product of the subscription is a standard product.
- Digital or bundle.

```
	Parameters: none
	Response: boolean
```

#### isPremiumProduct

```javascript
const isPremiumProduct = userSubscriptionInstance.isPremiumProduct();
```

- Returns true if the product of the subscription is a premium product.
- Digital or bundle.

```
	Parameters: none
	Response: boolean
```

#### isPrintProduct

```javascript
const isPrintProduct = userSubscriptionInstance.isPrintProduct();
```

- Returns true if the product of the subscription is only a print product.
- This does not include bundles.

```
	Parameters: none
	Response: boolean
```

#### isWeekendOnlyProduct

```javascript
const isWeekendOnlyProduct = userSubscriptionInstance.isWeekendOnlyProduct();
```

- Returns true if the product of the subscription is only a weekend product.
- Print or bundle.

```
	Parameters: none
	Response: boolean
```

#### isWeekdayOnlyProduct

```javascript
const isWeekdayOnlyProduct = userSubscriptionInstance.isWeekdayOnlyProduct();
```

- Returns true if the product of the subscription is only a weekday product.
- Print or bundle.

```
	Parameters: none
	Response: boolean
```

#### isWeekdayWeekendProduct

```javascript
const isWeekdayWeekendProduct =
  userSubscriptionInstance.isWeekdayWeekendProduct();
```

- Returns true if the product of the subscription is a weekday and weekend product.
- Print or bundle.

```
	Parameters: none
	Response: boolean
```

#### isPrintTypeProduct

```javascript
const isPrintTypeProduct = userSubscriptionInstance.isPrintTypeProduct();
```

- Returns true if the product of the subscription contains a print product.
- Print or bundle.

```
	Parameters: none
	Response: boolean
```

#### isBundleProduct

```javascript
const isBundleProduct = userSubscriptionInstance.isBundleProduct();
```

- Returns true if the product of the subscription is a print and digital product (excluding niche email newsletter digital products).

```
	Parameters: none
	Response: boolean
```

#### isEpaperBundleProduct

```javascript
const isEpaperBundleProduct = userSubscriptionInstance.isEpaperBundleProduct();
```

- Returns true if the product of the subscription is a print product and ePaper.

```
	Parameters: none
	Response: boolean
```

#### isEpaperProduct

```javascript
const isBundleProduct = userSubscriptionInstance.isEpaperProduct();
```

- Returns true if the product of the subscription is for the ePaper.

```
	Parameters: none
	Response: boolean
```

#### isHomeDelivery

```javascript
const isHomeDelivery = userSubscriptionInstance.isHomeDelivery();
```

- Returns true if the print product of the subscription gets delivered to a personal address

```
	Parameters: none
	Response: boolean
```

#### isPaperVoucher

```javascript
const isPaperVoucher = userSubscriptionInstance.isPaperVoucher();
```

- Returns true if the print product of the subscription is claimed through a paper voucher.

```
	Parameters: none
	Response: boolean
```

#### isNewsletterOnlyProduct

```javascript
const isNewsletterOnlyProduct =
  userSubscriptionInstance.isNewsletterOnlyProduct();
```

- Returns true if the product code is one of the newletter only products

```
	Parameters: none
	Response: boolean
```

### Membership Subscription Response

- This is the subscription specific response from the userBySession request.
- Note this is just a fragment of the [entire response](./USER.md#Membership-User-Response).

```json
{
	"subscription": [
		{
			"active": true,
			"fulfilmentOption": "HD",
			"productCodes": ["n6d", "p2"],
			"productName": "productName",
			"reference": "subscriptionNumber",
			"renewalDate": "2020-08-16T00:00:00.000Z",
			"endDate": "2020-08-16T00:00:00.000Z",
			"trialEndDate": "2020-08-17T00:00:00.000Z",
			"productType": "DIGITAL",
			"trialPrice": {
				"currency": "GBR",
				"nativeSymbol": "£",
				"symbol": "£",
				"value": "500.00"
			},
			"price": {
				"currency": "GBR",
				"nativeSymbol": "£",
				"symbol": "£",
				"value": "500.00"
			}
		}
	]
}
```
