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:
parent
cf8a8eb0ab
commit
4125565570
@ -212,6 +212,16 @@ class RetailcrmConfigProvider
|
|||||||
return static::$orderTypes;
|
return static::$orderTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setOrderTypes
|
||||||
|
*
|
||||||
|
* @param array $orderTypesArr
|
||||||
|
*/
|
||||||
|
public static function setOrderTypes($orderTypesArr)
|
||||||
|
{
|
||||||
|
static::setOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getDeliveryTypes
|
* getDeliveryTypes
|
||||||
*
|
*
|
||||||
@ -226,6 +236,16 @@ class RetailcrmConfigProvider
|
|||||||
return static::$deliveryTypes;
|
return static::$deliveryTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setDeliveryTypes
|
||||||
|
*
|
||||||
|
* @param array $deliveryTypesArr
|
||||||
|
*/
|
||||||
|
public static function setDeliveryTypes($deliveryTypesArr)
|
||||||
|
{
|
||||||
|
static::setOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getPaymentTypes
|
* getPaymentTypes
|
||||||
*
|
*
|
||||||
@ -240,6 +260,16 @@ class RetailcrmConfigProvider
|
|||||||
return static::$paymentTypes;
|
return static::$paymentTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setPaymentTypes
|
||||||
|
*
|
||||||
|
* @param array $paymentTypesArr
|
||||||
|
*/
|
||||||
|
public static function setPaymentTypes($paymentTypesArr)
|
||||||
|
{
|
||||||
|
static::setOption(RetailcrmConstants::CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getPaymentStatuses
|
* getPaymentStatuses
|
||||||
*
|
*
|
||||||
@ -254,6 +284,16 @@ class RetailcrmConfigProvider
|
|||||||
return static::$paymentStatuses;
|
return static::$paymentStatuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getPaymentStatuses
|
||||||
|
*
|
||||||
|
* @param array $paymentStatusesArr
|
||||||
|
*/
|
||||||
|
public static function setPaymentStatuses($paymentStatusesArr)
|
||||||
|
{
|
||||||
|
static::setOption(RetailcrmConstants::CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getPayment
|
* getPayment
|
||||||
*
|
*
|
||||||
@ -310,6 +350,16 @@ class RetailcrmConfigProvider
|
|||||||
return static::$contragentTypes;
|
return static::$contragentTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setContragentTypes
|
||||||
|
*
|
||||||
|
* @param array $contragentTypeArr
|
||||||
|
*/
|
||||||
|
public static function setContragentTypes($contragentTypeArr)
|
||||||
|
{
|
||||||
|
static::setOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getCustomFields
|
* getCustomFields
|
||||||
*
|
*
|
||||||
@ -350,6 +400,36 @@ class RetailcrmConfigProvider
|
|||||||
return static::getOption(RetailcrmConstants::CRM_ORDER_LAST_ID);
|
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
|
* setLastOrderId
|
||||||
*
|
*
|
||||||
|
@ -77,4 +77,5 @@ class RetailcrmConstants
|
|||||||
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
|
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
|
||||||
const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
|
const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
|
||||||
const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
|
const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
|
||||||
|
const SEND_PAYMENT_AMOUNT = 'send_payment_amount';
|
||||||
}
|
}
|
||||||
|
@ -486,8 +486,7 @@ class RetailCrmEvent
|
|||||||
|
|
||||||
if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) {
|
if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) {
|
||||||
$paymentToCrm = array(
|
$paymentToCrm = array(
|
||||||
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']],
|
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]
|
||||||
'amount' => $arPayment['SUM']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($arPayment['ID'])) {
|
if (!empty($arPayment['ID'])) {
|
||||||
@ -510,6 +509,10 @@ class RetailCrmEvent
|
|||||||
if (!empty($arPayment['ORDER_ID'])) {
|
if (!empty($arPayment['ORDER_ID'])) {
|
||||||
$paymentToCrm['order']['externalId'] = $arPayment['ORDER_ID'];
|
$paymentToCrm['order']['externalId'] = $arPayment['ORDER_ID'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RetailcrmConfigProvider::shouldSendPaymentAmount()) {
|
||||||
|
$paymentToCrm['amount'] = $arPayment['SUM'];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.');
|
RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.');
|
||||||
return false;
|
return false;
|
||||||
|
@ -255,18 +255,25 @@ class RetailCrmOrder
|
|||||||
foreach ($arFields['PAYMENTS'] as $payment) {
|
foreach ($arFields['PAYMENTS'] as $payment) {
|
||||||
if (!empty($payment['PAY_SYSTEM_ID']) && isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']])) {
|
if (!empty($payment['PAY_SYSTEM_ID']) && isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']])) {
|
||||||
$pm = array(
|
$pm = array(
|
||||||
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']],
|
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]
|
||||||
'amount' => $payment['SUM']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($payment['ID'])) {
|
if (!empty($payment['ID'])) {
|
||||||
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
|
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($payment['DATE_PAID'])) {
|
if (!empty($payment['DATE_PAID'])) {
|
||||||
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($arParams['optionsPayment'][$payment['PAID']])) {
|
if (!empty($arParams['optionsPayment'][$payment['PAID']])) {
|
||||||
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
|
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RetailcrmConfigProvider::shouldSendPaymentAmount()) {
|
||||||
|
$pm['amount'] = $payment['SUM'];
|
||||||
|
}
|
||||||
|
|
||||||
$payments[] = $pm;
|
$payments[] = $pm;
|
||||||
} else {
|
} else {
|
||||||
RCrmActions::eventLog(
|
RCrmActions::eventLog(
|
||||||
|
@ -75,6 +75,7 @@ $MESS ['ORDER_NUMBERS'] = 'Транслировать номера заказо
|
|||||||
$MESS ['CRM_API_VERSION'] = 'Версия API клиента';
|
$MESS ['CRM_API_VERSION'] = 'Версия API клиента';
|
||||||
$MESS ['CURRENCY'] = 'Валюта, устанавливаемая в заказе при выгрузке из CRM';
|
$MESS ['CURRENCY'] = 'Валюта, устанавливаемая в заказе при выгрузке из CRM';
|
||||||
$MESS ['ORDER_DIMENSIONS'] = 'Передавать габариты и вес товаров в заказе';
|
$MESS ['ORDER_DIMENSIONS'] = 'Передавать габариты и вес товаров в заказе';
|
||||||
|
$MESS ['SEND_PAYMENT_AMOUNT'] = 'Передавать сумму оплаты в заказе';
|
||||||
|
|
||||||
$MESS ['INVENTORIES_UPLOAD'] = 'Включить выгрузку остатков в разрезе складов';
|
$MESS ['INVENTORIES_UPLOAD'] = 'Включить выгрузку остатков в разрезе складов';
|
||||||
$MESS ['INVENTORIES'] = 'Склады';
|
$MESS ['INVENTORIES'] = 'Склады';
|
||||||
|
@ -344,8 +344,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
|||||||
}
|
}
|
||||||
//order numbers
|
//order numbers
|
||||||
$orderNumbers = htmlspecialchars(trim($_POST['order-numbers'])) ? htmlspecialchars(trim($_POST['order-numbers'])) : 'N';
|
$orderNumbers = htmlspecialchars(trim($_POST['order-numbers'])) ? htmlspecialchars(trim($_POST['order-numbers'])) : 'N';
|
||||||
|
|
||||||
$orderDimensions = htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) ? htmlspecialchars(trim($_POST[$CRM_DIMENSIONS])) : '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
|
//stores
|
||||||
$bitrixStoresArr = array();
|
$bitrixStoresArr = array();
|
||||||
@ -567,6 +567,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
|||||||
COption::SetOptionString($mid, $CRM_UA, $ua);
|
COption::SetOptionString($mid, $CRM_UA, $ua);
|
||||||
COption::SetOptionString($mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr($uaKeys)));
|
COption::SetOptionString($mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr($uaKeys)));
|
||||||
COption::SetOptionString($mid, $CRM_DIMENSIONS, $orderDimensions);
|
COption::SetOptionString($mid, $CRM_DIMENSIONS, $orderDimensions);
|
||||||
|
RetailcrmConfigProvider::setSendPaymentAmount($sendPaymentAmount);
|
||||||
|
|
||||||
COption::SetOptionString($mid, $CRM_DISCOUNT_ROUND, $discount_round);
|
COption::SetOptionString($mid, $CRM_DISCOUNT_ROUND, $discount_round);
|
||||||
COption::SetOptionString($mid, $CRM_PURCHASE_PRICE_NULL, $purchasePrice_null);
|
COption::SetOptionString($mid, $CRM_PURCHASE_PRICE_NULL, $purchasePrice_null);
|
||||||
@ -1202,6 +1203,15 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
|||||||
</b>
|
</b>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td colspan="2" class="option-head option-other-top option-other-bottom">
|
<td colspan="2" class="option-head option-other-top option-other-bottom">
|
||||||
<b>
|
<b>
|
||||||
|
8
intaro.retailcrm/update/updater-5.5.0.php
Normal file
8
intaro.retailcrm/update/updater-5.5.0.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function update_5_5_0()
|
||||||
|
{
|
||||||
|
if (!RetailcrmConfigProvider::shouldSendPaymentAmount()) {
|
||||||
|
RetailcrmConfigProvider::setSendPaymentAmount('Y');
|
||||||
|
}
|
||||||
|
}
|
29
intaro.retailcrm/updater.php
Normal file
29
intaro.retailcrm/updater.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
110
tests/classes/general/order/RetailCrmOrder_v5.php
Normal file
110
tests/classes/general/order/RetailCrmOrder_v5.php
Normal 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'])
|
||||||
|
]]
|
||||||
|
],
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user