1
0
mirror of synced 2024-11-21 21:06:09 +03:00

Ability to disable payment passthrough (#140)

* optional payment total in the order
* updater won't fail in case of error
This commit is contained in:
Pavel 2020-09-25 12:17:29 +03:00 committed by GitHub
parent cf8a8eb0ab
commit 4125565570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 254 additions and 5 deletions

View File

@ -212,6 +212,16 @@ class RetailcrmConfigProvider
return static::$orderTypes;
}
/**
* setOrderTypes
*
* @param array $orderTypesArr
*/
public static function setOrderTypes($orderTypesArr)
{
static::setOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
}
/**
* getDeliveryTypes
*
@ -226,6 +236,16 @@ class RetailcrmConfigProvider
return static::$deliveryTypes;
}
/**
* setDeliveryTypes
*
* @param array $deliveryTypesArr
*/
public static function setDeliveryTypes($deliveryTypesArr)
{
static::setOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr)));
}
/**
* getPaymentTypes
*
@ -240,6 +260,16 @@ class RetailcrmConfigProvider
return static::$paymentTypes;
}
/**
* setPaymentTypes
*
* @param array $paymentTypesArr
*/
public static function setPaymentTypes($paymentTypesArr)
{
static::setOption(RetailcrmConstants::CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr)));
}
/**
* getPaymentStatuses
*
@ -254,6 +284,16 @@ class RetailcrmConfigProvider
return static::$paymentStatuses;
}
/**
* getPaymentStatuses
*
* @param array $paymentStatusesArr
*/
public static function setPaymentStatuses($paymentStatusesArr)
{
static::setOption(RetailcrmConstants::CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr)));
}
/**
* getPayment
*
@ -310,6 +350,16 @@ class RetailcrmConfigProvider
return static::$contragentTypes;
}
/**
* setContragentTypes
*
* @param array $contragentTypeArr
*/
public static function setContragentTypes($contragentTypeArr)
{
static::setOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr)));
}
/**
* getCustomFields
*
@ -350,6 +400,36 @@ class RetailcrmConfigProvider
return static::getOption(RetailcrmConstants::CRM_ORDER_LAST_ID);
}
/**
* getSendPaymentAmount
*
* @return bool|string|null
*/
public static function getSendPaymentAmount()
{
return static::getOption(RetailcrmConstants::SEND_PAYMENT_AMOUNT);
}
/**
* setSendPaymentAmount
*
* @param string $value
*/
public static function setSendPaymentAmount($value)
{
static::setOption(RetailcrmConstants::SEND_PAYMENT_AMOUNT, $value);
}
/**
* Returns true if payment amount should be sent from CMS to retailCRM.
*
* @return bool|string|null
*/
public static function shouldSendPaymentAmount()
{
return static::getSendPaymentAmount() === 'Y';
}
/**
* setLastOrderId
*

View File

@ -77,4 +77,5 @@ class RetailcrmConstants
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
const SEND_PAYMENT_AMOUNT = 'send_payment_amount';
}

View File

@ -486,8 +486,7 @@ class RetailCrmEvent
if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) {
$paymentToCrm = array(
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']],
'amount' => $arPayment['SUM']
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]
);
if (!empty($arPayment['ID'])) {
@ -510,6 +509,10 @@ class RetailCrmEvent
if (!empty($arPayment['ORDER_ID'])) {
$paymentToCrm['order']['externalId'] = $arPayment['ORDER_ID'];
}
if (RetailcrmConfigProvider::shouldSendPaymentAmount()) {
$paymentToCrm['amount'] = $arPayment['SUM'];
}
} else {
RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.');
return false;

View File

@ -255,18 +255,25 @@ class RetailCrmOrder
foreach ($arFields['PAYMENTS'] as $payment) {
if (!empty($payment['PAY_SYSTEM_ID']) && isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']])) {
$pm = array(
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']],
'amount' => $payment['SUM']
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]
);
if (!empty($payment['ID'])) {
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
}
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 (RetailcrmConfigProvider::shouldSendPaymentAmount()) {
$pm['amount'] = $payment['SUM'];
}
$payments[] = $pm;
} else {
RCrmActions::eventLog(

View File

@ -75,6 +75,7 @@ $MESS ['ORDER_NUMBERS'] = 'Транслировать номера заказо
$MESS ['CRM_API_VERSION'] = 'Версия API клиента';
$MESS ['CURRENCY'] = 'Валюта, устанавливаемая в заказе при выгрузке из CRM';
$MESS ['ORDER_DIMENSIONS'] = 'Передавать габариты и вес товаров в заказе';
$MESS ['SEND_PAYMENT_AMOUNT'] = 'Передавать сумму оплаты в заказе';
$MESS ['INVENTORIES_UPLOAD'] = 'Включить выгрузку остатков в разрезе складов';
$MESS ['INVENTORIES'] = 'Склады';

View File

@ -344,8 +344,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
}
//order numbers
$orderNumbers = htmlspecialchars(trim($_POST['order-numbers'])) ? htmlspecialchars(trim($_POST['order-numbers'])) : 'N';
$orderDimensions = htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) ? htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) : 'N';
$sendPaymentAmount = htmlspecialchars(trim($_POST[RetailcrmConstants::SEND_PAYMENT_AMOUNT])) ? htmlspecialchars(trim($_POST[RetailcrmConstants::SEND_PAYMENT_AMOUNT])) : 'N';
//stores
$bitrixStoresArr = array();
@ -567,6 +567,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
COption::SetOptionString($mid, $CRM_UA, $ua);
COption::SetOptionString($mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr($uaKeys)));
COption::SetOptionString($mid, $CRM_DIMENSIONS, $orderDimensions);
RetailcrmConfigProvider::setSendPaymentAmount($sendPaymentAmount);
COption::SetOptionString($mid, $CRM_DISCOUNT_ROUND, $discount_round);
COption::SetOptionString($mid, $CRM_PURCHASE_PRICE_NULL, $purchasePrice_null);
@ -1202,6 +1203,15 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</b>
</td>
</tr>
<tr>
<td colspan="2" class="option-head option-other-top option-other-bottom">
<b>
<label>
<input class="addr" type="checkbox" name="<?php echo RetailcrmConstants::SEND_PAYMENT_AMOUNT; ?>" value="Y" <?php if(RetailcrmConfigProvider::shouldSendPaymentAmount()) echo "checked"; ?>> <?php echo GetMessage('SEND_PAYMENT_AMOUNT'); ?>
</label>
</b>
</td>
</tr>
<tr>
<td colspan="2" class="option-head option-other-top option-other-bottom">
<b>

View File

@ -0,0 +1,8 @@
<?php
function update_5_5_0()
{
if (!RetailcrmConfigProvider::shouldSendPaymentAmount()) {
RetailcrmConfigProvider::setSendPaymentAmount('Y');
}
}

View File

@ -0,0 +1,29 @@
<?php
$rcrmVersionFile = __DIR__ . '/install/version.php';
if(!CModule::IncludeModule('intaro.retailcrm')
|| !CModule::IncludeModule('sale')
|| !CModule::IncludeModule('iblock')
|| !CModule::IncludeModule('catalog')
|| !file_exists($rcrmVersionFile)
) {
return;
}
include_once $rcrmVersionFile;
if (!isset($arModuleVersion['VERSION'])) {
return;
}
$rcrmCurrentUpdateFile = __DIR__ . '/update/' . sprintf('updater-%s.php', $arModuleVersion['VERSION']);
if (file_exists($rcrmCurrentUpdateFile)) {
include_once $rcrmCurrentUpdateFile;
$functionName = 'update_' . str_replace('.', '_', $arModuleVersion['VERSION']);
if (function_exists($functionName)) {
$functionName();
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Class RetailCrmOrder_v5Test
*/
class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
/**
* setUp method
*/
public function setUp()
{
parent::setUp();
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
CModule::IncludeModule('intaro.retailcrm');
RetailcrmConfigProvider::setOrderTypes(['bitrixType' => 'crmType']);
RetailcrmConfigProvider::setContragentTypes(['bitrixType' => 'crmType']);
RetailcrmConfigProvider::setPaymentStatuses([1 => 'paymentStatus']);
RetailcrmConfigProvider::setPaymentTypes(['bitrixPayment' => 'crmPayment']);
RetailcrmConfigProvider::setDeliveryTypes(['test' => 'test']);
RetailcrmConfigProvider::setSendPaymentAmount('N');
}
/**
* @param array $arFields
* @param array $arParams
* @param string $methodApi
* @param array $expected
*
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\ObjectPropertyException
* @throws \Bitrix\Main\SystemException
* @dataProvider orderSendProvider
*/
public function testOrderSend($arFields, $arParams, $methodApi, $expected)
{
self::assertEquals($expected, RetailCrmOrder::orderSend(
$arFields,
new stdClass(),
$arParams,
false,
null,
$methodApi
));
}
/**
* @return array[]
*/
public function orderSendProvider()
{
$arFields = [
'ID' => 1,
'NUMBER' => 1,
'USER_ID' => 1,
'STATUS_ID' => 1,
'PERSON_TYPE_ID' => 'bitrixType',
'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
]]
];
$arParams = [
'optionsOrderTypes' => RetailcrmConfigProvider::getOrderTypes(),
'optionsPayStatuses' => RetailcrmConfigProvider::getPaymentStatuses(),
'optionsContragentType' => RetailcrmConfigProvider::getContragentTypes(),
'optionsDelivTypes' => RetailcrmConfigProvider::getDeliveryTypes(),
'optionsPayTypes' => RetailcrmConfigProvider::getPaymentTypes(),
'optionsPayment' => []
];
return [[
'arFields' => $arFields,
'arParams' => $arParams,
'methodApi' => 'ordersCreate',
'expected' => [
'number' => $arFields['NUMBER'],
'externalId' => $arFields['ID'],
'createdAt' => $arFields['DATE_INSERT'],
'customer' => ['externalId' => $arFields['USER_ID']],
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']],
'customerComment' => $arFields['USER_DESCRIPTION'],
'managerComment' => $arFields['COMMENTS'],
'delivery' => [
'cost' => $arFields['PRICE_DELIVERY'],
'code' => $arFields['DELIVERYS'][0]['service'],
],
'contragent' => [
'contragentType' => $arParams['optionsContragentType'][$arFields['PERSON_TYPE_ID']]
],
'payments' => [[
'type' => $arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]['PAY_SYSTEM_ID']],
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID'])
]]
],
]];
}
}