1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

add request models

This commit is contained in:
Sergey Chazov 2020-09-28 16:26:59 +03:00
parent 1446b7204e
commit 8cd87c54f5
20 changed files with 891 additions and 1 deletions

View file

@ -0,0 +1,50 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api;
/**
* Class LoyaltyAccount
*
* @package Intaro\RetailCrm\Model\Api
*/
class LoyaltyAccount
{
/**
* Номер телефона
*
* @var string $phoneNumber
*
* @Mapping\Type("string")
* @Mapping\SerializedName("phoneNumber")
*/
public $phoneNumber;
/**
* Номер карты
*
* @var string $cardNumber
*
* @Mapping\Type("string")
* @Mapping\SerializedName("cardNumber")
*/
public $cardNumber;
/**
* Id участия в программе лояльности
*
* @var integer $id
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("id")
*/
public $id;
}

View file

@ -0,0 +1,30 @@
<?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;
/**
* Class PriceType
*
* @package Intaro\RetailCrm\Model\Api
*/
class PriceType
{
/**
* Код типа цены
*
* @var string $code
*
* @Mapping\Type("string")
* @Mapping\SerializedName("code")
*/
public $code;
}

View file

@ -0,0 +1,33 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyAccountActivateRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyAccountActivateRequest extends AbstractApiModel
{
/**
* Id участия в программе лояльности
*
* @var string $loyaltyId
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("id")
*/
public $loyaltyId;
}

View file

@ -0,0 +1,31 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyAccountCreateRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyAccountCreateRequest extends AbstractApiModel
{
/**
* @var \Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount")
* @Mapping\SerializedName("loyalty_account")
*/
public $loyaltyAccount;
}

View file

@ -0,0 +1,31 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyAccountEditRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyAccountEditRequest extends AbstractApiModel
{
/**
* @var \Intaro\RetailCrm\Model\Api\LoyaltyAccount
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\LoyaltyAccount")
* @Mapping\SerializedName("loyalty_account")
*/
public $loyaltyAccount;
}

View file

@ -0,0 +1,40 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyCalculateRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyCalculateRequest extends AbstractApiModel
{
/**
* @var string $site
*
* @Mapping\Type("string")
* @Mapping\SerializedName("site")
*/
public $site;
/**
* @var \Intaro\RetailCrm\Model\Api\SerializedOrder
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedOrder")
* @Mapping\SerializedName("order")
*/
public $order;
}

View file

@ -0,0 +1,31 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Order\Loyalty
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Order\Loyalty;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class OrderLoyaltyApplyRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class OrderLoyaltyApplyRequest extends AbstractApiModel
{
/**
* @var \Intaro\RetailCrm\Model\Api\SerializedOrderReference
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedOrderReference")
* @Mapping\SerializedName("order")
*/
public $order;
}

View file

@ -24,7 +24,7 @@ class SmsVerificationStatusRequest extends AbstractApiModel
/**
* Номер телефона для отправки сообщения
*
* @var string $phone
* @var string $checkId
*
* @Mapping\Type("string")
* @Mapping\SerializedName("checkId")

View file

@ -0,0 +1,33 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyAccountActivateRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyAccountActivateRequest extends AbstractApiModel
{
/**
* Id участия в программе лояльности
*
* @var string $loyaltyId
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("id")
*/
public $loyaltyId;
}

View file

@ -0,0 +1,31 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyAccountCreateRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyAccountCreateRequest extends AbstractApiModel
{
/**
* @var \Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount")
* @Mapping\SerializedName("loyalty_account")
*/
public $loyaltyAccount;
}

View file

@ -0,0 +1,31 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyAccountEditRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyAccountEditRequest extends AbstractApiModel
{
/**
* @var \Intaro\RetailCrm\Model\Api\LoyaltyAccount
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\LoyaltyAccount")
* @Mapping\SerializedName("loyalty_account")
*/
public $loyaltyAccount;
}

View file

@ -0,0 +1,40 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Model\Api\Request\Loyalty;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\AbstractApiModel;
/**
* Class LoyaltyCalculateRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class LoyaltyCalculateRequest extends AbstractApiModel
{
/**
* @var string $site
*
* @Mapping\Type("string")
* @Mapping\SerializedName("site")
*/
public $site;
/**
* @var \Intaro\RetailCrm\Model\Api\SerializedOrder
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedOrder")
* @Mapping\SerializedName("order")
*/
public $order;
}

