139 lines
5.3 KiB
PHP
139 lines
5.3 KiB
PHP
<?php
|
||
// spl_autoload_register(function ($class) {
|
||
include 'Pay/index.php';
|
||
|
||
class ClassPay
|
||
{
|
||
public $config;
|
||
private $array;
|
||
|
||
// public $Way = 'logs/';
|
||
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.'/payment.log',PHP_EOL.'Массив данных не был передан в конструктор', FILE_APPEND);
|
||
exit;
|
||
}
|
||
|
||
$this->array = $array;
|
||
|
||
if(empty($this->array['request_url']))
|
||
{
|
||
file_put_contents($this->WayLog.'/payment.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.'/payment.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"]?? null,
|
||
'merchant_id'=> $this->array['marketPlace']?? null,
|
||
'merchant_key'=> $this->array['secretKey']?? null,
|
||
'request_url'=> $this->array['request_url']?? null,
|
||
'success_url'=>$this->array['success_url']?? null,
|
||
'fail_url'=>$this->array['fail_url']?? null,
|
||
'amount'=>0,
|
||
'showOrderId' =>$this->array['showOrderId']?? null,
|
||
'details' => $this->array['details']?? null,
|
||
'paymentMethod'=>$this->array['paymentMethod']?? null,
|
||
'customerAccount'=>$this->array['customerAccount']?? null,
|
||
'customerComment'=>$this->array['customerComment']?? null,
|
||
'customerEmail'=> $this->array['customerEmail']?? null,
|
||
'customerPhone'=>$this->array['customerPhone']?? null,
|
||
'displayLanguage'=>$this->array['displayLanguage']?? null,
|
||
'recurrentable'=>$this->array['recurrentable']?? null,
|
||
'debug'=>$this->array['debug']?? null,
|
||
'hold' =>$this->array['hold']?? false,
|
||
];
|
||
|
||
// echo $Domain;
|
||
}
|
||
|
||
function CreatePayment($product = '')
|
||
{
|
||
if (!is_array($product))
|
||
{
|
||
file_put_contents($this->WayLog.'/payment.log',PHP_EOL.'Массив данных для чека не был передан', FILE_APPEND);
|
||
exit;
|
||
}
|
||
$paymentParams = new PaymentParams($this->config);
|
||
|
||
foreach ($product as $key1 => $productt)
|
||
{
|
||
foreach ($productt as $key2 => $value)
|
||
{
|
||
if($key2 == 0 || $key2 == 1)
|
||
{
|
||
file_put_contents($this->WayLog.'/payment.log',PHP_EOL.'В price либо amount передано значение с《,》необходимо указать не целочисленное значение через《.》', FILE_APPEND);
|
||
exit;
|
||
}
|
||
}
|
||
}
|
||
|
||
// print_r($product);
|
||
|
||
$count = count($product);
|
||
file_put_contents($this->WayLog.'/payment.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'.'/payment.log',PHP_EOL.'Не указаны или указаны не все составляющие для чека', FILE_APPEND);
|
||
}
|
||
}
|
||
|
||
$paymentParams->generateReceipt();
|
||
$html = $paymentParams->renderPaymentForm($paymentParams->getParams());
|
||
|
||
file_put_contents($this->WayEvents.'/CreatePayResult.json', PHP_EOL.$html, FILE_APPEND);
|
||
|
||
|
||
if ('logs'=== $this->WayLog)
|
||
{
|
||
$N = 1;
|
||
$N.= strlen($this->WayLog);
|
||
}
|
||
else
|
||
if ('logs'!== $this->WayLog)
|
||
{
|
||
$N = 0;
|
||
$N.= strlen($this->WayLog);
|
||
$N.= strlen('logs');
|
||
}
|
||
|
||
if(!empty($this->config['orderId']))
|
||
{
|
||
file_put_contents($this->WayLog.'/payment.log',PHP_EOL.'orderId: '.$this->config['orderId'].' Получена команда на запуск модуля ', FILE_APPEND);
|
||
}
|
||
if(empty($this->config['orderId']))
|
||
{
|
||
file_put_contents($this->WayLog.'/payment.log',PHP_EOL.'Получена команда на запуск модуля ', FILE_APPEND);
|
||
}
|
||
|
||
echo $html;
|
||
return $html;
|
||
}
|
||
}
|
||
|
||
?>
|