# Шаблоны подписок

### Создание/редактирование шаблона подписок

/<span style="color: #505050;">api/lite/product/subscription/parse</span>

Создаёт структуру шаблона подписок по заданному шаблону. Все заданные товары должны существовать в кактусе до загрузки шаблона.

Если тип оплаты *recurrent*:

- Стоимость товара-подписки становится равной сумме первых отправлений
- Стоимость остальных отправлений становится 0

Если тип оплаты *all\_in\_moment*:

- Стоимость товара-подписки становится равен сумме всех отправлений

**Передаваемые параметры:**

<table border="1" id="bkmrk-%D0%98%D0%BC%D1%8F-%D0%A2%D0%B8%D0%BF-%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5-fil" style="border-collapse: collapse; width: 100%; height: 145px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 20.7251%; height: 29px;">**Имя**</td><td class="align-center" style="width: 17.3877%; height: 29px;">**Тип**</td><td class="align-center" style="width: 61.8871%; height: 29px;">**Описание**</td></tr><tr style="height: 29px;"><td class="align-center" style="width: 20.7251%; height: 29px;">file</td><td class="align-center" style="width: 17.3877%; height: 29px;">MultipartFile</td><td class="align-left" style="width: 61.8871%; height: 29px;">Файл (.XLS) для парсинга. [Пример файла](https://docs.google.com/spreadsheets/d/1vwH5icSRvmbnXtXTFcMSS00JNMtRzF3o8Ta_sLlUczk/edit?usp=sharing) . Возможные значения в payment\_method: RECURRENT и ALL\_IN\_MOMENT</td></tr><tr style="height: 29px;"><td class="align-center" style="width: 20.7251%; height: 29px;">productId</td><td class="align-center" style="width: 17.3877%; height: 29px;">String</td><td class="align-left" style="width: 61.8871%; height: 29px;">productId товара-подписки</td></tr><tr style="height: 29px;"><td class="align-center" style="width: 20.7251%; height: 29px;">variantId</td><td class="align-center" style="width: 17.3877%; height: 29px;">String</td><td class="align-left" style="width: 61.8871%; height: 29px;">variantId товара-подписки</td></tr><tr style="height: 29px;"><td class="align-center" style="width: 20.7251%; height: 29px;">startDate (optional)</td><td class="align-center" style="width: 17.3877%; height: 29px;">String</td><td class="align-left" style="width: 61.8871%; height: 29px;">Дата с которой начинается первое отправление. Если не задано, берётся текущая</td></tr></tbody></table>

#### **При удачном парсинге возвращает структуру шаблона:** 

```JSON
{
    "success": true,
    "productId": "1002",
    "variantId": "1002",
    "type": "SUBSCRIPTION",
    "onlinePaymentType": "recurrent",
    "useShipmentDelayInterval": true,
    "items": [
        {
            "productId": "1002",
            "variantId": "1006",
            "count": 1,
            "subscriptionShipmentNum": 1,
            "shipmentDelayIntervalDays": 30,
            "subscriptionStartDate": "2020-09-10",
            "itemPrice": 120.0
        },
        {
            "productId": "1002",
            "variantId": "1007",
            "count": 1,
            "subscriptionShipmentNum": 1,
            "shipmentDelayIntervalDays": 30,
            "subscriptionStartDate": "2020-09-10",
            "itemPrice": 120.0
        },
        {
            "productId": "1002",
            "variantId": "1008",
            "count": 1,
            "subscriptionShipmentNum": 2,
            "shipmentDelayIntervalDays": 20,
            "subscriptionStartDate": "2020-09-30",
            "itemPrice": 150.0
        },
        {
            "productId": "1002",
            "variantId": "1009",
            "count": 1,
            "subscriptionShipmentNum": 2,
            "shipmentDelayIntervalDays": 20,
            "subscriptionStartDate": "2020-09-30",
            "itemPrice": 150.0
        },
        {
            "productId": "1002",
            "variantId": "1010",
            "count": 1,
            "subscriptionShipmentNum": 3,
            "shipmentDelayIntervalDays": 20,
            "subscriptionStartDate": "2020-10-20",
            "itemPrice": 250.0
        }
    ]
}
```

#### **Пример ошибки:** 

```JSON
{
    "success": false,
    "errors": [
        {
            "code": 0,
            "message": "Update SubscriptionTemplate not implemented yet!\n"
        }
    ]
}
```

###  

### Получение информации о шаблоне

/<span style="color: #505050;">api/lite/product/subscription</span>

**Передаваемые параметры:**

<table border="1" id="bkmrk-%D0%98%D0%BC%D1%8F-%D0%A2%D0%B8%D0%BF-%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5-id-" style="border-collapse: collapse; width: 100%;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 20.7251%; height: 29px;">**Имя**</td><td class="align-center" style="width: 17.3877%; height: 29px;">**Тип**</td><td class="align-center" style="width: 61.8871%; height: 29px;">**Описание**</td></tr><tr><td class="align-center" style="width: 20.7251%;">id</td><td class="align-center" style="width: 17.3877%;">String</td><td class="align-left" style="width: 61.8871%;">productId товара-подписки</td></tr></tbody></table>

#### **Пример успешного ответа:**

```JSON
{
    "success": true,
    "productId": "1002",
    "variantId": "1002",
    "type": "SUBSCRIPTION",
    "onlinePaymentType": "recurrent",
    "useShipmentDelayInterval": true,
    "items": [
        {
            "productId": "1002",
            "variantId": "1006",
            "count": 1,
            "subscriptionShipmentNum": 1,
            "shipmentDelayIntervalDays": 30,
            "subscriptionStartDate": "2020-09-10",
            "itemPrice": 120.0
        },
        {
            "productId": "1002",
            "variantId": "1007",
            "count": 1,
            "subscriptionShipmentNum": 1,
            "shipmentDelayIntervalDays": 30,
            "subscriptionStartDate": "2020-09-10",
            "itemPrice": 120.0
        },
        {
            "productId": "1002",
            "variantId": "1008",
            "count": 1,
            "subscriptionShipmentNum": 2,
            "shipmentDelayIntervalDays": 20,
            "subscriptionStartDate": "2020-09-30",
            "itemPrice": 150.0
        },
        {
            "productId": "1002",
            "variantId": "1009",
            "count": 1,
            "subscriptionShipmentNum": 2,
            "shipmentDelayIntervalDays": 20,
            "subscriptionStartDate": "2020-09-30",
            "itemPrice": 150.0
        },
        {
            "productId": "1002",
            "variantId": "1010",
            "count": 1,
            "subscriptionShipmentNum": 3,
            "shipmentDelayIntervalDays": 20,
            "subscriptionStartDate": "2020-10-20",
            "itemPrice": 250.0
        }
    ]
}
```

<div id="bkmrk-"><div></div></div>