1
0
mirror of synced 2025-02-20 08:53:15 +03:00

Remove status from integration payment (#192)

This commit is contained in:
RenCurs 2021-04-19 15:38:09 +03:00 committed by GitHub
parent e422557514
commit 4f2bc1a1b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 226 additions and 34 deletions

View File

@ -464,7 +464,6 @@ class RCrmActions
case 'paymentEditByExternalId':
return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'externalId', $site));
default:
return self::proxy($api, $methodApi, $method, array($params, $site));
}

View File

@ -66,6 +66,9 @@ class RetailcrmConfigProvider
/** @var array $paymentTypes */
private static $paymentTypes;
/** @var array $integrationPayment */
private static $integrationPayment;
/** @var array $paymentStatuses */
private static $paymentStatuses;
@ -295,6 +298,38 @@ class RetailcrmConfigProvider
return static::$paymentTypes;
}
/**
* getIntegrationPaymentTypes
*
* @return array
*/
public static function getIntegrationPaymentTypes(): array
{
if (self::isEmptyNotZero(static::$integrationPayment)) {
static::$integrationPayment = static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT);
}
return static::$integrationPayment;
}
/**
* setIntegrationPaymentTypes
* @param $integrationPayment
*/
public static function setIntegrationPaymentTypes($integrationPayment)
{
static::setOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT, serialize(RCrmActions::clearArr($integrationPayment)));
}
/**
* setIntegrationDelivery
* @param $deliveryIntegrationCode
*/
public static function setIntegrationDelivery($deliveryIntegrationCode)
{
static::setOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY, serialize(RCrmActions::clearArr($deliveryIntegrationCode)));
}
/**
* setPaymentTypes
*

View File

@ -28,6 +28,7 @@ class RetailcrmConstants
const CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
const CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr';
const CRM_PAYMENT_TYPES = 'pay_types_arr';
const CRM_INTEGRATION_PAYMENT = 'integration_payment';
const CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
const CRM_PAYMENT = 'payment_arr'; //order payment Y/N
const CRM_ORDER_LAST_ID = 'order_last_id';

View File

@ -441,6 +441,7 @@ class RetailCrmEvent
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
$optionsPaymentTypes = RetailcrmConfigProvider::getPaymentTypes();
$optionsPayStatuses = RetailcrmConfigProvider::getPayment();
$integrationPaymentTypes = RetailcrmConfigProvider::getIntegrationPaymentTypes();
$arPayment = array(
'ID' => $event->getId(),
@ -462,9 +463,7 @@ class RetailCrmEvent
$site = null;
}
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\ApiClient($api_host, $api_key);
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site);
if (isset($orderCrm['order'])) {
@ -531,6 +530,15 @@ class RetailCrmEvent
if (empty($paymentData)) {
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
} elseif ($paymentData['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
if (in_array($paymentData['type'], $integrationPaymentTypes)) {
RCrmActions::eventLog(
'RetailCrmEvent::paymentSave',
'payments',
'OrderID = ' . $arPayment['ID'] . '. Integration payment detected, which is not editable.'
);
return false;
}
$paymentToCrm['externalId'] = $paymentData['externalId'];
RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site);
} elseif ($paymentData['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {

View File

@ -252,6 +252,7 @@ class RetailCrmOrder
$order['weight'] = $weight;
}
$integrationPayment = RetailcrmConfigProvider::getIntegrationPaymentTypes();
//payments
$payments = array();
foreach ($arFields['PAYMENTS'] as $payment) {
@ -269,7 +270,9 @@ class RetailCrmOrder
}
if (!empty($arParams['optionsPayment'][$payment['PAID']])) {
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
if (array_search($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']], $integrationPayment) === false) {
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
}
}
if (RetailcrmConfigProvider::shouldSendPaymentAmount()) {

View File

@ -13,10 +13,10 @@ class RetailCrmService
public static function unsetIntegrationDeliveryFields(array $order): array
{
$integrationDelivery = RetailcrmConfigProvider::getCrmIntegrationDelivery();
if (isset($order['delivery']['code'])) {
$deliveryCode = $order['delivery']['code'];
if (!empty($integrationDelivery[$deliveryCode])
&& $integrationDelivery[$deliveryCode] !== 'sdek'
&& $integrationDelivery[$deliveryCode] !== 'dpd'
@ -32,7 +32,7 @@ class RetailCrmService
unset($order['delivery']['address']);
unset($order['delivery']['data']);
}
switch ($integrationDelivery[$deliveryCode]) {
case "sdek":
unset($order['weight']);
@ -71,7 +71,43 @@ class RetailCrmService
break;
}
}
return $order;
}
/**
* @param array $data
*
* @return array
*/
public static function selectIntegrationDeliveries(array $data): array
{
$result = [];
foreach ($data as $elem) {
if (!empty($elem['integrationCode'])) {
$result[$elem['code']] = $elem['integrationCode'];
}
}
return $result;
}
/**
* @param array $data
*
* @return array
*/
public static function selectIntegrationPayments(array $data): array
{
$result = [];
foreach ($data as $elem) {
if (!empty($elem['integrationModule'])) {
$result[] = $elem['code'];
}
}
return $result;
}
}

