# Offer Model

## Request

- When requesting `graphql.getOffer` a Offer instance is returned.

```javascript
try {
	const offer = await graphql.getOffer(offerId);
} catch (error) {
	throw error;
}
```

### Required Parameters

| Parameters  | Required | Type   | Description        | Example                              |
| ----------  | -------- | ------ | ------------------ | ------------------------------------ |
| offerId     | Yes      | String | Product Offer Id   | 6c7b7f36-0b91-b33b-2257-71d09919ddc4 |

**Response**: Returns an offer instance: [OfferClassResponse](../../src/models/offer.ts).

## Table of Contents

* [Initiate Offer Class](Initiate-Offer-Class)
* [Properties of the offer response](#Properties-of-the-offer-response)
* [Prototypes](#Prototypes)
* [Membership Offer Response](#Membership-Offer-Response)
* [Charges Formatted Response](#Charges-Formatted-Response)

### Initiate Offer Class

```javascript
 const offerInstance = new Offer(offer);
```

| Parameters  | Required | Type   | Description                                | Example |
| ----------  | -------- | ------ | ------------------------------------------ | --------|
| offer       | Yes      | Object | Membership graphql offerById data response | see [Membership Offer Response](#Membership-Offer-Response) |


### Properties of the offer response

| Properties  | Type   | Description           | Example                                   |
| ----------  | ------ | --------------------- | ----------------------------------------- |
| rawResponse | Object | Membership graphql offerById data response | see [Membership Offer Response](#Membership-Offer-Response)          |
| id          | String | ID of the offer       | 6c7b7f36-0b91-b33b-2257-71d09919ddc4      |
| type        | String | Product type          | RRP or Trial                              |
| productName | String | Product name          | Standard FT.com                           |
| productType | String | Product type          | Digital or Print                          |
| productCode | String | Product code          | P1                                        |
| pricing     | Array  | Product pricing array | see pricing in [Membership Offer Response](#Membership-Offer-Response) |

### Prototypes

* [isDigital](#isDigital)
* [isTrial](#isTrial)
* [isPrint](#isPrint)
* [isBundle](#isBundle)
* [isStandard](#isStandard)
* [isPremium](#isPremium)
* [getPrintProductCode](#getPrintProductCode)
* [getDigitalProductCode](#getDigitalProductCode)
* [getBillingCountries](#getBillingCountries)
* [getBillingCountriesForCurrency](#getBillingCountriesForCurrency)
* [getCountryPricing](#getCountryPricing)
* [getFulfilmentPricing](#getFulfilmentPricing)
* [getTermPricing](#getTermPricing)
* [getAvailableCharges](#getAvailableCharges)
* [getAllAvailableCharges](#getAllAvailableCharges)
* [getAvailableChargesForCountry](#getAvailableChargesForCountry)
* [getAvailableChargesForCountryAndFulfilmentOption](#getAvailableChargesForCountryAndFulfilmentOption)
* [getCurrency](#getCurrency)
* [getSubscriptionTerm](#getSubscriptionTerm)


#### isDigital

```javascript
const isDigital = offer.isDigital();
```

- Returns true if offer is a Digital product type otherwise it returns false.
```
	Parameters: none
	Response: boolean
```

#### isTrial

```javascript
const isTrial = offer.isTrial();
```

- Returns true if offer has the type Trial otherwise it returns false.
```
	Parameters: none
	Response: boolean
```

#### isPrint

```javascript
const isPrint = offer.isPrint();
```

- Returns true if offer is a Print product type otherwise it returns false.
```
	Parameters: none
	Response: boolean
```

#### isBundle

```javascript
const isBundle = offer.isBundle();
```
- Returns true if offer is a Bundle product type otherwise it returns false.
```
	Parameters: none
	Response: boolean
```

#### isStandard

```javascript
const isStandard = offer.isStandard();
```

- Returns true if offer is a standard product type otherwise it returns false.
```
	Parameters: none
	Response: boolean
```

#### isPremium

```javascript
const isPremium = offer.isPremium();
```

- Returns true if offer is a premium product type otherwise it returns false.
```
	Parameters: none
	Response: boolean
```

#### isEpaper

```javascript
const isEpaper = offer.isEpaper();
```

- Returns true if offer is an ePaper product type otherwise it returns false.
```
	Parameters: none
	Response: boolean
```

#### getPrintProductCode

```javascript
const printProductCode = offer.getPrintProductCode();
```

- Returns upper case print product code of `N5D`, `N6D`or `NWE` if the product is a print or bundle.
- It will throw an `EmptyResultError` if the product does not contain one of the above print product codes.
```
	Parameters: none
	Response: N5D / N6D / NWE
```

#### getDigitalProductCode

```javascript
const digitalProductCode = offer.getDigitalProductCode();
```

- Returns upper case digital product code of:
  - `P1` or `P2` if the product is a digital or bundle
  - `NS1` if the product is the Inside Politics (standard) niche email newsletter
  - `NP1` if the product is the Unhedged (premium) niche email newsletter
  - `PNWU1` if the product is the FT Newsletter trial (for Inside Politics and Unhedged email newsletters)
- It will throw an `EmptyResultError` if the product does not contain one of the above digital product codes.
```
	Parameters: none
	Response: P1 / P2 / NP1 / NS1 / PNWU1
```

#### getBillingCountries

```javascript
const billingCountries = offer.getBillingCountries();
```

- Returns all available billing countries for the offer.

```
	Parameters: none
	Response: [
		'GBR',
		'USA',
		'AUS',
		'FRA',
		...
	]
```

#### getBillingCountriesForCurrency

```javascript
const billingCountries = offer.getBillingCountriesForCurrency('GBP');
```

- Returns all available billing countries for the offer that support the given currency.

| Parameters  | Required | Type   | Description                          | Example |
| ----------  | -------- | ------ | ------------------------------------ | ------ |
| currencyCode | Yes     | String | Three letter ISO 4217 currency code  | GBP    |

**Response**:

```
[
	'GBR',
	'USA',
	'AUS',
	'FRA',
	...
]
```

#### getCountryPricing

```javascript
const countryPricing = offer.getCountryPricing(countryCode, pricing);
```

- Returns an array of all pricing information for the country specified.

| Parameters  | Required | Type   | Description                          | Example |
| ----------  | -------- | ------ | ------------------------------------ | ------- |
| countryCode | Yes      | String | Three letter ISO 3166-1 country code | GBR     |
| pricing     | Yes      | Array  | Prices		                           | see pricing in [Membership Offer Response](#Membership-Offer-Response) |

**Response**: see pricing in [Membership Offer Response](#Membership-Offer-Response). Only the pricing for the specified **country** will be returned.

#### getFulfilmentPricing

```javascript
const fulfilmentPricing = offer.getFulfilmentPricing(fulfilmentOption, pricing);
```

- Returns all pricing information for the fulfilmentOption specified.

| Parameters  | Required | Type   | Description                          | Example |
| ----------  | -------- | ------ | ------------------------------------ | ------- |
| fulfilmentOption | No       | String | Newspaper delivery type         | HD (Home Delivery) |
| pricing     | Yes      | Array  | Prices		                           | see pricing in [Membership Offer Response](#Membership-Offer-Response) |

Response: see pricing in [Membership Offer Response](#Membership-Offer-Response). Only the specified **fulfilment option** pricing will be returned.

#### getTermPricing

```javascript
const termPricing = offer.getTermPricing(term, pricing);
```

- Returns all pricing information for the term specified.

| Parameters       | Required | Type   | Description               | Example |
| ---------------- | -------- | ------ | ------------------------- | ------- |
| term             | Yes      | String | Payment/billing term - how often the user will make a payment | Annual  |
| pricing          | Yes      | Array  | Prices		                 | see pricing in [Membership Offer Response](#Membership-Offer-Response) |

**Response**: see pricing in [Membership Offer Response](#Membership-Offer-Response). Only the pricing for the specified **term** will be returned.

#### getAvailableCharges

```javascript
 const availableCharges = offer.getAvailableCharges(countryCode, fulfilmentOption);
```

- Returns an array of all the formatted charges based on country code and fulfilment options (optional).

| Parameters       | Required | Type   | Description                          | Example |
| ---------------- | -------- | ------ | ------------------------------------ | ------- |
| countryCode      | Yes      | String | Three letter ISO 3166-1 country code | GBR     |
| fulfilmentOption | No       | String | Newspaper delivery type              | HD (Home Delivery) |

**Response**: See [Charges Formatted Response](#Charges-Formatted-Response). Only the formatted charges for the countryCode and fulfilmentOption (if given) will be returned.

#### getAllAvailableCharges

- Returns an array of ALL charges formatted.

```javascript
const allAvailableCharges = offer.getAllAvailableCharges();
```
**Response**: See [Charges Formatted Response](#Charges-Formatted-Response)

#### getAvailableChargesForCountry

```javascript
const availableChargesForCountry = offer.getAvailableChargesForCountry(countryCode);
```

- Returns an array of charges formatted for the specified country.

| Parameters  | Required | Type   | Description                          | Example |
| ----------  | -------- | ------ | ------------------------------------ | ------- |
| countryCode | Yes      | String | Three letter ISO 3166-1 country code | GBR     |

**Response**: See [Charges Formatted Response](#Charges-Formatted-Response). Only the formatted charges for the countryCode will be returned.

#### getAvailableChargesForCountryAndFulfilmentOption

```javascript
const availableChargesForCountryAndFulfilmentOption = offer.getAvailableChargesForCountryAndFulfilmentOption(countryCode, fulfilmentOption);
```

- Returns an array of all the formatted charges based on country code and fulfilment options.

| Parameters       | Required | Type   | Description                          | Example |
| ---------------- | -------- | ------ | ------------------------------------ | ------- |
| countryCode      | Yes      | String | Three letter ISO 3166-1 country code | GBR     |
| fulfilmentOption | Yes      | String | Newspaper delivery type              | HD (Home Delivery) |

**Response**: See [Charges Formatted Response](#Charges-Formatted-Response). Only the formatted charges for the countryCode and fulfilmentOption will be returned.

#### getCurrency

```javascript
const currency = offer.getCurrency(countryCode);
```

- Returns currency for the country code specified.

| Parameters  | Required | Type   | Description                          | Example |
| ----------  | -------- | ------ | ------------------------------------ | ------- |
| countryCode | Yes      | String | Three letter ISO 3166-1 country code | GBR     |

**Response**: String. Returns currency ISO 4217 code of country specified (e.g 'GBP').

#### getSubscriptionTerm

```javascript
const subscriptionTerm = offer.getSubscriptionTerm(price);
```

- Returns `displayName` and `iso8601Duration` code for given price.

| Parameters  | Required | Type   | Description            | Example |
| ----------  | -------- | ------ | ---------------------- | ------- |
| price       | Yes      | Array  | Single selected price  | see pricing in see [Membership Offer Response](#Membership-Offer-Response) |

**Response**:

```javascript
	// RRP

	{
		displayName: 'Monthly',
		iso8601Duration: 'P1M'
	}

	// Trial

	{
		displayName: 'Trial',
		iso8601Duration: 'P4W'
	}

```

**Note**: The iso8601Duration code for a trial is set to `paymentDue.after` value.

### Membership Offer Response

```javascript
rawResponse: {
	id: '6c7b7f36-0b91-b33b-2257-71d09919ddc4',
	name: 'FT.com - Standard RRP',
	pricing: [
		{
			charges: [
				{
					amount: {
						currency: 'AUD',
						nativeSymbol: '$',
						symbol: 'AUS',
						value: '311.48'
					},
					basis: 'RECURRING',
					billingFrequency: {
						displayName: 'Annual',
						iso8601Duration: 'P1Y',
						unit: 'month',
						value: '12'
					},
					paymentDue: null,
					subscriptionTerm: {
						displayName: 'Annual',
						iso8601Duration: 'P1Y'
					},
					type: 'Standard Digital'
				}
			],
			country: 'CCK',
			currency: 'AUD',
			option: null,
			total: {
				currency: 'AUD',
				nativeSymbol: '$',
				symbol: '$',
				value: '311.48'
			},
			trialTotal: null
		},
		...
	],
	product: {
		code: 'P1',
		name: 'Standard FT.com',
		type: 'Digital'
	},
	type: 'RRP'
}
```

### Charges Formatted Response

```javascript
	Response:
		[
			{
				subscriptionName: 'Monthly',
				subscriptionCode: 'P1M',
				currency: 'GBP',
				symbol: '£',
				option: {
					code: 'HD',
					displayName: 'Home Delivery'
					},
				value: '103.00',
				trialValue: null
			},
			{
				subscriptionName: 'Annual',
				subscriptionCode: 'P1Y',
				currency: 'GBP',
				symbol: '£',
				option: {
					code: 'HD',
					displayName: 'Home Delivery'
					},
				value: '690.00',
				trialValue: null
			},
			...
		]
```
