complete simple register in LP, without custom fields and activation
This commit is contained in:
parent
17ad58833a
commit
e2ba47ed13
20 changed files with 258 additions and 77 deletions
|
@ -3009,7 +3009,11 @@ class ApiClient
|
|||
return $this->client->makeRequest(
|
||||
"/loyalty/account/create",
|
||||
Client::METHOD_POST,
|
||||
$request
|
||||
[
|
||||
'loyaltyAccount'=>json_encode($request['loyaltyAccount']),
|
||||
'site'=>$request['site'],
|
||||
]
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ $MESS["AUTH_SECURE_NOTE"] = "Перед отправкой формы парол
|
|||
$MESS["AUTH_NONSECURE_NOTE"] = "Пароль будет отправлен в открытом виде. Включите JavaScript в браузере, чтобы зашифровать пароль перед отправкой.";
|
||||
$MESS["main_register_sms"] = "Код подтверждения из СМС:";
|
||||
$MESS["main_register_sms_send"] = "Отправить";
|
||||
$MESS["UF_REG_IN_PL_INTARO"] = "Зарегистрироваться в программе лояльности:";
|
||||
$MESS["UF_REG_IN_PL_INTARO"] = "Зарегистрироваться в программе лояльности";
|
||||
$MESS["UF_AGREE_PL_INTARO"] = "программы лояльности:";
|
||||
$MESS["I_AM_AGREE"] = "Я согласен с условиями";
|
||||
$MESS["UF_PD_PROC_PL_INTARO"] = "обработки персональных данных:";
|
||||
|
@ -69,3 +69,8 @@ $MESS["SEND"] = "Отправить";
|
|||
$MESS["VERIFICATION_CODE"] = "Код подтверждения";
|
||||
$MESS["SEND_VERIFICATION_CODE"] = "Отправьте код подтверждения";
|
||||
$MESS["REG_LP_MESSAGE"] = "Для завершения регистрации в программе лояльности введите номер телефона и номер карты программы лояльности";
|
||||
$MESS["YES"] = "Да";
|
||||
$MESS["BONUS_CARD_NUMBER"] = "Номер карты лояльности (если есть):";
|
||||
$MESS["SUCCESS_PL_REG"] = "Вы успешно зарегистрировались в программе лояльности.";
|
||||
$MESS["LP_FIELDS_NOT_EXIST"] = "Ошибка установки модуля ПЛ. Отсутствуют UF поля для USER";
|
||||
$MESS["REG_LP_ERROR"] = "Ошибка регистрации в Программе лояльности";
|
||||
|
|
|
@ -7,6 +7,26 @@ use Bitrix\Main\SystemException;
|
|||
use Intaro\RetailCrm\Repository\AgreementRepository;
|
||||
Loader::includeModule('intaro.retailcrm');
|
||||
|
||||
global $USER;
|
||||
if($USER->IsAuthorized()){
|
||||
$rsUser = CUser::GetByID($USER->GetID());
|
||||
$arResult['USER_FIELDS'] = $rsUser->Fetch();
|
||||
|
||||
if (isset(
|
||||
$arResult['USER_FIELDS']['UF_EXT_REG_PL_INTARO'],
|
||||
$arResult['USER_FIELDS']['UF_AGREE_PL_INTARO'],
|
||||
$arResult['USER_FIELDS']['UF_PD_PROC_PL_INTARO'],
|
||||
$arResult['USER_FIELDS']['UF_EXT_REG_PL_INTARO'],
|
||||
$arResult['USER_FIELDS']['UF_LP_ID_INTARO']
|
||||
)) {
|
||||
$arResult['LP_ERRORS'] = true;
|
||||
|
||||
AddMessage2Log(GetMessage('LP_FIELDS_NOT_EXIST'));
|
||||
}else{
|
||||
$arResult['LP_ERRORS'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$agreementPersonalData = AgreementRepository::getFirstByWhere(
|
||||
['AGREEMENT_TEXT'],
|
||||
|
@ -25,5 +45,3 @@ try {
|
|||
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {
|
||||
AddMessage2Log($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -57,4 +57,14 @@ function sendVerificationCode() {
|
|||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function lpFieldToggle(){
|
||||
if ($('#checkbox_UF_REG_IN_PL_INTARO').is(':checked')){
|
||||
$('.lp_toggled_block').css('display', 'table-row');
|
||||
$('.lp_agree_checkbox').prop('checked', true);
|
||||
} else {
|
||||
$('.lp_toggled_block').css('display', 'none');
|
||||
$('.lp_agree_checkbox').prop('checked', true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,35 +82,35 @@ if($arResult["SHOW_SMS_FIELD"] == true)
|
|||
|
||||
<?if($USER->IsAuthorized()):?>
|
||||
|
||||
<p><?echo GetMessage("MAIN_REGISTER_AUTH")?></p>
|
||||
<?php
|
||||
<p><?php echo GetMessage("MAIN_REGISTER_AUTH") ?></p>
|
||||
<?php
|
||||
$this->addExternalJs(SITE_TEMPLATE_PATH . '/script.js');
|
||||
|
||||
$rsUser = CUser::GetByID($USER->GetID());
|
||||
$arUser = $rsUser->Fetch();
|
||||
|
||||
if (
|
||||
isset($arUser['UF_REG_IN_PL_INTARO'], $arUser['UF_AGREE_PL_INTARO'], $arUser['UF_PD_PROC_PL_INTARO'])
|
||||
&& (int)$arUser['UF_REG_IN_PL_INTARO'] === 1
|
||||
&& (int)$arUser['UF_AGREE_PL_INTARO'] === 1
|
||||
&& (int)$arUser['UF_PD_PROC_PL_INTARO'] === 1
|
||||
) { ?>
|
||||
?>
|
||||
<?php if ($arResult['LP_ERRORS']): ?>
|
||||
<?=GetMessage('REG_LP_ERROR')?>
|
||||
<?php else: ?>
|
||||
<!--елси регистрация в программе лояльности прошла успешно-->
|
||||
<?php if (isset($arResult['USER_FIELDS']['UF_EXT_REG_PL_INTARO']) && $arResult['USER_FIELDS']['UF_EXT_REG_PL_INTARO'] === 1): ?>
|
||||
<b><?=GetMessage('SUCCESS_PL_REG')?></b>
|
||||
<?php elseif ((int)$arResult['USER_FIELDS']['UF_EXT_REG_PL_INTARO'] === 0): ?>
|
||||
<div id="regbody">
|
||||
<b><?= GetMessage('REG_LP_MESSAGE')?></b><br>
|
||||
<b><?=GetMessage('REG_LP_MESSAGE')?></b><br>
|
||||
<input type="tel" id="loyaltyRegPhone" placeholder="+7 (900) 000-00-00">
|
||||
<br>
|
||||
<input type="text" id="loyaltyRegCard" placeholder="<?= GetMessage('LP_CARD_NUMBER')?>">
|
||||
<input type="button" onclick="addTelNumber(<?=$USER->GetID()?>)" value="<?= GetMessage('SEND')?>"/>
|
||||
<input type="text" id="loyaltyRegCard" placeholder="<?=GetMessage('LP_CARD_NUMBER')?>">
|
||||
<input type="button" onclick="addTelNumber(<?=$USER->GetID()?>)" value="<?=GetMessage('SEND')?>"/>
|
||||
<br>
|
||||
<div id="verificationCodeBlock" style="display: none;">
|
||||
<b><?= GetMessage('SEND_VERIFICATION_CODE')?></b><br>
|
||||
<input type="text" id="verificationCode" placeholder="<?= GetMessage('VERIFICATION_CODE')?>">
|
||||
<input type="button" onclick="sendVerificationCode()" value="<?= GetMessage('SEND')?>"/>
|
||||
<b><?=GetMessage('SEND_VERIFICATION_CODE')?></b><br>
|
||||
<input type="text" id="verificationCode" placeholder="<?=GetMessage('VERIFICATION_CODE')?>">
|
||||
<input type="button" onclick="sendVerificationCode()" value="<?=GetMessage('SEND')?>"/>
|
||||
</div>
|
||||
<div id="msg"></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?else:?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else:?>
|
||||
<?
|
||||
if (count($arResult["ERRORS"]) > 0):
|
||||
foreach ($arResult["ERRORS"] as $key => $error)
|
||||
|
@ -307,30 +307,52 @@ document.getElementById('bx_auth_secure').style.display = 'inline-block';
|
|||
<?endforeach;?>
|
||||
<?endif;?>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="fields boolean" id="main_UF_REG_IN_PL_INTARO">
|
||||
<div class="fields boolean"><input type="hidden" value="0" name="UF_REG_IN_PL_INTARO">
|
||||
<label><input type="checkbox" value="1" name="UF_REG_IN_PL_INTARO"> да</label></div>
|
||||
<td></td>
|
||||
<td><div class="fields boolean" id="main_UF_REG_IN_PL_INTARO">
|
||||
<div class="fields boolean">
|
||||
<input type="hidden" value="0" name="UF_REG_IN_PL_INTARO">
|
||||
<label>
|
||||
<input type="checkbox" value="1" name="UF_REG_IN_PL_INTARO" onchange="lpFieldToggle()" id="checkbox_UF_REG_IN_PL_INTARO"> <?= GetMessage("UF_REG_IN_PL_INTARO")?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><?= GetMessage("UF_REG_IN_PL_INTARO")?></td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="lp_toggled_block" style="display: none">
|
||||
<td><?= GetMessage("BONUS_CARD_NUMBER")?></td>
|
||||
<td><input size="30" type="text" name="UF_CARD_NUM_INTARO" value=""></td>
|
||||
</tr>
|
||||
<tr class="lp_toggled_block" style="display: none">
|
||||
<td>
|
||||
<?= GetMessage("REGISTER_FIELD_PERSONAL_PHONE")?>
|
||||
</td>
|
||||
<td>
|
||||
<input size="30" type="text" name="REGISTER[PERSONAL_PHONE]" value>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="lp_toggled_block" style="display: none">
|
||||
<td>
|
||||
<div class="fields boolean" id="main_UF_AGREE_PL_INTARO">
|
||||
<div class="fields boolean"><input type="hidden" value="0" name="UF_AGREE_PL_INTARO">
|
||||
<label><input type="checkbox" value="1" name="UF_AGREE_PL_INTARO"> да</label></div>
|
||||
<div class="fields boolean">
|
||||
<input type="hidden" value="0" name="UF_AGREE_PL_INTARO">
|
||||
<label>
|
||||
<input class="lp_agree_checkbox" type="checkbox" value="1" name="UF_AGREE_PL_INTARO" > <?= GetMessage("YES")?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<?= GetMessage("I_AM_AGREE")?> <a class="lp_agreement_link" href="javascript:void(0)" ><?= GetMessage("UF_AGREE_PL_INTARO")?></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="lp_toggled_block" style="display: none">
|
||||
<td>
|
||||
<div class="fields boolean" id="main_UF_PD_PROC_PL_INTARO">
|
||||
<div class="fields boolean"><input type="hidden" value="0" name="UF_PD_PROC_PL_INTARO">
|
||||
<label><input type="checkbox" value="1" name="UF_PD_PROC_PL_INTARO"> да</label></div>
|
||||
<label>
|
||||
<input class="lp_agree_checkbox" type="checkbox" value="1" name="UF_PD_PROC_PL_INTARO"> <?= GetMessage("YES")?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
|
|
@ -1526,6 +1526,10 @@ class intaro_retailcrm extends CModule
|
|||
'name' => "UF_CARD_NUM_INTARO",
|
||||
'title' => GetMessage('UF_CARD_NUMBER_INTARO_TITLE'),
|
||||
],
|
||||
[
|
||||
'name' => "UF_LP_ID_INTARO",
|
||||
'title' => GetMessage('UF_LP_ID_INTARO_TITLE'),
|
||||
],
|
||||
],
|
||||
'string'
|
||||
);
|
||||
|
|
|
@ -23,8 +23,9 @@ $MESS ['AGREEMENT_PERSONAL_DATA_TITLE'] = 'Согласие на обрабо
|
|||
$MESS ['UF_REG_IN_PL_INTARO_TITLE'] = 'Зарегистрироваться в программе лояльности';
|
||||
$MESS ['UF_AGREE_PL_INTARO_TITLE'] = 'Я согласен с условиями программы лояльности';
|
||||
$MESS ['UF_PD_PROC_PL_INTARO_TITLE'] = 'Согласие на обработку персональных данных';
|
||||
$MESS ['UF_EXT_REG_PL_INTARO_TITLE'] = 'Поле, с меткой регистрации пользователя в ПЛ';
|
||||
$MESS ['UF_EXT_REG_PL_INTARO_TITLE'] = 'Активность в программе лояльности';
|
||||
$MESS ['UF_CARD_NUMBER_INTARO_TITLE'] = 'Номер карты программы лояльности';
|
||||
$MESS ['UF_LP_ID_INTARO_TITLE'] = 'Номер аккаунта в программе лояльности';
|
||||
/*
|
||||
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа retailCRM свойствам заказа 1С-Битрикс';
|
||||
$MESS ['FIO'] = 'Ф.И.О.';
|
||||
|
|
|
@ -24,8 +24,11 @@ use Bitrix\Sale\Order;
|
|||
use Bitrix\Sale\PaySystem\Manager;
|
||||
use Exception;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Model\Api\User;
|
||||
use Intaro\RetailCrm\Repository\PaySystemActionRepository;
|
||||
use Intaro\RetailCrm\Repository\UserRepository;
|
||||
use Intaro\RetailCrm\Service\LoyaltyService;
|
||||
use Intaro\RetailCrm\Service\UserAccountService;
|
||||
use RetailCrm\ApiClient;
|
||||
use RetailcrmConfigProvider;
|
||||
use RetailCrmUser;
|
||||
|
@ -150,7 +153,7 @@ class EventsHandlers
|
|||
|
||||
if (isset($_POST['bonus-input'], $_POST['available-bonuses'])
|
||||
&& $isNew
|
||||
&& (int) $_POST['available-bonuses'] >= (int) $_POST['bonus-input']
|
||||
&& (int)$_POST['available-bonuses'] >= (int)$_POST['bonus-input']
|
||||
) {
|
||||
$orderId = $order->getId();
|
||||
$bonusCount = $_POST['bonus-input'];
|
||||
|
@ -206,16 +209,60 @@ class EventsHandlers
|
|||
}
|
||||
|
||||
/**
|
||||
* Регистрирует пользователя в CRM системе после регистрации на сайте
|
||||
*
|
||||
* @param $arFields
|
||||
* @return mixed
|
||||
*/
|
||||
public function OnAfterUserRegisterHandler($arFields)
|
||||
{
|
||||
if (isset($arFields['USER_ID']) && $arFields['USER_ID'] > 0) {
|
||||
$arFields['ID'] = $arFields['USER_ID'];
|
||||
$user = UserRepository::getById($arFields['USER_ID']);
|
||||
|
||||
if (isset($_POST['REGISTER']['PERSONAL_PHONE'])) {
|
||||
$phone = htmlspecialchars($_POST['REGISTER']['PERSONAL_PHONE']);
|
||||
|
||||
if ($user !== null) {
|
||||
$user->setPersonalPhone($phone);
|
||||
$user->save();
|
||||
}
|
||||
$arFields['PERSONAL_PHONE'] = $phone;
|
||||
}
|
||||
|
||||
$arFields['ID'] = $arFields['USER_ID'];
|
||||
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
|
||||
$api = new ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
$api = new ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
RetailCrmUser::customerSend($arFields, $api, 'individual', true, $optionsSitesList);
|
||||
|
||||
//Если пользователь выразил желание зарегистрироваться в ПЛ и согласился со всеми правилами
|
||||
if ((int)$arFields['UF_REG_IN_PL_INTARO'] === 1
|
||||
&& (int)$arFields['UF_AGREE_PL_INTARO'] === 1
|
||||
&& (int)$arFields['UF_PD_PROC_PL_INTARO'] === 1
|
||||
) {
|
||||
$phone = $arFields['PERSONAL_PHONE'] ?? '';
|
||||
$card = $arFields['UF_CARD_NUM_INTARO'] ?? '';
|
||||
$customerId = (string) $arFields['USER_ID'];
|
||||
$customFields = $arFields['UF_CSTM_FLDS_INTARO'] ?? [];
|
||||
$service = new UserAccountService();
|
||||
$createResponse = $service->createLoyaltyAccount($phone, $card, $customerId, $customFields);
|
||||
|
||||
//если участник ПЛ создан и активирован
|
||||
if (($createResponse !== null)
|
||||
&& $createResponse->success === true
|
||||
&& $createResponse->loyaltyAccount->active
|
||||
) {
|
||||
global $USER_FIELD_MANAGER;
|
||||
|
||||
$USER_FIELD_MANAGER->Update('USER', $arFields['USER_ID'], [
|
||||
'UF_EXT_REG_PL_INTARO' => 'Y',
|
||||
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($createResponse->errorMsg)) {
|
||||
AddMessage2Log($createResponse->errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,18 +2,13 @@
|
|||
|
||||
namespace Intaro\RetailCrm\Controller\Loyalty;
|
||||
|
||||
use Bitrix\Main\Engine\ActionFilter\Authentication;
|
||||
use Bitrix\Main\Engine\Controller;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Component\Constants;
|
||||
use Intaro\RetailCrm\Component\Factory\ClientFactory;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountActivateRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
|
||||
use Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount;
|
||||
use Intaro\RetailCrm\Model\Api\SmsVerificationConfirm;
|
||||
use Intaro\RetailCrm\Model\Bitrix\User;
|
||||
use Intaro\RetailCrm\Service\UserAccountService;
|
||||
use RetailCrm\ApiClient;
|
||||
|
||||
class Register extends Controller
|
||||
{
|
||||
|
@ -51,19 +46,8 @@ class Register extends Controller
|
|||
|
||||
//TODO когда станет известен формат карты ПЛ, то добавить валидацию ввода
|
||||
|
||||
/** @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter $client */
|
||||
$client = ClientFactory::createClientAdapter();
|
||||
$credentials = $client->getCredentials();
|
||||
|
||||
$createRequest = new LoyaltyAccountCreateRequest();
|
||||
$createRequest->site = $credentials->sitesAvailable[0];
|
||||
$createRequest->loyaltyAccount = new SerializedCreateLoyaltyAccount();
|
||||
$createRequest->loyaltyAccount->phoneNumber = $loyaltyAccount['phone'] ?? '';
|
||||
$createRequest->loyaltyAccount->cardNumber = $loyaltyAccount['card'] ?? '';
|
||||
$createRequest->loyaltyAccount->customerId = $loyaltyAccount['customerId'];
|
||||
$createRequest->loyaltyAccount->customFields = $loyaltyAccount['customFields'] ?? [];
|
||||
|
||||
$createResponse = $client->createLoyaltyAccount($createRequest);
|
||||
$service = new UserAccountService();
|
||||
$createResponse = $service->createLoyaltyAccount($loyaltyAccount['phone'], $loyaltyAccount['card'], (string) $loyaltyAccount['customerId'], $loyaltyAccount['customFields']);
|
||||
//TODO добавить провеку на кастомные поля, когда будет готов метод запроса
|
||||
if ($createResponse !== null) {
|
||||
|
||||
|
@ -83,10 +67,8 @@ class Register extends Controller
|
|||
'msgColor' => 'green'
|
||||
];
|
||||
}
|
||||
|
||||
$activateRequest = new LoyaltyAccountActivateRequest();
|
||||
$activateRequest->loyaltyId = $createResponse->loyaltyAccount->id;
|
||||
$activateResponse = $client->activateLoyaltyAccount($activateRequest);
|
||||
|
||||
$activateResponse = $service->activateLoyaltyAccount($createResponse->loyaltyAccount->id);
|
||||
|
||||
if (isset($activateResponse->verification)) {
|
||||
return ['status' => 'smsVerification'];
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
*/
|
||||
namespace Intaro\RetailCrm\Model\Api;
|
||||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping;
|
||||
|
||||
/**
|
||||
* Class LoyaltyAccount
|
||||
*
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
*/
|
||||
namespace Intaro\RetailCrm\Model\Api;
|
||||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping;
|
||||
|
||||
/**
|
||||
* Class LoyaltyCalculation
|
||||
*
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
*/
|
||||
namespace Intaro\RetailCrm\Model\Api;
|
||||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping;
|
||||
|
||||
/**
|
||||
* Class LoyaltyLevel
|
||||
*
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace Intaro\RetailCrm\Model\Api\Request\Loyalty\Account;
|
|||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping;
|
||||
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
|
||||
use Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount;
|
||||
|
||||
/**
|
||||
* Class LoyaltyAccountCreateRequest
|
||||
|
@ -26,7 +25,7 @@ class LoyaltyAccountCreateRequest extends AbstractApiModel
|
|||
* @var \Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount
|
||||
*
|
||||
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount")
|
||||
* @Mapping\SerializedName("loyalty_account")
|
||||
* @Mapping\SerializedName("loyaltyAccount")
|
||||
*/
|
||||
public $loyaltyAccount;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class LoyaltyAccountEditRequest extends AbstractApiModel
|
|||
* @var \Intaro\RetailCrm\Model\Api\LoyaltyAccount
|
||||
*
|
||||
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\LoyaltyAccount")
|
||||
* @Mapping\SerializedName("loyalty_account")
|
||||
* @Mapping\SerializedName("loyaltyAccount")
|
||||
*/
|
||||
public $loyaltyAccount;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class LoyaltyAccountActivateResponse extends AbstractApiResponseModel
|
|||
* @var \Intaro\RetailCrm\Model\Api\LoyaltyAccount
|
||||
*
|
||||
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\LoyaltyAccount")
|
||||
* @Mapping\SerializedName("loyalty_account")
|
||||
* @Mapping\SerializedName("loyaltyAccount")
|
||||
*/
|
||||
public $loyaltyAccount;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class LoyaltyAccountCreateResponse extends AbstractApiResponseModel
|
|||
* @var \Intaro\RetailCrm\Model\Api\LoyaltyAccount
|
||||
*
|
||||
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\LoyaltyAccount")
|
||||
* @Mapping\SerializedName("loyalty_account")
|
||||
* @Mapping\SerializedName("loyaltyAccount")
|
||||
*/
|
||||
public $loyaltyAccount;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class LoyaltyAccountEditResponse extends AbstractApiResponseModel
|
|||
* @var \Intaro\RetailCrm\Model\Api\LoyaltyAccount
|
||||
*
|
||||
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\LoyaltyAccount")
|
||||
* @Mapping\SerializedName("loyalty_account")
|
||||
* @Mapping\SerializedName("loyaltyAccount")
|
||||
*/
|
||||
public $loyaltyAccount;
|
||||
|
||||
|
|
|
@ -43,12 +43,12 @@ class SerializedCreateLoyaltyAccount
|
|||
/**
|
||||
* ID клиента
|
||||
*
|
||||
* @var integer $customerId
|
||||
* @var \Intaro\RetailCrm\Model\Api\SerializedEntityCustomer
|
||||
*
|
||||
* @Mapping\Type("integer")
|
||||
* @Mapping\SerializedName("customerId")
|
||||
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedEntityCustomer")
|
||||
* @Mapping\SerializedName("customer")
|
||||
*/
|
||||
public $customerId;
|
||||
public $customer;
|
||||
|
||||
/**
|
||||
* Ассоциативный массив пользовательских полей
|
||||
|
|
43
intaro.retailcrm/lib/model/api/serializedentitycustomer.php
Normal file
43
intaro.retailcrm/lib/model/api/serializedentitycustomer.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Model\Api
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Model\Api;
|
||||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping;
|
||||
|
||||
/**
|
||||
* Class SerializedEntityCustomer
|
||||
* @package Intaro\RetailCrm\Model\Api
|
||||
*/
|
||||
class SerializedEntityCustomer
|
||||
{
|
||||
/**
|
||||
* Внутренний ID клиента
|
||||
*
|
||||
* @var integer $id
|
||||
*
|
||||
* @Mapping\Type("integer")
|
||||
* @Mapping\SerializedName("id")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* Внешний ID клиента
|
||||
*
|
||||
* @var string $externalId
|
||||
*
|
||||
* @Mapping\Type("string")
|
||||
* @Mapping\SerializedName("id")
|
||||
*/
|
||||
public $externalId;
|
||||
}
|
|
@ -9,20 +9,27 @@
|
|||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Service;
|
||||
|
||||
use Exception;
|
||||
use Intaro\RetailCrm\Component\Factory\ClientFactory;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountActivateRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountActivateResponse;
|
||||
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse;
|
||||
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
|
||||
use Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount;
|
||||
use Intaro\RetailCrm\Model\Api\SmsVerificationConfirm;
|
||||
use Intaro\RetailCrm\Repository\UserRepository;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class UserVerificationService
|
||||
*/
|
||||
class UserAccountService
|
||||
{
|
||||
public const NOT_AUTHORIZE = 'Пользователь на авторизован';
|
||||
/**
|
||||
* @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter
|
||||
*/
|
||||
|
@ -35,7 +42,7 @@ class UserAccountService
|
|||
{
|
||||
$this->client = ClientFactory::createClientAdapter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получает статус текущего состояния верификации
|
||||
*
|
||||
|
@ -79,6 +86,39 @@ class UserAccountService
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $loyaltyId
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountActivateResponse|null
|
||||
*/
|
||||
public function activateLoyaltyAccount(int $loyaltyId): ?LoyaltyAccountActivateResponse
|
||||
{
|
||||
$activateRequest = new LoyaltyAccountActivateRequest();
|
||||
$activateRequest->loyaltyId = $loyaltyId;
|
||||
return $this->client->activateLoyaltyAccount($activateRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $phone
|
||||
* @param string $card
|
||||
* @param string $externalId
|
||||
* @param array $customFields
|
||||
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse|null
|
||||
*/
|
||||
public function createLoyaltyAccount(string $phone, string $card, string $externalId, array $customFields=[]): ?LoyaltyAccountCreateResponse
|
||||
{
|
||||
$credentials = $this->client->getCredentials();
|
||||
|
||||
$createRequest = new LoyaltyAccountCreateRequest();
|
||||
$createRequest->site = $credentials->sitesAvailable[0];
|
||||
$createRequest->loyaltyAccount = new SerializedCreateLoyaltyAccount();
|
||||
$createRequest->loyaltyAccount->phoneNumber = $phone ?? '';
|
||||
$createRequest->loyaltyAccount->cardNumber = $card ?? '';
|
||||
$createRequest->loyaltyAccount->customer->externalId = $externalId;
|
||||
$createRequest->loyaltyAccount->customFields = $customFields ?? [];
|
||||
|
||||
return $this->client->createLoyaltyAccount($createRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
@ -88,7 +128,7 @@ class UserAccountService
|
|||
$user = $USER;
|
||||
|
||||
if (!$user->IsAuthorized()) {
|
||||
throw new Exception(self::NOT_AUTHORIZE);
|
||||
throw new RuntimeException(self::NOT_AUTHORIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue