• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/ui/barcode/payment.php
  • Класс: Bitrix\Crm\UI\Barcode\Payment
  • Вызов: Payment::saveToTemporaryFile
public function saveToTemporaryFile(int $hoursToKeep = 1): ?string
{
	if ($this->isSavedTemporary())
	{
		throw new InvalidOperationException('This payment barcode is already saved');
	}

	if (!$this->validate()->isSuccess())
	{
		return null;
	}

	$tmpDirName = \CTempFile::GetDirectoryName($hoursToKeep, static::TMP_DIR_NAME);

	// maybe you should the file change extension if you change barcode format
	/** @see Barcode::format() */
	$tmpFileName = Path::combine($tmpDirName, Random::getString(5) . '.png');
	if (!Path::validate($tmpFileName))
	{
		return null;
	}

	$tmpFile = new File($tmpFileName);

	$writeResult = $tmpFile->putContents($this->render());
	if ($writeResult === false)
	{
		return null;
	}

	$this->pathToTmpFile = $tmpFile->getPath();

	return $this->pathToTmpFile;
}