ref #92904
Возврат логики сохранения подмененной оплаты Код для подмены оплаты перенесен в константы Добавлена подмена оплаты при отправке заказа в систему
This commit is contained in:
parent
27a7092a0c
commit
04960ec669
3 changed files with 34 additions and 31 deletions
|
@ -9,6 +9,7 @@ use Bitrix\Sale\Internals\OrderTable;
|
|||
use Bitrix\Sale\Location\LocationTable;
|
||||
use Bitrix\Sale\Order;
|
||||
use Intaro\RetailCrm\Component\ApiClient\ClientAdapter;
|
||||
use Intaro\RetailCrm\Component\Constants;
|
||||
use Intaro\RetailCrm\Component\Factory\ClientFactory;
|
||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||
use Intaro\RetailCrm\Service\LoyaltyService;
|
||||
|
@ -368,26 +369,35 @@ class RetailCrmOrder
|
|||
$isIntegrationPayment = RetailCrmService::isIntegrationPayment($payment['PAY_SYSTEM_ID'] ?? null);
|
||||
|
||||
if (!empty($payment['PAY_SYSTEM_ID']) && isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']])) {
|
||||
$pm = [
|
||||
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]
|
||||
];
|
||||
$pm = [];
|
||||
|
||||
if (!empty($payment['DATE_PAID'])) {
|
||||
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
||||
}
|
||||
|
||||
if (!empty($arParams['optionsPayment'][$payment['PAID']])) {
|
||||
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
|
||||
}
|
||||
|
||||
if (!empty($payment['ID'])) {
|
||||
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
|
||||
}
|
||||
|
||||
if (!empty($payment['DATE_PAID']) && !$isIntegrationPayment) {
|
||||
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
||||
}
|
||||
|
||||
if (!empty($arParams['optionsPayment'][$payment['PAID']]) && !$isIntegrationPayment) {
|
||||
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
|
||||
}
|
||||
|
||||
if (RetailcrmConfigProvider::shouldSendPaymentAmount()) {
|
||||
$pm['amount'] = $payment['SUM'];
|
||||
}
|
||||
|
||||
if ($isIntegrationPayment && RetailcrmConfigProvider::getSyncIntegrationPayment() === 'Y') {
|
||||
$pm['type'] = $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']] .
|
||||
Constants::CRM_PART_SUBSTITUTED_PAYMENT_CODE;
|
||||
} else {
|
||||
$pm['type'] = $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']];
|
||||
|
||||
if ($isIntegrationPayment) {
|
||||
unset($pm['paidAt'], $pm['status']);
|
||||
}
|
||||
}
|
||||
|
||||
$payments[] = $pm;
|
||||
} else {
|
||||
RCrmActions::eventLog(
|
||||
|
|
|
@ -109,4 +109,5 @@ class Constants
|
|||
public const USE_CRM_ORDER_METHODS = 'use_crm_order_methods';
|
||||
public const CRM_ORDER_METHODS = 'crm_order_methods';
|
||||
public const SYNC_INTEGRATION_PAYMENT = 'sync_integration_payment';
|
||||
public const CRM_PART_SUBSTITUTED_PAYMENT_CODE = '-not-integration';
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ $CRM_CART = 'cart';
|
|||
$MODULE_DEACTIVATE = 'module_deactivate';
|
||||
$AGENTS_DEACTIVATE = 'agents_deactivate';
|
||||
$EVENTS_DEACTIVATE = 'events_deactivate';
|
||||
$CRM_PART_SUBSTITUTED_PAYMENT_CODE = '-not-integration';
|
||||
|
||||
if (!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('catalog')) {
|
||||
return;
|
||||
|
@ -784,6 +783,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
$CRM_DELIVERY_TYPES_ARR,
|
||||
serialize(RCrmActions::clearArr(is_array($deliveryTypesArr) ? $deliveryTypesArr : []))
|
||||
);
|
||||
COption::SetOptionString(
|
||||
$mid,
|
||||
$CRM_PAYMENT_TYPES,
|
||||
serialize(RCrmActions::clearArr(is_array($paymentTypesArr) ? $paymentTypesArr : []))
|
||||
);
|
||||
COption::SetOptionString(
|
||||
$mid,
|
||||
$CRM_PAYMENT_STATUSES,
|
||||
|
@ -834,15 +838,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
|
||||
$syncIntegrationPayment = htmlspecialchars(trim($_POST['sync-integration-payment'])) ?: 'N';
|
||||
|
||||
ConfigProvider::setSyncIntegrationPayment($syncIntegrationPayment);
|
||||
|
||||
if ($syncIntegrationPayment === 'Y') {
|
||||
$crmCodePaymentList = array_column($arResult['paymentTypesList'], 'code');
|
||||
|
||||
foreach (RetailcrmConfigProvider::getIntegrationPaymentTypes() as $integrationPayment) {
|
||||
if (in_array($integrationPayment, $paymentTypesArr)) {
|
||||
$originalPayment = $arResult['paymentTypesList'][$integrationPayment];
|
||||
$codePayment = $integrationPayment . $CRM_PART_SUBSTITUTED_PAYMENT_CODE;
|
||||
$codePayment = $integrationPayment . Constants::CRM_PART_SUBSTITUTED_PAYMENT_CODE;
|
||||
|
||||
$response = $api->paymentTypesEdit([
|
||||
'name' => $originalPayment['name'] . ' ' . GetMessage('NO_INTEGRATION_PAYMENT'),
|
||||
|
@ -855,31 +857,21 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
|
||||
$statusCode = $response->getStatusCode();
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$listKeys = array_keys($paymentTypesArr, $integrationPayment);
|
||||
|
||||
foreach ($listKeys as $key) {
|
||||
$paymentTypesArr[$key] = $codePayment;
|
||||
}
|
||||
} else {
|
||||
if (!$response->isSuccessful()) {
|
||||
RCrmActions::eventLog(
|
||||
'Retailcrm::options.php',
|
||||
'syncIntegrationPayment',
|
||||
GetMessage('ERROR_LINK_INTEGRATION_PAYMENT') . ' : ' . $response->getResponseBody()
|
||||
);
|
||||
|
||||
$syncIntegrationPayment = 'N';
|
||||
$error = 'ERR_CHECK_JOURNAL';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
COption::SetOptionString(
|
||||
$mid,
|
||||
$CRM_PAYMENT_TYPES,
|
||||
serialize(RCrmActions::clearArr(is_array($paymentTypesArr) ? $paymentTypesArr : []))
|
||||
);
|
||||
|
||||
ConfigProvider::setSyncIntegrationPayment($syncIntegrationPayment);
|
||||
COption::SetOptionString(
|
||||
$mid,
|
||||
$CRM_COUPON_FIELD,
|
||||
|
@ -1147,8 +1139,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
|
||||
$arResult['paymentTypesList'] = array_filter(
|
||||
$arResult['paymentTypesList'],
|
||||
function ($payment) use ($CRM_PART_SUBSTITUTED_PAYMENT_CODE) {
|
||||
return strripos($payment['code'], $CRM_PART_SUBSTITUTED_PAYMENT_CODE) === false;
|
||||
function ($payment) {
|
||||
return strripos($payment['code'], Constants::CRM_PART_SUBSTITUTED_PAYMENT_CODE) === false;
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -1923,7 +1915,7 @@ 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 (explode($CRM_PART_SUBSTITUTED_PAYMENT_CODE, $optionsPayTypes[$bitrixPaymentType['ID']])[0] === $paymentType['code']) {
|
||||
<?php if ($optionsPayTypes[$bitrixPaymentType['ID']] === $paymentType['code']) {
|
||||
echo 'selected';
|
||||
} ?>>
|
||||
<?php echo $APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET); ?>
|
||||
|
|
Loading…
Add table
Reference in a new issue