1
0
mirror of synced 2024-11-25 23:06:08 +03:00

Merge pull request #68 from Neur0toxine/master

Изменена логика генерации externalId для оплат
This commit is contained in:
Alex Lushpai 2019-07-04 10:37:54 +03:00 committed by GitHub
commit 6d379c52f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 106 additions and 17 deletions

View File

@ -19,7 +19,7 @@ env:
before_script: before_script:
# Change MySQL root password # Change MySQL root password
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root - echo "USE mysql;\nUPDATE user SET authentication_string=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root
- composer install - composer install
- bash tests/bin/before_script.sh - bash tests/bin/before_script.sh

View File

@ -1,5 +1,6 @@
## 2019-07-01 v.2.4.8 ## 2019-07-01 v.2.4.8
* Исправлена отправка пустого заказа при удалении заказа из СMS * Исправлена отправка пустого заказа при удалении заказа из СMS
* Изменена логика генерации внешнего идентификатора оплат для сохранения его уникальности в пределах системы
## 2019-03-28 v.2.4.7 ## 2019-03-28 v.2.4.7
* Добавлено удаление в системе типа цены у товара для неактивного типа цены на сайте * Добавлено удаление в системе типа цены у товара для неактивного типа цены на сайте

View File

@ -700,7 +700,7 @@ class ApiClient
} }
return $this->client->makeRequest( return $this->client->makeRequest(
sprintf('/orders/payments/%s/edit', $payment[$by]), sprintf('/orders/payments/%s/edit', urlencode($payment[$by])),
Client::METHOD_POST, Client::METHOD_POST,
$this->fillSite( $this->fillSite(
$site, $site,

View File

@ -268,6 +268,67 @@ class RCrmActions
return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET);
} }
/**
* Extracts payment ID or client ID from payment externalId
* Payment ID - pass nothing or 'id' as second argument
* Client ID - pass 'client_id' as second argument
*
* @param $externalId
* @param string $data
* @return bool|string
*/
public static function getFromPaymentExternalId($externalId, $data = 'id')
{
switch ($data) {
case 'id':
if (false === strpos($externalId, '_')) {
return $externalId;
} else {
return substr($externalId, 0, strpos($externalId, '_'));
}
break;
case 'client_id':
if (false === strpos($externalId, '_')) {
return '';
} else {
return substr($externalId, strpos($externalId, '_'), count($externalId));
}
break;
}
return '';
}
/**
* Returns true if provided externalId in new format (id_clientId)
*
* @param $externalId
* @return bool
*/
public static function isNewExternalId($externalId)
{
return !(false === strpos($externalId, '_'));
}
/**
* Generates payment external ID
*
* @param $id
*
* @return string
*/
public static function generatePaymentExternalId($id)
{
return sprintf(
'%s_%s',
$id,
COption::GetOptionString(self::$MODULE_ID, 'client_id', 0)
);
}
/** /**
* Unserialize array * Unserialize array
* *

View File

@ -267,10 +267,15 @@ class RetailCrmEvent
if ($payments) { if ($payments) {
foreach ($payments as $payment) { foreach ($payments as $payment) {
if (isset($payment['externalId'])) { if (isset($payment['externalId'])) {
if (RCrmActions::isNewExternalId($payment['externalId'])) {
$paymentsExternalIds[RCrmActions::getFromPaymentExternalId($payment['externalId'])] =
$payment;
} else {
$paymentsExternalIds[$payment['externalId']] = $payment; $paymentsExternalIds[$payment['externalId']] = $payment;
} }
} }
} }
}
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(
@ -279,7 +284,7 @@ class RetailCrmEvent
); );
if (!empty($arPayment['ID'])) { if (!empty($arPayment['ID'])) {
$paymentToCrm['externalId'] = $arPayment['ID']; $paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']);
} }
if (!empty($arPayment['DATE_PAID'])) { if (!empty($arPayment['DATE_PAID'])) {
@ -303,12 +308,28 @@ class RetailCrmEvent
return false; return false;
} }
if (!array_key_exists($arPayment['ID'], $paymentsExternalIds)) { $arPaymentExtId = RCrmActions::generatePaymentExternalId($arPayment['ID']);
if (array_key_exists($arPaymentExtId, $paymentsExternalIds)) {
$paymentData = $paymentsExternalIds[$arPaymentExtId];
} elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds)) {
$paymentData = $paymentsExternalIds[$arPayment['ID']];
} else {
$paymentData = array();
}
if (empty($paymentData)) {
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
} elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds) && $paymentsExternalIds[$arPayment['ID']]['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { } elseif ($paymentData['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
$paymentToCrm['externalId'] = $paymentData['externalId'];
RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site); RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site);
} elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds) && $paymentsExternalIds[$arPayment['ID']]['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { } elseif ($paymentData['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $paymentsExternalIds[$arPayment['ID']]['id']); RCrmActions::apiMethod(
$api,
'ordersPaymentDelete',
__METHOD__,
$paymentData['id']
);
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
} }
@ -356,7 +377,10 @@ class RetailCrmEvent
if (isset($orderCrm['order']['payments']) && $orderCrm['order']['payments']) { if (isset($orderCrm['order']['payments']) && $orderCrm['order']['payments']) {
foreach ($orderCrm['order']['payments'] as $payment) { foreach ($orderCrm['order']['payments'] as $payment) {
if (isset($payment['externalId']) && $payment['externalId'] == $event->getId()) { if (isset($payment['externalId'])
&& ($payment['externalId'] == $event->getId()
|| RCrmActions::getFromPaymentExternalId($payment['externalId']) == $event->getId())
) {
RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $payment['id']); RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $payment['id']);
} }
} }

View File

@ -762,12 +762,13 @@ class RetailCrmHistory
if (!empty($newHistoryPayments)) { if (!empty($newHistoryPayments)) {
foreach ($newOrder->getPaymentCollection() as $orderPayment) { foreach ($newOrder->getPaymentCollection() as $orderPayment) {
if (array_key_exists($orderPayment->getField('XML_ID'), $newHistoryPayments)) { if (array_key_exists($orderPayment->getField('XML_ID'), $newHistoryPayments)) {
$paymentExternalId = $orderPayment->getId(); $paymentId = $orderPayment->getId();
$paymentExternalId = RCrmActions::generatePaymentExternalId($paymentId);
if ($paymentExternalId) { if ($paymentExternalId) {
$newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId; $newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId;
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]); RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]);
\Bitrix\Sale\Internals\PaymentTable::update($paymentExternalId, array('XML_ID' => '')); \Bitrix\Sale\Internals\PaymentTable::update($paymentId, array('XML_ID' => ''));
} }
} }
} }
@ -1140,7 +1141,8 @@ class RetailCrmHistory
foreach ($paymentsCrm['payments'] as $paymentCrm) { foreach ($paymentsCrm['payments'] as $paymentCrm) {
if (isset($paymentCrm['externalId']) && !empty($paymentCrm['externalId'])) { if (isset($paymentCrm['externalId']) && !empty($paymentCrm['externalId'])) {
//find the payment //find the payment
$nowPayment = $paymentsList[$paymentCrm['externalId']]; $nowPaymentId = RCrmActions::getFromPaymentExternalId($paymentCrm['externalId']);
$nowPayment = $paymentsList[$nowPaymentId];
//update data //update data
if ($nowPayment instanceof \Bitrix\Sale\Payment) { if ($nowPayment instanceof \Bitrix\Sale\Payment) {
$nowPayment->setField('SUM', $paymentCrm['amount']); $nowPayment->setField('SUM', $paymentCrm['amount']);
@ -1152,7 +1154,7 @@ class RetailCrmHistory
$nowPayment->setField('PAID', $optionsPayment[$paymentCrm['status']]); $nowPayment->setField('PAID', $optionsPayment[$paymentCrm['status']]);
} }
unset($paymentsList[$paymentCrm['externalId']]); unset($paymentsList[$nowPaymentId]);
} }
} else { } else {
$newHistoryPayments[$paymentCrm['id']] = $paymentCrm; $newHistoryPayments[$paymentCrm['id']] = $paymentCrm;

View File

@ -205,7 +205,7 @@ class RetailCrmOrder
'amount' => $payment['SUM'] 'amount' => $payment['SUM']
); );
if (!empty($payment['ID'])) { if (!empty($payment['ID'])) {
$pm['externalId'] = $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']);

View File

@ -1 +1,2 @@
- Добавлено удаление неактивного типа цены у товара в системе - Исправлена отправка пустого заказа при удалении заказа из СMS
- Изменена логика генерации внешнего идентификатора оплат для сохранения его уникальности в пределах системы

View File

@ -1,5 +1,5 @@
<? <?
$arModuleVersion = array( $arModuleVersion = array(
"VERSION" => "2.4.7", "VERSION" => "2.4.8",
"VERSION_DATE" => "2019-05-23 16:30:00" "VERSION_DATE" => "2019-06-03 13:14:00"
); );