Remove date for integration payment (#214)
This commit is contained in:
parent
9354bca0b3
commit
d06cb3c6e6
@ -7,7 +7,6 @@ log_errors = On
|
|||||||
display_startup_errors = On
|
display_startup_errors = On
|
||||||
cgi.fix_pathinfo = 0
|
cgi.fix_pathinfo = 0
|
||||||
date.timezone = "Europe/Moscow"
|
date.timezone = "Europe/Moscow"
|
||||||
mbstring.func_overload = 2
|
|
||||||
mbstring.internal_encoding = "UTF-8"
|
mbstring.internal_encoding = "UTF-8"
|
||||||
default_charset = utf-8
|
default_charset = utf-8
|
||||||
max_input_vars = 10000
|
max_input_vars = 10000
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@
|
|||||||
.env
|
.env
|
||||||
.phpunit.result.cache
|
.phpunit.result.cache
|
||||||
/release/
|
/release/
|
||||||
|
coverage.xml
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Bitrix\Main\Context\Culture;
|
||||||
use Intaro\RetailCrm\Service\ManagerService;
|
use Intaro\RetailCrm\Service\ManagerService;
|
||||||
use Bitrix\Sale\Payment;
|
use Bitrix\Sale\Payment;
|
||||||
use RetailCrm\ApiClient;
|
use RetailCrm\ApiClient;
|
||||||
@ -497,16 +498,19 @@ class RetailCrmEvent
|
|||||||
$paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']);
|
$paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($arPayment['DATE_PAID'])) {
|
$isIntegrationPayment
|
||||||
|
= RetailCrmService::isIntegrationPayment($arPayment['PAY_SYSTEM_ID'] ?? null);
|
||||||
|
|
||||||
|
if (!empty($arPayment['DATE_PAID']) && !$isIntegrationPayment) {
|
||||||
if (is_object($arPayment['DATE_PAID'])) {
|
if (is_object($arPayment['DATE_PAID'])) {
|
||||||
$culture = new Bitrix\Main\Context\Culture(['FORMAT_DATETIME' => 'YYYY-MM-DD HH:MI:SS']);
|
$culture = new Culture(['FORMAT_DATETIME' => 'YYYY-MM-DD HH:MI:SS']);
|
||||||
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID']->toString($culture);
|
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID']->toString($culture);
|
||||||
} elseif (is_string($arPayment['DATE_PAID'])) {
|
} elseif (is_string($arPayment['DATE_PAID'])) {
|
||||||
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID'];
|
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($optionsPayStatuses[$arPayment['PAID']])) {
|
if (!empty($optionsPayStatuses[$arPayment['PAID']]) && !$isIntegrationPayment) {
|
||||||
$paymentToCrm['status'] = $optionsPayStatuses[$arPayment['PAID']];
|
$paymentToCrm['status'] = $optionsPayStatuses[$arPayment['PAID']];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,11 +274,12 @@ class RetailCrmOrder
|
|||||||
$order['weight'] = $weight;
|
$order['weight'] = $weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
$integrationPayment = RetailcrmConfigProvider::getIntegrationPaymentTypes();
|
|
||||||
//payments
|
//payments
|
||||||
$payments = [];
|
$payments = [];
|
||||||
|
|
||||||
foreach ($arOrder['PAYMENTS'] as $payment) {
|
foreach ($arOrder['PAYMENTS'] as $payment) {
|
||||||
|
$isIntegrationPayment = RetailCrmService::isIntegrationPayment($payment['PAY_SYSTEM_ID'] ?? null);
|
||||||
|
|
||||||
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 = [
|
$pm = [
|
||||||
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]
|
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]
|
||||||
@ -288,14 +289,11 @@ class RetailCrmOrder
|
|||||||
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
|
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($payment['DATE_PAID'])) {
|
if (!empty($payment['DATE_PAID']) && !$isIntegrationPayment) {
|
||||||
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!empty($arParams['optionsPayment'][$payment['PAID']]) && !$isIntegrationPayment) {
|
||||||
!empty($arParams['optionsPayment'][$payment['PAID']])
|
|
||||||
&& !in_array($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']], $integrationPayment)
|
|
||||||
) {
|
|
||||||
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
|
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,4 +110,17 @@ class RetailCrmService
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int|null $paySystemId
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isIntegrationPayment(?int $paySystemId): bool {
|
||||||
|
return in_array(
|
||||||
|
RetailcrmConfigProvider::getPaymentTypes()[$paySystemId] ?? null,
|
||||||
|
RetailcrmConfigProvider::getIntegrationPaymentTypes(),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,37 @@ class BitrixTestCase extends \PHPUnit\Framework\TestCase
|
|||||||
// без этого вызова Mockery не будет работать
|
// без этого вызова Mockery не будет работать
|
||||||
\Mockery::close();
|
\Mockery::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getArFields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'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' => 1,
|
||||||
|
'SUM' => 1000,
|
||||||
|
'DATE_PAID' => $this->getDateTime(),
|
||||||
|
'PAID' => 'Y'
|
||||||
|
]]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateTime(): \Bitrix\Main\Type\DateTime
|
||||||
|
{
|
||||||
|
return \Bitrix\Main\Type\DateTime::createFromPhp(new DateTime('2000-01-01'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,3 +38,4 @@ VALUES ('2020-05-08 19:04:03', 'iblock', '500', '500', '23791', 'image/jpeg', 'i
|
|||||||
$DB->Query($strSql);
|
$DB->Query($strSql);
|
||||||
|
|
||||||
require_once 'BitrixTestCase.php';
|
require_once 'BitrixTestCase.php';
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
/**
|
/**
|
||||||
* Class RetailCrmOrder_v5Test
|
* Class RetailCrmOrder_v5Test
|
||||||
*/
|
*/
|
||||||
class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
|
class RetailCrmOrder_v5Test extends BitrixTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp method
|
* setUp method
|
||||||
*/
|
*/
|
||||||
@ -13,12 +14,6 @@ class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
||||||
CModule::IncludeModule('intaro.retailcrm');
|
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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,40 +39,55 @@ class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider orderSendProvider
|
||||||
|
*/
|
||||||
|
public function testOrderSendWitIntegrationPayment(
|
||||||
|
array $arFields,
|
||||||
|
array $arParams,
|
||||||
|
string $methodApi,
|
||||||
|
array $expected
|
||||||
|
): void {
|
||||||
|
RetailcrmConfigProvider::setIntegrationPaymentTypes(['testPayment']);
|
||||||
|
|
||||||
|
$orderSend = RetailCrmOrder::orderSend(
|
||||||
|
$arFields,
|
||||||
|
new stdClass(),
|
||||||
|
$arParams,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
$methodApi
|
||||||
|
);
|
||||||
|
|
||||||
|
unset($expected['payments'][0]['paidAt'], $expected['payments'][0]['status']);
|
||||||
|
static::assertEquals($expected['payments'][0], $orderSend['payments'][0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initSystemData(): void
|
||||||
|
{
|
||||||
|
RetailcrmConfigProvider::setOrderTypes(['bitrixType' => 'crmType']);
|
||||||
|
RetailcrmConfigProvider::setContragentTypes(['bitrixType' => 'individual']);
|
||||||
|
RetailcrmConfigProvider::setPaymentStatuses([1 => 'paymentStatus']);
|
||||||
|
RetailcrmConfigProvider::setPaymentTypes([1 => 'testPayment']);
|
||||||
|
RetailcrmConfigProvider::setDeliveryTypes(['test' => 'test']);
|
||||||
|
RetailcrmConfigProvider::setSendPaymentAmount('N');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
public function orderSendProvider()
|
public function orderSendProvider()
|
||||||
{
|
{
|
||||||
$arFields = [
|
$arFields = $this->getArFields();
|
||||||
'ID' => 1,
|
$this->initSystemData();
|
||||||
'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 = [
|
$arParams = [
|
||||||
'optionsOrderTypes' => RetailcrmConfigProvider::getOrderTypes(),
|
'optionsOrderTypes' => RetailcrmConfigProvider::getOrderTypes(),
|
||||||
'optionsPayStatuses' => RetailcrmConfigProvider::getPaymentStatuses(),
|
'optionsPayStatuses' => RetailcrmConfigProvider::getPaymentStatuses(),
|
||||||
'optionsContragentType' => RetailcrmConfigProvider::getContragentTypes(),
|
'optionsContragentType' => RetailcrmConfigProvider::getContragentTypes(),
|
||||||
'optionsDelivTypes' => RetailcrmConfigProvider::getDeliveryTypes(),
|
'optionsDelivTypes' => RetailcrmConfigProvider::getDeliveryTypes(),
|
||||||
'optionsPayTypes' => RetailcrmConfigProvider::getPaymentTypes(),
|
'optionsPayTypes' => RetailcrmConfigProvider::getPaymentTypes(),
|
||||||
'optionsPayment' => []
|
'optionsPayment' => ['Y' => 'paid']
|
||||||
];
|
];
|
||||||
|
|
||||||
return [[
|
return [[
|
||||||
@ -86,7 +96,7 @@ class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
|
|||||||
'methodApi' => 'ordersCreate',
|
'methodApi' => 'ordersCreate',
|
||||||
'expected' => [
|
'expected' => [
|
||||||
'number' => $arFields['NUMBER'],
|
'number' => $arFields['NUMBER'],
|
||||||
'externalId' => $arFields['ID'],
|
'externalId' => (string) $arFields['ID'],
|
||||||
'createdAt' => $arFields['DATE_INSERT'],
|
'createdAt' => $arFields['DATE_INSERT'],
|
||||||
'customer' => ['externalId' => $arFields['USER_ID']],
|
'customer' => ['externalId' => $arFields['USER_ID']],
|
||||||
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
|
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
|
||||||
@ -95,14 +105,17 @@ class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
|
|||||||
'managerComment' => $arFields['COMMENTS'],
|
'managerComment' => $arFields['COMMENTS'],
|
||||||
'delivery' => [
|
'delivery' => [
|
||||||
'cost' => $arFields['PRICE_DELIVERY'],
|
'cost' => $arFields['PRICE_DELIVERY'],
|
||||||
'code' => $arFields['DELIVERYS'][0]['service'],
|
'code' => $arFields['DELIVERYS'][0]['id'],
|
||||||
|
'service' => ['code' => $arFields['DELIVERYS'][0]['service']]
|
||||||
],
|
],
|
||||||
'contragent' => [
|
'contragent' => [
|
||||||
'contragentType' => $arParams['optionsContragentType'][$arFields['PERSON_TYPE_ID']]
|
'contragentType' => $arParams['optionsContragentType'][$arFields['PERSON_TYPE_ID']]
|
||||||
],
|
],
|
||||||
'payments' => [[
|
'payments' => [[
|
||||||
'type' => $arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]['PAY_SYSTEM_ID']],
|
'type' => $arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]['PAY_SYSTEM_ID']],
|
||||||
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID'])
|
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID']),
|
||||||
|
'status' => 'paid',
|
||||||
|
'paidAt' => $this->getDateTime()->format('Y-m-d H:i:s')
|
||||||
]]
|
]]
|
||||||
],
|
],
|
||||||
]];
|
]];
|
Loading…
Reference in New Issue
Block a user