# AcquisitionContext Model

## Request

- When requesting `membershipSdk.getLicence`, a Licence instance is returned containing an array of `acquisitionContext` instances.

```javascript
try {
	const licence = await membershipSdk.getLicence(licenceId);
} catch (error) {
	throw error;
}
```

### Required Parameters

| Parameters   | Required | Type   | Description        | Example                             |
| ----------   | -------- | ------ | ------------------ | ----------------------------------- |
| licenceId | Yes      | String | The licence's Id. This can be retrieved from the [graphql.getRedeemableToken](../services/GRAPHQL.md#getRedeemableToken) | zyoRrJB7YEJC...|

**Response**: Returns a [Licence instance](../../src/models/licence.ts)

## Table of Contents

* [Initiate AcquisitionContext Class](#Initiate-AcquisitionContext-Class)
* [Acquisition Context Model Response](#AcquisitionContext-Model-Response)
* [Properties of the acquisitionContext response](#Properties-of-the-acquisitionContext-response)
* [Prototypes](#Prototypes)
* [Membership AcquisitionContext Response](#Membership-AcquisitionContext-Response)

### Initiate AcquisitionContext Class

```javascript
	const acquisitionContext = new AcquisitionContext(AcquisitionContextData);
```

| Parameters  | Required | Type   | Description                                | Example |
| ----------  | -------- | ------ | ------------------------------------------ | --------|
| acquisitionContextData | Yes   | Object | A mapped membership acquisition context data for a licence| see [Membership AcquisitionContext Response](#Membership-AcquisitionContext-Response) |

The membership response is mapped to the model [here](../../src/mappers/acquisition-context.ts).

### AcquisitionContext Model Response

```javascript
{
	displayName: 'Display Name',
	hasRestrictIpRanges: true,
	accessLicenceId: 'lienceId',
	hasRestrictEmailDomains: true,
	allowedEmailDomains: ['ExamPle.com', 'Example_2.com'],
	hasRestrictBlockedEmailDomains: true,
	blockedEmailDomains: ['BLOCKED.com'],
	signupWelcomeText: 'Welcome to your free trial'
}
```

### Properties of the acquisitionContext response

| Parameters          | Required | Type    | Description                               | Example      |
| ------------------- | -------- | ------- | ----------------------------------------- | ------------ |
| accessLicenceId | No | String | The licence id that this acquisitionContext refers to | zyoRrJB7YEJC... |
| displayName | No | String  | Name of the company or '**Marketing Campaigns Account**' | Financial Times |
| hasRestrictIpRanges | No | Boolean | The licence contains an array of IP address that are restricted | true |
| hasRestrictEmailDomains | No | Boolean | The licence contains an array of email domains that are restricted for the licence | true |
| allowedEmailDomains | No  | Array | The licence contains an array of email domains that are restricted | [ ft.com ] |
| hasRestrictBlockedEmailDomains | No | Boolean | The licence contains an array of email domains that are not allowed for the licence | true |
| blockedEmailDomains | No | Array | A list of email domains that are not allowed to be used to get a seat on the licence | [ ft.org ] |
| signupWelcomeText | No | String | B2B custom form heading | Welcome to your free trial |

### Prototypes

* [isAllowedEmailDomain](#isAllowedEmailDomain)
* [isBlockedEmailDomain](#isBlockedEmailDomain)
* [isMarketingCampaign](#isMarketingCampaign)

#### isAllowedEmailDomain

```javascript
const isAllowedEmailDomain = acquisitionContext.isAllowedEmailDomain(email);
```
- Checks whether the licence has an **allowed** email domain list and if the email domain is in that list.
- Returns true or false.

| Parameters  | Required | Type   | Description                            | Example  |
| ----------  | -------- | ------ | -------------------------------------- | -------- |
| email | Yes | String | User's email address | email@ft.com |

**Response**: `true`

#### isBlockedEmailDomain

```javascript
const isBlockedEmailDomain = acquisitionContext.isBlockedEmailDomain(email);
```
- Checks whether the licence has a **blocked** and **restricted** email domain list and if the email domain is in that list.
- Returns true or false.

| Parameters  | Required | Type   | Description                            | Example  |
| ----------  | -------- | ------ | -------------------------------------- | -------- |
| email | Yes | String | User's email address | email@ft.com |

**Response**: `true`

#### isMarketingCampaign

```javascript
const isMarketingCampaign = acquisitionContext.isMarketingCampaign();
```

- Returns true if acquisitionContext displayName is **Marketing Campaigns Account**.
```
	Parameters: none
	Response: boolean
```

### Membership AcquisitionContext Response

```javascript
{
	displayName: 'Display Name',
	restrictIpRanges: false,
	signupContext: {
		accessLicence: {
			id: 'tokenId',
		},
		restrictEmailDomains: true,
		allowedEmailDomains: ['ExamPle.com', 'Example_2.com'],
		restrictBlockedEmailDomains: false,
		blockedEmailDomains: ['BLOCKED.com'],
		signupWelcomeText: 'Welcome to your free trial'
	}
}
```