View file

@ -0,0 +1,60 @@
<?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;
/**
* Class SerializedCreateLoyaltyAccount
*
* @package Intaro\RetailCrm\Model\Api
*/
class SerializedCreateLoyaltyAccount
{
/**
* Номер телефона
*
* @var string $phoneNumber
*
* @Mapping\Type("string")
* @Mapping\SerializedName("phoneNumber")
*/
public $phoneNumber;
/**
* Номер карты
*
* @var string $cardNumber
*
* @Mapping\Type("string")
* @Mapping\SerializedName("cardNumber")
*/
public $cardNumber;
/**
* ID участия
*
* @var integer $loyaltyId
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("loyaltyId")
*/
public $loyaltyId;
/**
* ID клиента
*
* @var integer $customerId
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("customerId")
*/
public $customerId;
}

View file

@ -0,0 +1,66 @@
<?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;
/**
* Class SerializedOrder
*
* @package Intaro\RetailCrm\Model\Api
*/
class SerializedOrder
{
/**
* Денежная скидка на весь заказ
*
* @var double $discountManualAmount
*
* @Mapping\Type("double")
* @Mapping\SerializedName("discountManualAmount")
*/
public $discountManualAmount;
/**
* Процентная скидка на весь заказ. Система округляет это значение до 2 знаков после запятой
*
* @var double $discountManualPercent
*
* @Mapping\Type("double")
* @Mapping\SerializedName("discountManualPercent")
*/
public $discountManualPercent;
/**
* Клиент
*
* @var \Intaro\RetailCrm\Model\Api\SerializedRelationCustomer
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedRelationCustomer")
* @Mapping\SerializedName("customer")
*/
public $customer;
/**
* @var array $items
*
* @Mapping\Type("array<Intaro\RetailCrm\Model\Api\SerializedOrderProduct>")
* @Mapping\SerializedName("items")
*/
public $items;
/**
* @var \Intaro\RetailCrm\Model\Api\SerializedOrderDelivery
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedOrderDelivery")
* @Mapping\SerializedName("delivery")
*/
public $delivery;
}

View file

@ -0,0 +1,30 @@
<?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;
/**
* Class SerializedOrderDelivery
*
* @package Intaro\RetailCrm\Model\Api
*/
class SerializedOrderDelivery
{
/**
* Цена товара/SKU
*
* @var double $cost
*
* @Mapping\Type("double")
* @Mapping\SerializedName("cost")
*/
public $cost;
}

View file

@ -0,0 +1,90 @@
<?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;
/**
* Class SerializedOrderProduct
*
* @package Intaro\RetailCrm\Model\Api
*/
class SerializedOrderProduct
{
/**
* Цена товара/SKU
*
* @var double $initialPrice
*
* @Mapping\Type("double")
* @Mapping\SerializedName("initialPrice")
*/
public $initialPrice;
/**
* Денежная скидка на единицу товара
*
* @var double $discountManualAmount
*
* @Mapping\Type("double")
* @Mapping\SerializedName("discountManualAmount")
*/
public $discountManualAmount;
/**
* Процентная скидка на единицу товара. Система округляет это значение до 2 знаков после запятой
*
* @var double $discountManualPercent
*
* @Mapping\Type("double")
* @Mapping\SerializedName("discountManualPercent")
*/
public $discountManualPercent;
/**
* Количество
*
* @var float $quantity
*
* @Mapping\Type("float")
* @Mapping\SerializedName("quantity")
*/
public $quantity;
/**
* Торговое предложение
*
* @var \Intaro\RetailCrm\Model\Api\SerializedOrderProductOffer
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedOrderProductOffer")
* @Mapping\SerializedName("offer")
*/
public $offer;
/**
* Тип цены
*
* @var \Intaro\RetailCrm\Model\Api\PriceType
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\PriceType")
* @Mapping\SerializedName("priceType")
*/
public $priceType;
/**
* Данные о доставке
*
* @var \Intaro\RetailCrm\Model\Api\SerializedOrderDelivery
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\SerializedOrderDelivery")
* @Mapping\SerializedName("delivery")
*/
public $delivery;
}

View file

