WayLog = trim($_SESSION['log_way']); $this->WayEvents = trim($_SESSION['events_way']); if (!is_array($array)) { file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.'Массив данных не был передан в конструктор', FILE_APPEND); exit; } $this->array = $array; if(empty($this->array['request_url'])) { file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.'Нет адреса для запроса', FILE_APPEND); exit; } if((strpos($this->array['request_url'], 'https://oos-stage.pscb.ru/')===false)&&(strpos($this->array['request_url'], 'https://oos.pscb.ru/')===false)&&(strpos($this->array['request_url'], 'https://oosdemo.pscb.ru/')===false)) { file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.' Не Cоответствующий URL', FILE_APPEND); exit; } $parsed_url= parse_url($this->array['request_url']?? null); $this->config = [ 'domain' => $parsed_url['host'], 'orderId'=> $this->array["orderId"], 'marketPlace'=> $this->array['marketPlace'], 'secretKey'=> $this->array['secretKey'], 'amount'=> $this->array['amount']?? null, 'paymentMethod'=> "sbp", 'details'=> $this->array['details']?? null, 'customerEmail'=> $this->array['customerEmail']?? null, 'sbpRedirectUrl'=> $this->array['sbpRedirectUrl']?? null, 'requestQrCodeImage'=> false, 'requestQrCodeImageUrl'=> false, ]; } function CreatePayment($product = '') { if (!is_array($product)) { file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.'Массив данных для чека не был передан', FILE_APPEND); exit; } $paymentParams = new CreatingAndTransmittingParametersForInvoicing($this->config); foreach ($product as $key1 => $productt) { foreach ($productt as $key2 => $value) { if($key2 == 0 || $key2 == 1) { file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.'В price либо amount передано значение с《,》необходимо указать не целочисленное значение через《.》', FILE_APPEND); exit; } } } $count = count($product); file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.'orderId: '.$this->config['orderId'].' Позиций в чеке: '.$count, FILE_APPEND); foreach($product as $prod) { if((!empty($prod["object"]))&&(!empty($prod["quantity"]))&&(!empty($prod["price"]))&&(!empty($prod["amount"]))) { $paymentParams->addItemToReceipt($prod["object"],$prod["quantity"], $prod["price"], $prod["amount"]); } else if((empty($prod["object"]))||(empty($prod["quantity"]))||(empty($prod["price"]))||(empty($prod["amount"]))) { file_put_contents('logs'.'/Invoicing.log',PHP_EOL.'Не указаны или указаны не все составляющие для чека', FILE_APPEND); } } $res = $paymentParams->processPayment2(); file_put_contents($this->WayEvents.'/CreateInvoicing.json', PHP_EOL.$res); $res = json_decode($res); $url = $res->payment->qrCodePayload; if(!empty($url)) { header("Location: $url"); echo($url); exit; } foreach($res as $Part_res =>$Value_Part_res) { if($Part_res == 'errorDescription'&&!empty($Value_Part_res)) { file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.'orderId: '.$this->config['orderId'].' '.$Value_Part_res, FILE_APPEND); } if($Part_res == 'errorDescription') { file_put_contents($this->WayLog.'/Invoicing.log',PHP_EOL.'orderId: '.$this->config['orderId'].' Есть ошибка в переданных параметрах или повторный OrderID '.$Value_Part_res, FILE_APPEND); } } return $res; if(!empty($this->config['orderId'])) { file_put_contents($this->WayLog.'/Invoicing.log', PHP_EOL.$this->config['orderId'].' Получена команда на запуск модуля', FILE_APPEND); } if(empty($this->config['orderId'])) { file_put_contents($this->WayLog.'/Invoicing.log', PHP_EOL.'Получена команда на запуск модуля', FILE_APPEND); } } } ?>