if ($payment['PAID'] !== 'Y' && $order['ORDER']['LOCK_CHANGE_PAYSYSTEM'] !== 'Y')
if (
is_array($this->arParams['RESTRICT_CHANGE_PAYSYSTEM'])
&& in_array($orderFields['STATUS_ID'], $this->arParams['RESTRICT_CHANGE_PAYSYSTEM'])
)
{
$orderFields['LOCK_CHANGE_PAYSYSTEM'] = 'Y';
}