pscbonline-php/Src/PayConfirmClass/ConfirmClass.php

123 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// spl_autoload_register(function ($class) {
include 'Confirm/index.php'; // Предполагается, что каждый класс находится в отдельном файле
// });
class ClassConfirm
{
public $config;
private $array;
public $WayLog;
public $WayEvents;
public $Domain;
public function __construct($array = '')
{
session_start();
$this->WayLog = trim($_SESSION['log_way']);
$this->WayEvents = trim($_SESSION['events_way']);
if (!is_array($array)) {
file_put_contents($this->WayLog.'/confirmation.log',PHP_EOL.'Массив данных не был передан в конструктор', FILE_APPEND);
exit;
}
$this->array = $array;
if(empty($this->array['request_url']))
{
file_put_contents($this->WayLog.'/confirmation.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.'/confirmation.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'],
// 'confirmAmount' => $this->array['confirmAmount'],
];
}
function CreatePayment($product = '')
{
if (!is_array($product)) {
file_put_contents($this->WayLog.'/confirmation.log',PHP_EOL.'Массив данных чека не был передан', FILE_APPEND);
exit;
}
$paymentParams = new CreatingAndTransmittingParametersForConfirm($this->config);
foreach ($product as $key1 => $productt)
{
foreach ($productt as $key2 => $value)
{
if($key2 == 0 || $key2 == 1)
{
file_put_contents($this->WayLog.'/confirmation.log',PHP_EOL.'В price либо amount передано значение с《,》необходимо указать не целочисленное значение через《.》', FILE_APPEND);
exit;
}
}
}
$count = count($product);
file_put_contents($this->WayLog.'/confirmation.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'.'/confirmation.log',PHP_EOL.'Не указаны или указаны не все составляющие для чека', FILE_APPEND);
}
}
$res = $paymentParams->processPayment($this->config);
file_put_contents($this->WayEvents.'/ConfirmPayment.json', PHP_EOL.$res);
$res =json_decode($res);
foreach($res as $Part_res =>$Value_Part_res)
{
if($Part_res == 'errorDescription'&&!empty($Value_Part_res))
{
file_put_contents($this->WayLog.'/confirmation.log',PHP_EOL.'orderId: '.$this->config['orderId'].' '.$Value_Part_res, FILE_APPEND);
}
if($Part_res == 'errorDescription')
{
file_put_contents($this->WayLog.'/confirmation.log',PHP_EOL.'orderId: '.$this->config['orderId'].' Есть ошибка в переданных параметрах или повторный OrderID '.$Value_Part_res, FILE_APPEND);
}
}
if(!empty($this->config['orderId']))
{
file_put_contents($this->WayLog.'/confirmation.log',PHP_EOL.'orderId: '.$this->config['orderId'].' Получена команда на запуск модуля', FILE_APPEND);
}
if(empty($this->config['orderId']))
{
file_put_contents($this->WayLog.'/confirmation.log',PHP_EOL.'Получена команда на запуск модуля', FILE_APPEND);
}
// var_dump($res);
return $res;
}
}
?>