View File

@ -144,14 +144,14 @@ class intaro_retailcrm extends CModule
include($this->INSTALL_PATH . '/../classes/general/services/RetailCrmService.php');
$version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 0);
if ($version == 'v4') {
include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php');
include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v4.php');
include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v4.php');
} elseif ($version == 'v5') {
if ($version == 'v5') {
include($this->INSTALL_PATH . '/../classes/general/ApiClient_v5.php');
include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v5.php');
include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v5.php');
} elseif ($version == 'v4') {
include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php');
include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v4.php');
include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v4.php');
}
$step = intval($_REQUEST['step']);
@ -387,6 +387,17 @@ class intaro_retailcrm extends CModule
$delivTypes[$delivType['code']] = $delivType;
}
}
$this->loadDeps();
RetailcrmConfigProvider::setIntegrationDelivery(
RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList'])
);
RetailcrmConfigProvider::setIntegrationPaymentTypes(
RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList'])
);
$arResult['deliveryTypesList'] = $delivTypes;
//bitrix personTypes

View File

@ -233,7 +233,8 @@ else{
</tr>
<?php endforeach; ?>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_TYPES_LIST'); ?></b></td>
<td colspan="2"><b><?php echo GetMessage('PAYMENT_TYPES_LIST'); ?></b>
<p><small><?php echo GetMessage('INTEGRATION_PAYMENT_LIST');?></small></p></td>
</tr>
<?php foreach($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType): ?>
<tr>
@ -246,7 +247,9 @@ else{
<?php foreach($arResult['paymentTypesList'] as $paymentType): ?>
<option value="<?php echo $paymentType['code']; ?>"
<?php if($defaultPayTypes[$bitrixPaymentType['ID']] == $paymentType['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET); ?>
<?php
$nameType = isset($paymentType['integrationModule']) ? $APPLICATION->ConvertCharset($paymentType['name'] . GetMessage('INTEGRATIONS'), 'utf-8', SITE_CHARSET) : $APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET);
echo $nameType;?>
</option>
<?php endforeach; ?>
</select>
@ -364,4 +367,4 @@ else{
</div>
</div>
</form>
</div>
</div>

View File

@ -20,3 +20,5 @@ $MESS ['MESS_5'] = 'A server error occurred, please contact Intaro Software.';
$MESS ['DELIV_TYPES_EXPORT'] = 'Export a list of delivery types from 1C-Bitrix';
$MESS ['DELIV_TYPES_EXPORT_F'] = 'Set the correspondence between 1C-Bitrix and RetailCRM delivery types';
$MESS ['STATUS_NOT_SETTINGS'] ='Cannot find suitable statuses in Bitrix';
$MESS ['INTEGRATIONS'] = ' (integration)';
$MESS ['INTEGRATION_PAYMENT_LIST'] = 'The status will not be transferred for integration payments';

View File

@ -94,3 +94,5 @@ $MESS['PHONE_REQUIRED'] = "In the main module settings «Phone Number is require
$MESS['CHANGE_SHIPMENT_STATUS_FROM_CRM'] = "Change the shipment status when corresponding flag is received from RetailCRM";
$MESS ['ONLINE_CONSULTANT'] = 'Activate Online Consultant';
$MESS ['ONLINE_CONSULTANT_LABEL'] = 'Online Consultant script';
$MESS ['INTEGRATION_PAYMENT_LIST'] = 'The status will not be transferred for integration payments';
$MESS ['INTEGRATIONS'] = ' (integration)';

View File

@ -20,3 +20,5 @@ $MESS ['MESS_5'] = 'Произошла ошибка сервера, обрати
$MESS ['DELIV_TYPES_EXPORT'] = 'Выгрузить список доставок из 1С-Битрикс';
$MESS ['DELIV_TYPES_EXPORT_F'] = 'Настроить соответствие доставок 1С-Битрикс и RetailCRM';
$MESS ['STATUS_NOT_SETTINGS'] ='Не найдены подходящие статусы в Битрикс';
$MESS ['INTEGRATIONS'] = ' (интеграционная)';
$MESS ['INTEGRATION_PAYMENT_LIST'] = 'Для интеграционных оплат статус не передаётся';

View File

@ -22,6 +22,8 @@ $MESS ['ORDER_CUSTOM'] = 'Кастомные поля';
$MESS ['ORDER_UPLOAD'] = 'Повторная выгрузка заказов';
$MESS ['ORDER_NUMBER'] = 'Номера заказов: ';
$MESS ['ORDER_UPLOAD_INFO'] = 'Для загрузки всех заказов нажмите кнопку «Начать выгрузку». Или перечислите необходимые ID заказов через запятую, интервалы через тире. Например: 1, 3, 5-10, 12, 13... и т.д.';
$MESS ['INTEGRATION_PAYMENT_LIST'] = 'Для интеграционных оплат статус не передаётся';
$MESS ['INTEGRATIONS'] = ' (интеграционная)';
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки';
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить';

View File

@ -547,6 +547,24 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
COption::SetOptionString($mid, $CRM_CURRENCY, $_POST['currency']);
}
try {
$arResult['paymentTypesList'] = $api->paymentTypesList()->paymentTypes;
$arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes;
} catch (\RetailCrm\Exception\CurlException $e) {
RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode()));
}
$integrationPayments = RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList']);
$integrationDeliveries = RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList']);
RetailcrmConfigProvider::setIntegrationPaymentTypes($integrationPayments);
RetailcrmConfigProvider::setIntegrationDelivery($integrationDeliveries);
COption::SetOptionString($mid, $CRM_ADDRESS_OPTIONS, serialize($addressDatailOptions));
COption::SetOptionString($mid, $CRM_SITES_LIST, serialize($siteListArr));
COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
@ -634,18 +652,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
echo CAdminMessage::ShowMessage(GetMessage('ERR_JSON'));
}
$deliveryTypes = array();
$deliveryIntegrationCode = array();
foreach ($arResult['deliveryTypesList'] as $deliveryType) {
if ($deliveryType['active'] === true) {
$deliveryTypes[$deliveryType['code']] = $deliveryType;
$deliveryIntegrationCode[$deliveryType['code']] = $deliveryType['integrationCode'];
}
}
$arResult['deliveryTypesList'] = $deliveryTypes;
COption::SetOptionString($mid, RetailcrmConstants::CRM_INTEGRATION_DELIVERY, serialize(RCrmActions::clearArr($deliveryIntegrationCode)));
//bitrix orderTypesList -- personTypes
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
@ -699,7 +705,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$optionCollector = COption::GetOptionString($mid, $CRM_COLLECTOR, 0);
$optionCollectorKeys = unserialize(COption::GetOptionString($mid, $CRM_COLL_KEY));
$optionOnlineConsultant = RetailcrmConfigProvider::isOnlineConsultantEnabled();
$optionOnlineConsultantScript = RetailcrmConfigProvider::getOnlineConsultantScript();
@ -1003,7 +1009,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</td>
</tr>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_TYPES_LIST'); ?></b></td>
<td colspan="2"><b><?php echo GetMessage('PAYMENT_TYPES_LIST'); ?></b>
<p><small><?php echo GetMessage('INTEGRATION_PAYMENT_LIST');?></small></p></td>
</tr>
<?php foreach($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType): ?>
<tr>
@ -1015,7 +1022,9 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<option value="" selected=""></option>
<?php foreach($arResult['paymentTypesList'] as $paymentType): ?>
<option value="<?php echo $paymentType['code']; ?>" <?php if ($optionsPayTypes[$bitrixPaymentType['ID']] == $paymentType['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET); ?>
<?php
$nameType = isset($paymentType['integrationModule']) ? $APPLICATION->ConvertCharset($paymentType['name'] . GetMessage('INTEGRATIONS'), 'utf-8', SITE_CHARSET) : $APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET);
echo $nameType;?>
</option>
<?php endforeach; ?>
</select>
@ -1450,7 +1459,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</td>
</tr>
<?php endforeach;?>
<tr class="heading r-consultant-button">
<td colspan="2" class="option-other-heading">
<b>
@ -1459,7 +1468,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</td>
</tr>
<tr class="r-consultant" <?php if (!$optionOnlineConsultant) echo 'style="display: none;"'; ?>>
<tr class="r-consultant" <?php if (!$optionOnlineConsultant) echo 'style="display: none;"'; ?>>
<td class="adm-detail-content-cell-l" width="45%"><?php echo GetMessage('ONLINE_CONSULTANT_LABEL')?></td>
<td class="adm-detail-content-cell-r" width="55%">
<textarea name="online_consultant_script"><?php echo $optionOnlineConsultantScript; ?></textarea>

View File

@ -4,6 +4,7 @@
* Class RetailCrmOrderTest
*/
use \Bitrix\Main\Loader;
use \Bitrix\Main\Application;
class RetailCrmOrderTest extends BitrixTestCase
{
@ -17,9 +18,15 @@ class RetailCrmOrderTest extends BitrixTestCase
{
parent::setUp();
$cache = Application::getInstance()->getManagedCache();
$cache->clean('b_option:intaro.retailcrm');
$this->retailCrmOrder = \Mockery::mock('RetailCrmOrder');
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
CModule::IncludeModule('intaro.retailcrm');
RetailcrmConfigProvider::setPaymentTypes(['bitrixPayment' => 'crmPayment']);
RetailcrmConfigProvider::setIntegrationPaymentTypes(['crmPayment']);
}
public function testModuleInstalled()
@ -169,4 +176,76 @@ class RetailCrmOrderTest extends BitrixTestCase
]
];
}
/**
* @param array $arFields
* @param array $arParams
* @param string $methodApi
* @param array $expected
*
* @dataProvider orderSendProvider
*/
public function testOrderSend($arFields, $arParams, $methodApi, $expected)
{
$orderSend = RetailCrmOrder::orderSend(
$arFields,
new stdClass(),
$arParams,
false,
null,
$methodApi
);
$this->assertEquals($expected['payments'][0], $orderSend['payments'][0]);
}
/**
* @return array[]
*/
public function orderSendProvider()
{
$arFields = [
'ID' => 1,
'NUMBER' => 1,
'USER_ID' => 1,
'STATUS_ID' => 1,
'PERSON_TYPE_ID' => 'individual',
'DATE_INSERT' => '2015-02-22 00:00:00',
'USER_DESCRIPTION' => 'userComment',
'COMMENTS' => 'managerComment',
'PRICE_DELIVERY' => '100',
'PROPS' => ['properties' => []],
'DELIVERYS' => [[
'id' => 'test',
'service' => 'service'
]],
'BASKET' => [],
'PAYMENTS' => [[
'ID' => 1,
'PAY_SYSTEM_ID' => 'bitrixPayment',
'SUM' => 1000,
'DATE_PAID' => '2021-02-08 10:36:16',
'PAID' => 'paid'
]]
];
$arParams = [
'optionsPayTypes' => ['bitrixPayment' => 'crmPayment'],
'optionsPayment' => ['paid' => 'Y']
];
return [[
'arFields' => $arFields,
'arParams' => $arParams,
'methodApi' => 'ordersCreate',
'expected' => [
'number' => strval($arFields['NUMBER']),
'externalId' => strval($arFields['ID']),
'payments' => [[
'type' => $arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]['PAY_SYSTEM_ID']],
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID']),
'paidAt' => '2021-02-08 10:36:16'
]]
],
]];
}
}