1
0
mirror of synced 2024-11-28 08:16:07 +03:00

Remove date for integration payment (#214)

This commit is contained in:
Сергей Чазов 2021-09-08 13:00:50 +03:00 committed by GitHub
parent 9354bca0b3
commit d06cb3c6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 107 additions and 45 deletions

View File

@ -7,7 +7,6 @@ log_errors = On
display_startup_errors = On
cgi.fix_pathinfo = 0
date.timezone = "Europe/Moscow"
mbstring.func_overload = 2
mbstring.internal_encoding = "UTF-8"
default_charset = utf-8
max_input_vars = 10000

3
.gitignore vendored
View File

@ -12,4 +12,5 @@
/vendor/
.env
.phpunit.result.cache
/release/
/release/
coverage.xml

View File

@ -1,5 +1,6 @@
<?php
use Bitrix\Main\Context\Culture;
use Intaro\RetailCrm\Service\ManagerService;
use Bitrix\Sale\Payment;
use RetailCrm\ApiClient;
@ -496,17 +497,20 @@ class RetailCrmEvent
if (!empty($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'])) {
$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);
} elseif (is_string($arPayment['DATE_PAID'])) {
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID'];
}
}
if (!empty($optionsPayStatuses[$arPayment['PAID']])) {
if (!empty($optionsPayStatuses[$arPayment['PAID']]) && !$isIntegrationPayment) {
$paymentToCrm['status'] = $optionsPayStatuses[$arPayment['PAID']];
}

View File

@ -274,11 +274,12 @@ class RetailCrmOrder
$order['weight'] = $weight;
}
$integrationPayment = RetailcrmConfigProvider::getIntegrationPaymentTypes();
//payments
$payments = [];
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']])) {
$pm = [
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]
@ -288,14 +289,11 @@ class RetailCrmOrder
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
}
if (!empty($payment['DATE_PAID'])) {
if (!empty($payment['DATE_PAID']) && !$isIntegrationPayment) {
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
}
if (
!empty($arParams['optionsPayment'][$payment['PAID']])
&& !in_array($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']], $integrationPayment)
) {
if (!empty($arParams['optionsPayment'][$payment['PAID']]) && !$isIntegrationPayment) {
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
}

View File

@ -110,4 +110,17 @@ class RetailCrmService
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
);
}
}

View File

@ -33,4 +33,37 @@ class BitrixTestCase extends \PHPUnit\Framework\TestCase
// без этого вызова Mockery не будет работать
\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'));
}
}

View File

@ -38,3 +38,4 @@ VALUES ('2020-05-08 19:04:03', 'iblock', '500', '500', '23791', 'image/jpeg', 'i
$DB->Query($strSql);
require_once 'BitrixTestCase.php';

View File

@ -3,7 +3,8 @@
/**
* Class RetailCrmOrder_v5Test
*/
class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
class RetailCrmOrder_v5Test extends BitrixTestCase {
/**
* setUp method
*/
@ -13,12 +14,6 @@ class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
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');
}
/**
@ -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[]
*/
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
]]
];
$arFields = $this->getArFields();
$this->initSystemData();
$arParams = [
'optionsOrderTypes' => RetailcrmConfigProvider::getOrderTypes(),
'optionsPayStatuses' => RetailcrmConfigProvider::getPaymentStatuses(),
'optionsContragentType' => RetailcrmConfigProvider::getContragentTypes(),
'optionsDelivTypes' => RetailcrmConfigProvider::getDeliveryTypes(),
'optionsPayTypes' => RetailcrmConfigProvider::getPaymentTypes(),
'optionsPayment' => []
'optionsPayment' => ['Y' => 'paid']
];
return [[
@ -86,7 +96,7 @@ class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
'methodApi' => 'ordersCreate',
'expected' => [
'number' => $arFields['NUMBER'],
'externalId' => $arFields['ID'],
'externalId' => (string) $arFields['ID'],
'createdAt' => $arFields['DATE_INSERT'],
'customer' => ['externalId' => $arFields['USER_ID']],
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
@ -95,14 +105,17 @@ class RetailCrmOrder_v5Test extends \PHPUnit_Framework_TestCase {
'managerComment' => $arFields['COMMENTS'],
'delivery' => [
'cost' => $arFields['PRICE_DELIVERY'],
'code' => $arFields['DELIVERYS'][0]['service'],
'code' => $arFields['DELIVERYS'][0]['id'],
'service' => ['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'])
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID']),
'status' => 'paid',
'paidAt' => $this->getDateTime()->format('Y-m-d H:i:s')
]]
],
]];