# Print Info Service

If you only require specific functionality from the print info service, you can import the `PrintInfo` module separately to the main SDK.

For example:

```javascript
const { PrintInfo } = require('n-membership-sdk');
const printInfoSdk = new PrintInfo(config);
```

## Table of Contents

* [Config](#config)
	* [How to obtain a key](#how-to-obtain-a-key)
* [Methods](#methods)
	* [getFirstDeliveryDate](#getFirstDeliveryDate)
	* [getFirstSuspensionDate](#getFirstSuspensionDate)
	* [getVoucherDeliverySchedule](#getVoucherDeliverySchedule)
* [Membership Documentation](#membership-documentation)

## Config

* See common configuration options in the [README file](./README.doc)
* `printInfoApiKey`

```javascript
const config = new ProductionConfiguration({
	printInfoApiKey: 'secret',
});
```

### How to obtain a key

Do one of the following:

1. Check in Doppler for your app to see if the API key you need already exists.
2. Contact #membership-support slack channel for a key for the service i.e. newspaper-info-svc.

## Methods

### getFirstDeliveryDate

```javascript
const firstAvailableDeliveryDate = printInfoSdk.getFirstDeliveryDate(printProductCode, countryCode, postcode, option, startDate);
```

| Parameters  | Required | Type   | Example | Description   |
| ----------- | -------- | -------| --------| ------------- |
| printProductCode | yes | String | NWE     | **Print Product Types**: Weekend (NWE), 6 Days a week (N6D) or 5 days a week (N5D). The underlying API does not accept bundle offer product codes |
| countryCode | yes      | string | GBR     | Three letter ISO 3166-1 country code  |
| postcode    | yes      | String | SE19HL  | User's delivery postcode |
| option      | yes      | String | HD  | **Delivery type**: Home Delivery (HD), Paper Voucher (PV), Digital Voucher (EV) |
| startDate   | no       | String | '2018-07-12'  | User's chosen date for delivery. Defaults to the first delivery date possible. Format yyyy-MM-dd |

**Response**:
```javascript
{
	countryCode: "GBR",
	firstDeliveryDate: "2018-07-21",
	postcode: "SE19HL",
	productCode: "NWE"
}
```

* **firstDeliveryDate**: The closest date the newspaper can be delivered to the user's chosen delivery date (start date).

* **Note**: In order to get the print product code from a bundle product, you can use the [offer.getPrintProductCode](../models/OFFER.md#getPrintProductCode) function.

### getFirstSuspensionDate

```javascript
const firstAvailableSuspensionDate = printInfoSdk.getFirstSuspensionDate(countryCode, fromDate);
```

| Parameters  | Required | Type   | Example | Description   |
| ----------- | -------- | -------| --------| ------------- |
| countryCode | yes      | string | GBR     | Three letter ISO 3166-1 country code  |
| fromDate    | no       | String | '2018-07-12'  | User's chosen date to start their suspension. Format yyyy-MM-dd. |

**Response**:
```javascript
{
	firstSuspensionDate: '2019-09-28'
}
```

### getVoucherDeliverySchedule

```javascript
const voucherDeliverySchedule = printInfoSdk.getVoucherDeliverySchedule(term, startDate);
```

| Parameters  | Required | Type   | Example | Description   |
| ----------- | -------- | -------| --------| ------------- |
| term        | yes      | string | P1Y     | Payment/billing term - how often the user will make a payment  |
| startDate   | no      | String | 2018-07-12 | The date you want to see all the delivery schedules from. Format yyyy-MM-dd. Defaults to today's date. |


**Response for delivery voucher schedule**:
* [Model](../../src/models/delivery-voucher-dates.ts)
* [Documentation](../models/DELIVERY-VOUCHER-DATES.md)

### getLastDeliveryDateGenerated

```javascript
const LastDeliveryDateGenerated = printInfoSdk.getLastDeliveryDateGenerated(date, region);
```

| Parameters  | Required | Type   | Example | Description   |
| ----------- | -------- | -------| --------| ------------- |
| date | yes      | String | '2018-07-12' | Given this date, when is the Last Delivery Date generated. Format yyyy-MM-dd.  |
| region    | yes      | String | 'UK' | One of `UK`, `US`, `CEMEA` (Central Europe Middle East Africa) and `APAC` (Asia Pacific) |

**Response**:
```javascript
{
	region: "UK",
	lastDeliveryDate: "2020-12-24"
}
```


### getLastDeliveryDateGeneratedByCountry

```javascript
const LastDeliveryDateGeneratedByCountry = printInfoSdk.getLastDeliveryDateGeneratedByCountry(date, countryCode);
```

| Parameters  | Required | Type   | Example | Description   |
| ----------- | -------- | -------| --------| ------------- |
| date | yes      | String | '2018-07-12' | Given this date, when is the Last Delivery Date generated. Format yyyy-MM-dd.  |
| countryCode    | yes      | String | 'GBR' | Three letter ISO 3166-1 country code  |

**Response**:
```javascript
{
	region: "UK",
	lastDeliveryDate: "2020-12-24"
}
```


## Membership Documentation

| API Documentation | Confluence  | Description | Owner |
| -------------- | -------- | -------- | -------- |
| [Newspaper Info API](https://newspaper-info-svc-eu-prod.memb.ft.com/swagger-ui.html) |  [Newspaper Info Documentation](https://confluence.ft.com/display/MEMB/Newspaper+Information+Service) | Documentation for the newspaper info service | FT Core - Membership |