@ -0,0 +1,50 @@
<?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;
/**
* Class SerializedOrderProductOffer
*
* @package Intaro\RetailCrm\Model\Api
*/
class SerializedOrderProductOffer
{
/**
* ID торгового предложения
*
* @var integer $initialPrice
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("id")
*/
public $id;
/**
* Внешний ID торгового предложения
*
* @var string $externalId
*
* @Mapping\Type("string")
* @Mapping\SerializedName("externalId")
*/
public $externalId;
/**
* ID торгового предложения в складской системе
*
* @var string $xmlId
*
* @Mapping\Type("string")
* @Mapping\SerializedName("xmlId")
*/
public $xmlId;
}

View file

@ -0,0 +1,36 @@
<?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;
/**
* Class LoyaltyCalculateRequest
*
* @package Intaro\RetailCrm\Model\Api\Response\SmsVerification
*/
class SerializedOrderReference
{
/**
* @var integer $id
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("id")
*/
public $id;
/**
* @var float $bonuses
*
* @Mapping\Type("float")
* @Mapping\SerializedName("bonuses")
*/
public $bonuses;
}

View file

@ -0,0 +1,40 @@
<?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;
/**
* Class SerializedRelationCustomer
*
* @package Intaro\RetailCrm\Model\Api
*/
class SerializedRelationCustomer
{
/**
* Денежная скидка на весь заказ
*
* @var integer $id
*
* @Mapping\Type("integer")
* @Mapping\SerializedName("id")
*/
public $id;
/**
* Процентная скидка на весь заказ. Система округляет это значение до 2 знаков после запятой
*
* @var string $externalId
*
* @Mapping\Type("string")
* @Mapping\SerializedName("externalId")
*/
public $externalId;
}

View file

@ -0,0 +1,137 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Service
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @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\SmsVerification\SmsVerificationConfirmRequest;
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationCreateRequest;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
use Intaro\RetailCrm\Model\Api\SmsVerificationConfirm;
use Intaro\RetailCrm\Model\Api\SmsVerificationCreate;
use Intaro\RetailCrm\Repository\UserRepository;
/**
* Class UserVerificationService
*/
class UserAccountService
{
/**
* @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter
*/
private $client;
/**
* @var \CAllUser|\CUser
*/
private $user;
public function __construct()
{
$this->client = ClientFactory::createClientAdapter();
}
/**
* send verification sms
*
* @param string $actionType [verify_customer|verify_privacy]
* @param int|null $orderId
* @param int $verificationLength
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationCreateResponse|null
* @throws \Exception
*/
public function sendSms(
string $actionType = 'verify_customer',
int $orderId = null,
int $verificationLength = self::DEFAULT_CODE_LENGHT
) {
$this->checkAuth();
$userId = $this->user->GetID();
/** @var \Intaro\RetailCrm\Model\Bitrix\User $user */
$user = UserRepository::getFirstByParams(
[
['ID', '=', $userId]
],
['PERSONAL_PHONE']
);
$request = new SmsVerificationCreateRequest();
$request->verification = new SmsVerificationCreate();
$request->verification->setLength($verificationLength);
$request->verification->setPhone($user->getPersonalPhone());
$request->verification->setPhone($this->userId);
$request->verification->setActionType($actionType);
$request->verification->setCustomerId($userId);
$request->verification->setOrderId($orderId);
return $this->client->sendSmsForLpVerification($request);
}
/**
* Получает статус текущего состояния верификации
*
* @param string $checkId Идентификатор проверки кода
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse|null
*/
public function getSmsStatus(string $checkId)
{
$request = new SmsVerificationStatusRequest();
$request->checkId = $checkId;
return $this->client->checkStatusPlVerification($request);
}
/**
* Подтверждает верификацию
*
* @param string $code Проверочный код
* @param string $checkId Идентификатор проверки кода
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse|null
*/
public function confirmVerification(string $code, string $checkId)
{
$request = new SmsVerificationConfirmRequest();
$request->verification = new SmsVerificationConfirm();
$request->verification->setCode($code);
$request->verification->setCheckId($checkId);
return $this->client->confirmLpVerificationBySMS($request);
}
/**
* Проверяем статус регистрации пользователя в ПЛ
*
* @param int $userId
* @return bool
*/
public function checkPlRegistrationStatus(int $userId)
{
//TODO когда метод будет реализован в АПИ, нужно будет написать реализацию
return true;
}
/**
* @throws \Exception
*/
private function checkAuth()
{
global $USER;
$this->user = $USER;
if (!$this->user->IsAuthorized()) {
throw new Exception(self::NOT_AUTHORIZE);
}
}
}