Skip to content

Latest commit

 

History

History
484 lines (353 loc) · 16.8 KB

customer_helper.md

File metadata and controls

484 lines (353 loc) · 16.8 KB

Стандартные операции над потребителем

Для наиболее часто используемых операций над потребителем реализован хелпер CustomerHelper.

Хелпер является обёрткой над универсальными методами отправки произвольного запроса.

Примеры использования CustomerHelper

Авторизация потребителя:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('[email protected]');

/* Формирование данных о потребителе */

try {
    $response = $mindbox->customer()
        ->authorize(
            $customer, // CustomerRequestDTO
            'Website.AuthorizeCustomer', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
        
        $requestBody = $response->getRequest()->getBody();
        $responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();
}

Поиск потребителя по номеру телефона:

/* Иинициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setMobilePhone(79999999999);

try {
    $response = $mindbox->customer()
        ->checkByPhone(
            $customer, // CustomerRequestDTO
            'Website.CheckCustomerByMobilePhone', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
        
        $requestBody = $response->getRequest()->getBody();
        $responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();
}

var_dump($response->getRequest());
var_dump($response->getBody());

Поиск потребителя по email адресу:

/* Инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('[email protected]');

try {
    $response = $mindbox->customer()
        ->checkByMail(
            $customer, // CustomerRequestDTO
            'Website.CheckCustomerByEmail', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
    
    $requestBody = $response->getRequest()->getBody();
    $responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();
}

Регистрация потребителя:

/* Инициализация SDK */
$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('[email protected]');

/* Отправка запроса в Mindbox */
try {
    $response = $mindbox->customer()
        ->register(
            $customer, // CustomerRequestDTO
            'Website.RegisterCustomer', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
        
    $requestBody = $response->getRequest()->getBody();
    $responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();
}

Редактирование данных потребителя:

/* Инициализация SDK */
$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('[email protected]');
$customer->setId('mindboxId', 12345);

/* Отправка запроса в Mindbox */
try {
    $response = $mindbox->customer()
        ->edit(
            $customer, // CustomerRequestDTO
            'Website.EditCustomer', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
        
    $requestBody = $response->getRequest()->getBody();
    $responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();
}

Дозаполнение профиля потребителя:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('[email protected]');
$customer->setId('mindboxId', 12345);

/* Формирование данных о потребителе */

try {
    $response = $mindbox->customer()
        ->fill(
            $customer, // CustomerRequestDTO
            'Website.FillCustomerProfile', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Поиск потребителя по номеру карты:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();

$discountCard = new \Mindbox\DTO\V3\Requests\DiscountCardIdentityRequestDTO();
$discountCard->setId('number', 1111111111111);

$customer->setDiscountCard($discountCard);

try {
    $response = $mindbox->customer()
        ->getDataByDiscountCard(
            $customer, // CustomerRequestDTO
            'Website.GetCustomerDataByDiscountCard', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Объединение потребителей:

/* Подключение автозагрузчика и инициализация SDK */

$mergeCustomers = new Mindbox\DTO\V3\Requests\MergeCustomersRequestDTO();

$customerToMerge = new \Mindbox\DTO\V3\Requests\CustomerIdentityRequestDTO();
$customerToMerge->setId('mindboxId', 1029);

$customersToMerge = new \Mindbox\DTO\V3\Requests\CustomerIdentityRequestCollection([$customerToMerge]);

$mergeCustomers->setCustomersToMerge($customersToMerge);

$resultingCustomer = new \Mindbox\DTO\V3\Requests\CustomerIdentityRequestDTO();
$resultingCustomer->setId('mindboxId', 328);

$mergeCustomers->setResultingCustomer($resultingCustomer);

try {
    $response = $mindbox->customer()
        ->merge(
            $mergeCustomers, // MergeCustomersRequestDTO
            'Website.MergeCustomers', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

Проверка на наличие потребителя в программе лояльности:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setId('mindboxId', 328);

try {
    $response = $mindbox->customer()
        ->checkActive(
            $customer, // CustomerRequestDTO
            'Website.CheckCustomerIsInLoyalityProgram', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Получение истории изменений баланса потребителя:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setId('mindboxId', 1812);

$page = new \Mindbox\DTO\V3\Requests\PageRequestDTO();
$page->setItemsPerPage(10);
$page->setPageNumber(1);

try {
    $response = $mindbox->customer()
        ->getBonusPointsHistory(
            $customer, // CustomerRequestDTO
            $page, // PageRequestDTO
            'Website.GetCustomerBonusPointsHistory', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Отправка кода подтверждения:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setMobilePhone(77777777777);

try {
    $response = $mindbox->customer()
        ->sendAuthorizationCode(
            $customer, // CustomerRequestDTO
            'Website.SendMobilePhoneAuthorizationCode', // название операции
            false, // добавлять ли DeviceUUID в запрос, необязательный параметр
            true // синхронный запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Проверка кода подтверждения:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setMobilePhone(77777777777);

try {
    $response = $mindbox->customer()
        ->checkAuthorizationCode(
            $customer, // CustomerRequestDTO
            '1234', // код подтверждения
            'Website.CheckMobilePhoneAuthorizationCode', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Повторная отправка кода подтверждения:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setId('mindboxId', 1812);

try {
    $response = $mindbox->customer()
        ->resendConfirmationCode(
            $customer, // CustomerRequestDTO
            'Website.ResendMobilePhoneConfirmationCode', // название операции
            false, // добавлять ли DeviceUUID в запрос, необязательный параметр
            true // синхронный запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Подтверждение мобильного телефона:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setId('mindboxId', 1812);

$smsConfirmation = new \Mindbox\DTO\V3\Requests\SmsConfirmationRequestDTO();
$smsConfirmation->setCode(1234);

try {
    $response = $mindbox->customer()
        ->confirmMobile(
            $customer, // CustomerRequestDTO
            $smsConfirmation, // SmsConfirmationRequestDTO
            'Website.ConfirmMobilePhone', // название операции
            false, // добавлять ли DeviceUUID в запрос, необязательный параметр
            true // синхронный запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Подписка потребителя на рассылки:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('[email protected]');

$subscription = new \Mindbox\DTO\V3\Requests\SubscriptionRequestDTO();
$subscription->setPointOfContact('email');

$subscriptionCollection = new \Mindbox\DTO\V3\Requests\SubscriptionRequestCollection([$subscription]);

$customer->setSubscriptions($subscriptionCollection);

try {
    $response = $mindbox->customer()
        ->subscribe(
            $customer, // CustomerRequestDTO
            'Website.SubscribeCustomer', // название операции
            false, // добавлять ли DeviceUUID в запрос, необязательный параметр
            true // синхронный запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Подтверждение мобильного телефона на стороне клиента:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setMobilePhone(77777777777);
$customer->setId('mindboxId', 1812);

try {
    $response = $mindbox->customer()
        ->autoConfirmMobile(
            $customer, // CustomerRequestDTO
            'Website.AutoConfirmMobilePhone', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());

Получение баланса потребителя:

/* Подключение автозагрузчика и инициализация SDK */

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setId('mindboxId', 1812);

try {
    $response = $mindbox->customer()
        ->getBalance(
            $customer, // CustomerRequestDTO
            'Website.GetCustomerBalance', // название операции
            false // добавлять ли DeviceUUID в запрос, необязательный параметр
        )->sendRequest();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();

    return;
}

var_dump($response->getRequest());
var_dump($response->getBody());