Исключить рабочие данные и служебные файлы из Git
This commit is contained in:
1 parent
ee12c548ca
commit
e563497a9f
17030 files changed
+80
-30487
No files matched your search
@@ -1,694 +0,0 @@
|
||||
<?php
|
||||
namespace App\Controller\Manager;
|
||||
use App\Controller\ElplatMerchantAPI;
|
||||
use App\Controller\CloudPaymentsMerchantAPI;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Event\Event;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use App\Controller\AppController;
|
||||
use SMSRU;
|
||||
|
||||
class OrderPaymentController extends AppController {
|
||||
|
||||
public function beforeFilter(Event $event) {
|
||||
parent::beforeFilter($event);
|
||||
$this->viewBuilder()->setLayout('manager');
|
||||
|
||||
$this->set('isAuthorized', $this->isAuthorized([], ["orderPayment"]));
|
||||
}
|
||||
|
||||
public function beforeRender(Event $event) {
|
||||
}
|
||||
|
||||
private function searchOrderPaymentOrders($result, $data) {
|
||||
/*$orderPaymentTable = TableRegistry::getTableLocator()->get("OrderPayment");
|
||||
$ordersList = $orderPaymentTable->find('all')->all();
|
||||
foreach($ordersList as $key => $order) {
|
||||
$order['data'] = json_decode($order['data'], true);
|
||||
|
||||
if (!empty($order['data']['telephone'])) {
|
||||
$order->telephone = cleanupPhone($order['data']['telephone']);
|
||||
|
||||
if (strlen($order->telephone) == 10) {
|
||||
$order->telephone = "7" . $order->telephone;
|
||||
}
|
||||
|
||||
//$order->telephone = formatPhone($order->telephone);
|
||||
} else {
|
||||
$order->telephone = '';
|
||||
}
|
||||
unset($order['data']);
|
||||
|
||||
$order->name = trim($order->name);
|
||||
|
||||
if (!empty($order->payment)) {
|
||||
$order->payment = json_decode($order->payment, true);
|
||||
$order->paid_date = $order->payment[count($order->payment) - 1]['DateTime'];
|
||||
unset($order->payment);
|
||||
}
|
||||
|
||||
$orderPaymentTable->save($order);
|
||||
}*/
|
||||
|
||||
$search = preg_replace("/%{2,}/", "%", "%" . preg_replace("/[^\w\d]/ui", "%" , $data['search']) . "%");
|
||||
$status = (!empty($data['paymentStatus']) ? trim($data['paymentStatus']) : null);
|
||||
$searchPhone = "%".cleanupPhone(trim($data['search']))."%";
|
||||
$paymentGateway = (!empty($data['paymentGateway']) ? trim($data['paymentGateway']) : null);
|
||||
|
||||
$conditions = [];
|
||||
if (!empty($search)) {
|
||||
$searchSum = trim(str_replace(["р.", "р", "₽", " "], "", mb_strtolower($data['search'])));
|
||||
|
||||
$conditions[] = ['OR' => [
|
||||
'order_num LIKE' => $search,
|
||||
'name LIKE' => $search,
|
||||
'telephone LIKE' => $searchPhone,
|
||||
'summa_order_decimal' => $searchSum
|
||||
]];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($data['dateFrom'])) {
|
||||
if (is_string($data['dateFrom'])) {
|
||||
$data['dateFrom'] = strtotime($data['dateFrom']);
|
||||
} else {
|
||||
$data['dateFrom'] = $data['dateFrom'] / 1000;
|
||||
}
|
||||
$conditions[] = ['expiry_date >=' => $this->patchTimestampForJS(date('Y-m-d 00:00:00', $data['dateFrom']), -24, true, 'Y-m-d H:i:s')];
|
||||
}
|
||||
|
||||
if (!empty($data['dateTo'])) {
|
||||
if (is_string($data['dateTo'])) {
|
||||
$data['dateTo'] = strtotime($data['dateTo']);
|
||||
} else {
|
||||
$data['dateTo'] = $data['dateTo'] / 1000;
|
||||
}
|
||||
$conditions[] = ['expiry_date <=' => $this->patchTimestampForJS(date('Y-m-d 23:59:59', $data['dateTo']), -24, true, 'Y-m-d H:i:s')];
|
||||
}
|
||||
|
||||
if (!empty($status)) {
|
||||
if ($status == 'Оплачен') {
|
||||
$conditions[] = ['payment is not null'];
|
||||
}
|
||||
|
||||
if ($status == 'Не оплачен') {
|
||||
$conditions[] = ['payment is null'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($paymentGateway)) {
|
||||
$conditions[] = ['paymentGateway' => $paymentGateway];
|
||||
}
|
||||
|
||||
$result['totalOrders'] = 0;
|
||||
$conditions = array_merge($conditions, ['isDeleted' => false]);
|
||||
|
||||
$currentPage = (!empty($data['currentPage']) ? (int)$data['currentPage']: 1);
|
||||
$numPerPage = (!empty($data['numPerPage']) ? (int)$data['numPerPage']: 25);
|
||||
|
||||
$sort = [
|
||||
'field' => 'expiry_date',
|
||||
'direction' => 'desc'
|
||||
];
|
||||
|
||||
if (!empty($data['sortFields'])) {
|
||||
switch($data['sortFields']['field']) {
|
||||
case 'order_num':
|
||||
case 'name':
|
||||
case 'summa_order_decimal':
|
||||
case 'telephone':
|
||||
case 'expiry_date':
|
||||
case 'paymentGateway':
|
||||
$sort['field'] = $data['sortFields']['field'];
|
||||
break;
|
||||
|
||||
|
||||
case 'statusJs':
|
||||
$sort['field'] = 'paid_date';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array($data['sortFields']['direction'], ['asc', 'desc'])) {
|
||||
$sort['direction'] = 'desc';
|
||||
} else {
|
||||
$sort['direction'] = $data['sortFields']['direction'];
|
||||
}
|
||||
|
||||
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get("OrderPayment");
|
||||
$ordersList = $orderPaymentTable->find('all')->where($conditions)
|
||||
->order([$sort['field'] => $sort['direction']])->page($currentPage, $numPerPage)->all();
|
||||
|
||||
if (!empty($ordersList)) {
|
||||
$ordersList = $ordersList->toArray();
|
||||
foreach($ordersList as $key => $order) {
|
||||
$order['data'] = json_decode($order['data'], true);
|
||||
$ordersList[$key]['expiry_date'] = date_timestamp_get($this->patchTimestampForJS($order['expiry_date'], 24, false)) * 1000;
|
||||
|
||||
$ordersList[$key]['summa_order_decimal'] = $order['summa_order_decimal'];
|
||||
$ordersList[$key]['summa_order'] = $order['data']['summa_order'];
|
||||
$ordersList[$key]['name'] = $order['name'];
|
||||
|
||||
if (!empty($order['telephone'])) {
|
||||
$ordersList[$key]['telephoneOriginal'] = $order['data']['telephone'];
|
||||
$order['telephone'] = formatPhone($order['telephone']);
|
||||
}
|
||||
|
||||
unset($ordersList[$key]['data']);
|
||||
|
||||
if (!empty($order['paid_date'])) {
|
||||
$ordersList[$key]['status'] = 'Оплачен';
|
||||
//$ordersList[$key]['paidDate'] = $this->patchTimestampForJS($order['payment'][count($order['payment']) - 1]['DateTime'], -3, true, 'd.m.Y H:i');
|
||||
$ordersList[$key]['paidDate'] = $this->patchTimestampForJS($order['paid_date'], -3, true, 'd.m.Y H:i');
|
||||
$ordersList[$key]['statusJs'] = $this->patchTimestampForJS($order['paid_date'], -3, true, 'U');;
|
||||
unset($ordersList[$key]['payment']);
|
||||
|
||||
} else {
|
||||
$ordersList[$key]['status'] = 'Не оплачен';
|
||||
$ordersList[$key]['statusJs'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$result['totalOrders'] = $orderPaymentTable->find('all')->where($conditions)->count();
|
||||
|
||||
$result['unpaidCount'] = $orderPaymentTable->find('all')->where(array_merge($conditions, [
|
||||
'OR' => [
|
||||
['payment is null'],
|
||||
['payment is not null', 'summa_order_decimal_paid' => 0]
|
||||
]
|
||||
]))->count();
|
||||
$result['unpaidTotal'] = str_replace(".00", "", toFixed2Price($orderPaymentTable->find('all')->where(array_merge($conditions, [
|
||||
'OR' => [
|
||||
['payment is null'],
|
||||
['payment is not null', 'summa_order_decimal_paid' => 0]
|
||||
]
|
||||
]))->sumOf('summa_order_decimal')));
|
||||
|
||||
$result['paidCount'] = $orderPaymentTable->find('all')->where(array_merge($conditions, [
|
||||
'payment is not null',
|
||||
'summa_order_decimal_paid > ' => 0
|
||||
]))->count();
|
||||
$result['paidTotal'] = str_replace(".00", "", toFixed2Price($orderPaymentTable->find('all')->where(array_merge($conditions, [
|
||||
'payment is not null',
|
||||
'summa_order_decimal_paid >' => 0
|
||||
]))->sumOf('summa_order_decimal_paid')));
|
||||
}
|
||||
|
||||
$result['ordersList'] = (!empty($ordersList) ? $ordersList : []);
|
||||
|
||||
$result['status'] = "success";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$jsConfig = $this->getAppJsConfig("orderPayment", true);
|
||||
|
||||
$data = $this->request->getData();
|
||||
if (!empty($data['action'])) {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'errors' => []
|
||||
];
|
||||
|
||||
switch($data['action']) {
|
||||
case "searchOrders":
|
||||
$result = $this->searchOrderPaymentOrders($result, $data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
} else {
|
||||
$this->set('jsConfig', $jsConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function adminDeleteOrder() {
|
||||
/*$orderPaymentTable = TableRegistry::getTableLocator()->get("OrderPayment");
|
||||
$ordersList = $orderPaymentTable->find('all')->where(['payment is not null'])->select([
|
||||
'id','payment'
|
||||
])->all();
|
||||
foreach($ordersList as $order) {
|
||||
$order->summa_order_decimal_paid = 0;
|
||||
$order['payment'] = json_decode($order['payment'], true);
|
||||
|
||||
foreach($order['payment'] as $payment) {
|
||||
$order->summa_order_decimal_paid += $payment['Amount'];
|
||||
|
||||
unset($order['payment']);
|
||||
$orderPaymentTable->save($order);
|
||||
}
|
||||
}*/
|
||||
|
||||
$result = [
|
||||
'status' => 'success'
|
||||
];
|
||||
|
||||
if ($this->isAuthorized(['admin'])) {
|
||||
$data = $this->request->getData();
|
||||
if (!empty($data['id'])) {
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get("OrderPayment");
|
||||
$order = $orderPaymentTable->find()->where(['id' => $data['id']])->first();
|
||||
|
||||
if (!empty($order)) {
|
||||
$order->isDeleted = true;
|
||||
$orderPaymentTable->save($order);
|
||||
|
||||
$result = $this->searchOrderPaymentOrders($result, $data);
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'error' => 'Недостаточно прав для удаления данного счета'
|
||||
];
|
||||
}
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
function getElplatPaymentHistory() {
|
||||
$result = [
|
||||
'status' => 'success'
|
||||
];
|
||||
|
||||
if ($this->isAuthorized(['admin', 'kassir'])) {
|
||||
$data = $this->request->getData();
|
||||
if (!empty($data['id'])) {
|
||||
$elplatPaymentsTable = TableRegistry::getTableLocator()->get('ElplatPayments');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $data['id'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
if (!empty($savedOrderData)) {
|
||||
$history = $elplatPaymentsTable->find()->where([
|
||||
'orderPaymentId' => $data['id'],
|
||||
'status IN' => ["success", "refund", "failure"]
|
||||
])->order(['id' => 'asc'])->all()->toArray();
|
||||
|
||||
if (!empty($history)) {
|
||||
$usersTable = TableRegistry::getTableLocator()->get('Users');
|
||||
|
||||
$result['history'] = [];
|
||||
foreach($history as $li) {
|
||||
$tmp = [
|
||||
'date' => $this->patchTimestampForJS($li['updated'], 0, true, 'd.m.Y H:i'),
|
||||
];
|
||||
|
||||
$li['responseData'] = @json_decode($li['responseData'], true);
|
||||
switch($li['status']) {
|
||||
case 'success':
|
||||
$tmp['description'] = 'Оплата счета ' . $savedOrderData['order_num'];
|
||||
$tmp['amount'] = str_replace(".00", "", toFixed2Price($li['responseData']['allAmount'] / 100)).'р.';
|
||||
break;
|
||||
|
||||
case 'failure':
|
||||
$tmp['description'] = 'Ошибка оплаты счета ' . $savedOrderData['order_num'];
|
||||
$tmp['amount'] = '';
|
||||
break;
|
||||
|
||||
case 'refund':
|
||||
$tmp['description'] = $li['responseData']['refundDescription'];
|
||||
$tmp['amount'] = str_replace(".00", "", toFixed2Price($li['responseData']['refundAmount'])).'р.';
|
||||
|
||||
if (!empty($li['responseData']['refundManagerId'])) {
|
||||
$refundManager = $usersTable->find()->where([
|
||||
'id' => $li['responseData']['refundManagerId']
|
||||
])->first();
|
||||
|
||||
if (!empty($refundManager)) {
|
||||
$tmp['refundManager'] = $refundManager->name;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$result['history'][] = $tmp;
|
||||
}
|
||||
|
||||
$result['refundAmount'] = $savedOrderData['summa_order_decimal_paid'];
|
||||
$result['refundDescription'] = "Возрат средств по счету ".$savedOrderData['order_num']." - ".str_replace(".00", "", toFixed2Price($savedOrderData['summa_order_decimal_paid']))."р.";
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'error' => 'Недостаточно прав для возврата средств по данному счету'
|
||||
];
|
||||
}
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
public function makeElplatRefund() {
|
||||
$result = [
|
||||
'status' => 'error'
|
||||
];
|
||||
|
||||
if ($this->isAuthorized(['admin', 'kassir'])) {
|
||||
$data = $this->request->getData();
|
||||
if (!empty($data['id'])) {
|
||||
$elplatPaymentsTable = TableRegistry::getTableLocator()->get('ElplatPayments');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $data['id'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
|
||||
if (!empty($savedOrderData)) {
|
||||
$orderPayment = $elplatPaymentsTable->find()->where([
|
||||
'orderPaymentId' => $data['id'],
|
||||
'qrcId is not null',
|
||||
"qrcId != ''",
|
||||
'status' => 'success'
|
||||
])->first();
|
||||
|
||||
if (!empty($orderPayment) && !empty($orderPayment->responseData)) {
|
||||
$orderPayment->responseData = @json_decode($orderPayment->responseData, true);
|
||||
|
||||
$elplatCredentials = Configure::read('elplat');
|
||||
$elplatCredentials = $elplatCredentials[$savedOrderData['domain']];
|
||||
|
||||
$elplat = new ElplatMerchantAPI();
|
||||
|
||||
$refundData = [
|
||||
'login' => $elplatCredentials['login'],
|
||||
"passwd" => $elplatCredentials['passwd'],
|
||||
"ebl27" => $orderPayment->responseData['ebl27'],
|
||||
"amount" => round($data['refundAmount'] * 100),
|
||||
"orgId" => $elplatCredentials['orgId'],
|
||||
"descr" => $data['refundDescription'],
|
||||
];
|
||||
|
||||
|
||||
$hashId = $elplat->getElplatHashId($refundData);
|
||||
unset($refundData['passwd']);
|
||||
|
||||
$request = $elplat->createQr($elplatCredentials['apiUrl'], array_merge($refundData, [
|
||||
"type" => "undone",
|
||||
'hashId' => $hashId,
|
||||
'vTerminal' => $elplatCredentials['login']
|
||||
]));
|
||||
|
||||
if (!empty($request['info']['status'])) {
|
||||
$request['info']['refundDescription'] = $data['refundDescription'];
|
||||
$request['info']['refundAmount'] = $data['refundAmount'];
|
||||
$request['info']['refundManagerId'] = $this->Auth->user('id');
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$elplatRefund = $elplatPaymentsTable->newEntity([
|
||||
'orderPaymentId' => $data['id'],
|
||||
'qrData' => '',
|
||||
'qrcId' => '',
|
||||
'responseData' => json_encode($request['info']),
|
||||
'status' => 'refund',
|
||||
'created' => $now,
|
||||
'updated' => $now,
|
||||
]);
|
||||
|
||||
$elplatPaymentsTable->save($elplatRefund);
|
||||
|
||||
$ftpParams = Configure::read("ftpParams");
|
||||
$ftpConnectionId = ftp_connect($ftpParams['ip'], (!empty($ftpParams['port']) ? $ftpParams['port'] : 21), 5);
|
||||
|
||||
if (!empty($ftpConnectionId)) {
|
||||
$ftpLoginResult = ftp_login($ftpConnectionId, $ftpParams['username'], $ftpParams['password']);
|
||||
ftp_pasv($ftpConnectionId, true);
|
||||
|
||||
if ($ftpLoginResult) {
|
||||
$ftpTargetDir = "";
|
||||
switch ($savedOrderData['domain']) {
|
||||
case "apps.supersam24.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiring24Out'];
|
||||
break;
|
||||
|
||||
case "apps.supersamsev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringOut'];
|
||||
break;
|
||||
|
||||
case "apps.prometeysev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringPrometeyOut'];
|
||||
break;
|
||||
}
|
||||
|
||||
ftp_chdir($ftpConnectionId, $ftpTargetDir);
|
||||
|
||||
$tmpOrder = $orderPaymentTable->get($data['id']);
|
||||
$tmpOrder->summa_order_decimal_paid -= $data['refundAmount'];
|
||||
|
||||
$xml = '<?xml version="1.0" encoding="windows-1251"?><orders><invoice_no>' . $savedOrderData['order_num'] . '</invoice_no>';
|
||||
$xml .= '<time>' . date('Y-m-d H:i:s') . '</time><paid>refund</paid><paid_summa>' . $data['refundAmount'] . '</paid_summa><gateway>СБП</gateway>';
|
||||
$xml .= '</orders>';
|
||||
$xml = mb_convert_encoding(str_replace("\n", "", $xml), "Windows-1251", "UTF-8");
|
||||
|
||||
$tmpFile = tmpfile();
|
||||
fwrite($tmpFile, $xml);
|
||||
rewind($tmpFile);
|
||||
|
||||
$filename = 'acquiring_in_' . date('Y-m-d_H-i-s') . '_' . bin2hex(random_bytes(4)) . '.xml';
|
||||
if (ftp_fput($ftpConnectionId, $filename, $tmpFile, FTP_BINARY, 0)) {
|
||||
if (empty($tmpOrder->summa_order_decimal_paid)) {
|
||||
$tmpOrder->payment = null;
|
||||
$tmpOrder->paid_date = null;
|
||||
}
|
||||
|
||||
/*if (empty($tmpOrder->files)) {
|
||||
$tmpOrder->files = [];
|
||||
} else {
|
||||
$tmpOrder->files = json_decode($tmpOrder->files, true);
|
||||
}
|
||||
|
||||
if (empty($tmpOrder->files["refund"])) {
|
||||
$tmpOrder->files["refund"] = [];
|
||||
}
|
||||
$tmpOrder->files["refund"][] = [
|
||||
"date" => date('d.m.Y H:i'),
|
||||
"filename" => $filename,
|
||||
"xml" => $xml
|
||||
];
|
||||
|
||||
$tmpOrder->files = json_encode($tmpOrder->files);*/
|
||||
|
||||
$orderPaymentTable->save($tmpOrder);
|
||||
$result['status'] = 'success';
|
||||
};
|
||||
fclose($tmpFile);
|
||||
|
||||
file_put_contents(TMP . $filename, $xml);
|
||||
TableRegistry::getTableLocator()->get('CutSheets')->putImportFileToArchive(TMP . $filename, false, $filename);
|
||||
|
||||
|
||||
}
|
||||
|
||||
ftp_close($ftpConnectionId);
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => $request['info']['descr']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'error' => 'Недостаточно прав для возврата средств по данному счету'
|
||||
];
|
||||
}
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
|
||||
function getCloudPaymentsPaymentHistory() {
|
||||
$result = [
|
||||
'status' => 'success'
|
||||
];
|
||||
|
||||
if ($this->isAuthorized(['admin', 'kassir'])) {
|
||||
$data = $this->request->getData();
|
||||
if (!empty($data['id'])) {
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $data['id'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
if (!empty($savedOrderData)) {
|
||||
$history = json_decode($savedOrderData->payment, true);
|
||||
|
||||
if (!empty($history)) {
|
||||
$usersTable = TableRegistry::getTableLocator()->get('Users');
|
||||
|
||||
$result['history'] = [];
|
||||
foreach($history as $li) {
|
||||
$tmp = [
|
||||
//'date' => $this->patchTimestampForJS($li['updated'], 0, true, 'd.m.Y H:i'),
|
||||
'date' => $this->patchTimestampForJS($li['DateTime'], -3, true, 'd.m.Y H:i')
|
||||
];
|
||||
|
||||
$li['responseData'] = @json_decode($li['responseData'], true);
|
||||
switch($li['OperationType']) {
|
||||
case 'Payment':
|
||||
$tmp['description'] = 'Оплата счета ' . $savedOrderData['order_num'];
|
||||
$tmp['amount'] = str_replace(".00", "", toFixed2Price($li['Amount'])).'р.';
|
||||
break;
|
||||
|
||||
case 'Refund':
|
||||
$tmp['description'] = 'Возврат средств по счету ' . $savedOrderData['order_num'];
|
||||
$tmp['amount'] = str_replace(".00", "", toFixed2Price($li['Amount'])).'р.';
|
||||
//refundAmount add to response data
|
||||
|
||||
if (!is_array($li['Data'])) {
|
||||
$li['Data'] = @json_decode($li['Data'], true);
|
||||
}
|
||||
|
||||
if (!empty($li['Data']['refundManagerId'])) {
|
||||
$refundManager = $usersTable->find()->where([
|
||||
'id' => $li['Data']['refundManagerId']
|
||||
])->first();
|
||||
|
||||
if (!empty($refundManager)) {
|
||||
$tmp['refundManager'] = $refundManager->name;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$result['history'][] = $tmp;
|
||||
}
|
||||
|
||||
$result['refundAmount'] = $savedOrderData['summa_order_decimal_paid'];
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'error' => 'Недостаточно прав для возврата средств по данному счету'
|
||||
];
|
||||
}
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
public function makeCloudPaymentsRefund() {
|
||||
$result = [
|
||||
'status' => 'error'
|
||||
];
|
||||
|
||||
|
||||
if ($this->isAuthorized(['admin', 'kassir'])) {
|
||||
$data = $this->request->getData();
|
||||
if (!empty($data['id'])) {
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $data['id'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
|
||||
if (!empty($savedOrderData)) {
|
||||
$cloudPaymentsCredentials = Configure::read('cloudPayments');
|
||||
$cloudPaymentsCredentials = $cloudPaymentsCredentials[$savedOrderData['domain']];
|
||||
|
||||
$cloudPayments = new CloudPaymentsMerchantAPI();
|
||||
|
||||
$paymentTransactionId = null;
|
||||
$savedOrderData->payment = json_decode($savedOrderData->payment, true);
|
||||
foreach ($savedOrderData->payment as $payment) {
|
||||
if ($payment["OperationType"] == "Payment") {
|
||||
$paymentTransactionId = $payment['TransactionId'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($paymentTransactionId)) {
|
||||
$refundData = [
|
||||
'paymentPublicId' => $cloudPaymentsCredentials['paymentPublicId'],
|
||||
"apiKey" => $cloudPaymentsCredentials['apiKey'],
|
||||
|
||||
"TransactionId" => $paymentTransactionId,
|
||||
"Amount" => $data['refundAmount'],
|
||||
'requestLocation' => 'payments/refund',
|
||||
'JsonData' => [
|
||||
'encOrderId' => $savedOrderData['encryptOrderId'],
|
||||
'refundManagerId' => $this->Auth->user('id'),
|
||||
]
|
||||
];
|
||||
|
||||
$request = $cloudPayments->createRefund($cloudPaymentsCredentials['apiUrl'], $refundData);
|
||||
|
||||
if (!empty($request["Success"])) {
|
||||
$result['status'] = 'success';
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => (!empty($request['Message']) ? $request['Message'] : "Произошла ошибка при возврате средств. Проверьте данные и попробуйте снова.")
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'warning' => 'Счет не найден'
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'error' => 'Недостаточно прав для возврата средств по данному счету'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->db->query("INSERT INTO `" . DB_PREFIX . "elplat_payments` SET order_id = '" . $orderId . "', qrData = '', qrcId = '', responseData = '" . $this->db->escape(json_encode($refundInfo)) . "', status = 'refund', created = NOW(), updated = NOW()");
|
||||
@@ -1,803 +0,0 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use Cake\Core\Configure;use Cake\Event\Event;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\Routing\Router;
|
||||
|
||||
class OrderPaymentController extends AppController {
|
||||
public function beforeFilter(Event $event)
|
||||
{
|
||||
parent::beforeFilter($event);
|
||||
$this->Auth->allow(['display', 'getPaymentStatus', 'callbackPay', 'callbackRefund', 'createElplatPaymentQr', 'callbackElplat', 'getElpatPaymentStatus']);
|
||||
$this->viewBuilder()->setLayout('order_payment');
|
||||
}
|
||||
|
||||
public function display($encOrderId = null) {
|
||||
if(!empty($encOrderId)) {
|
||||
$ordersTable = TableRegistry::getTableLocator()->get('CutOrders');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
$decryptedData = $ordersTable->decryptCustomData($encOrderId, $this->config);
|
||||
|
||||
if (!empty($decryptedData['orderId'])) {
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $decryptedData['orderId'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
|
||||
if (!empty($savedOrderData)) {
|
||||
$savedOrderData['data'] = json_decode($savedOrderData['data'], true);
|
||||
$appsDomain = $savedOrderData['domain'];
|
||||
|
||||
if (empty($_SERVER['HTTP_CUSTOMHOST']) && !empty($_SERVER['SERVER_NAME']) && ($appsDomain != $_SERVER['SERVER_NAME'])) {
|
||||
$this->redirect("https://".$appsDomain."/order-payment/".$encOrderId, 301);
|
||||
}
|
||||
|
||||
if (!empty($_SERVER['HTTP_CUSTOMHOST']) && ($_SERVER['HTTP_CUSTOMHOST'] != $appsDomain)) {
|
||||
$this->set("customAppsRedirect", "https://".$appsDomain."/order-payment/".$encOrderId);
|
||||
}
|
||||
|
||||
if (!empty($savedOrderData['paid_date'])
|
||||
|| !empty($savedOrderData['expiry_date']) && (date('Y-m-d H:i:s', strtotime($savedOrderData['expiry_date'])) >= date('Y-m-d H:i:s'))
|
||||
|| ($this->isAuthorized([], ["orderPayment"], false))
|
||||
) {
|
||||
$savedOrderData['encOrderId'] = $encOrderId;
|
||||
|
||||
if (!empty($savedOrderData['paid_date'])) {
|
||||
|
||||
//var_dump($savedOrderData['paid_date']);
|
||||
//$savedOrderData['payment'] = json_decode($savedOrderData['payment'], true);
|
||||
$savedOrderData['payment'] = [
|
||||
//'DateTime' => $this->patchTimestampForJS($savedOrderData['payment'][count($savedOrderData['payment']) - 1]['DateTime'], -3, true, 'd.m.Y H:i')
|
||||
'DateTime' => $this->patchTimestampForJS($savedOrderData['paid_date'], -3, true, 'd.m.Y H:i')
|
||||
];
|
||||
} else {
|
||||
$savedOrderData['payment'] = null;
|
||||
}
|
||||
} else {
|
||||
$savedOrderData = [
|
||||
'data' => [
|
||||
'manager_tel' => $savedOrderData['data']['manager_tel']
|
||||
],
|
||||
'link_expired' => true,
|
||||
'order_num' => '',
|
||||
];
|
||||
}
|
||||
|
||||
$jsConfig = $this->getAppJsConfig("orderPayment", false, $savedOrderData);
|
||||
$jsConfig["appsDomain"] = $appsDomain;
|
||||
$jsConfig["rootUrl"] = "https://" . str_replace("apps.", "", $appsDomain);
|
||||
$jsConfig["rootAppsUrl"] = "https://" . $appsDomain;
|
||||
|
||||
$paymentPublicId = "";
|
||||
if (!empty($savedOrderData['targetGateway']) && ($savedOrderData['targetGateway'] == 'РНКБ')) {
|
||||
if (!empty($savedOrderData['domain'])) {
|
||||
$paymentPublicIds = Configure::read("cloudPayments");
|
||||
|
||||
switch ($savedOrderData['domain']) {
|
||||
case "apps.supersamsev.ru":
|
||||
case "apps.supersam24.ru":
|
||||
$paymentPublicId = $paymentPublicIds[$savedOrderData['domain']]['paymentPublicId'];
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
$jsConfig["paymentPublicId"] = $paymentPublicId;
|
||||
|
||||
$elplatQrEnabled = false;
|
||||
if (!empty($savedOrderData['targetGateway']) && ($savedOrderData['targetGateway'] == 'СБП')) {
|
||||
if (!empty($savedOrderData['domain'])) {
|
||||
switch ($savedOrderData['domain']) {
|
||||
case "apps.prometeysev.ru":
|
||||
case "apps.supersam24.ru":
|
||||
case "apps.supersamsev.ru":
|
||||
$elplatQrEnabled = true;
|
||||
$this->config['common']['siteTitle']['value'] = $jsConfig["primarySiteTitle"];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$jsConfig["elplatQrEnabled"] = $elplatQrEnabled;
|
||||
|
||||
$this->set('jsConfig', $jsConfig);
|
||||
$this->set('siteTitle', $this->config['common']['siteTitle']['value'] . " - " . 'Оплата счета ' . $savedOrderData['order_num']);
|
||||
} else {
|
||||
$savedOrderData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (empty($savedOrderData)) {
|
||||
$this->redirect('/404');
|
||||
}
|
||||
}
|
||||
|
||||
public function getPaymentStatus() {
|
||||
$result = [
|
||||
'status' => true
|
||||
];
|
||||
|
||||
$data = $this->request->getData();
|
||||
if(!empty($data['encOrderId'])) {
|
||||
$ordersTable = TableRegistry::getTableLocator()->get('CutOrders');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
$decryptedData = $ordersTable->decryptCustomData($data['encOrderId'], $this->config);
|
||||
|
||||
if (!empty($decryptedData['orderId'])) {
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $decryptedData['orderId'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
|
||||
if (!empty($savedOrderData)) {
|
||||
if (!empty($savedOrderData['paid_date'])) {
|
||||
$result['status'] = true;
|
||||
//$savedOrderData['payment'] = json_decode($savedOrderData['payment'], true);
|
||||
$result['payment'] = [
|
||||
//'DateTime' => $this->patchTimestampForJS($savedOrderData['payment'][count($savedOrderData['payment']) - 1]['DateTime'], -3, true, 'd.m.Y H:i')
|
||||
'paid_date' => $this->patchTimestampForJS($savedOrderData['paid_date'], -3, true, 'd.m.Y H:i')
|
||||
];
|
||||
} else {
|
||||
$result['status'] = false;
|
||||
}
|
||||
} else {
|
||||
$savedOrderData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
public function callbackPay() {
|
||||
$result = [
|
||||
'code' => 13
|
||||
];
|
||||
|
||||
$data = $this->request->getData();
|
||||
if (!empty($data['Data'])) {
|
||||
$data['Data'] = @json_decode(html_entity_decode($data['Data']), true);
|
||||
file_put_contents(TMP . 'callbackPayData' . date('Y-m-d_H-i-s') . '.txt', json_encode($data));
|
||||
|
||||
if (!empty($data['Status']) && ($data['Status'] == 'Completed')) {
|
||||
$ordersTable = TableRegistry::getTableLocator()->get('CutOrders');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
$decryptedData = $ordersTable->decryptCustomData($data['Data']['encOrderId'], $this->config);
|
||||
|
||||
if (!empty($decryptedData['orderId'])) {
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $decryptedData['orderId'],
|
||||
])->first();
|
||||
|
||||
if (!empty($savedOrderData)) {
|
||||
$savedOrderData['data'] = json_decode($savedOrderData['data'], true);
|
||||
$savedOrderData['payment'] = json_decode($savedOrderData['payment'], true);
|
||||
|
||||
if ($savedOrderData['data']['summa_order_decimal'] == $data['Amount']) {
|
||||
$uploadXmlToFtp = false;
|
||||
$xml = '<?xml version="1.0" encoding="windows-1251"?><orders><invoice_no>' . $savedOrderData['order_num'] . '</invoice_no>';
|
||||
|
||||
$isTransactionAlreadyExists = false;
|
||||
if (!empty($savedOrderData['payment'])) {
|
||||
foreach ($savedOrderData['payment'] as $payment) {
|
||||
if ($payment['TransactionId'] == $data['TransactionId']) {
|
||||
$isTransactionAlreadyExists = true;
|
||||
$result['code'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($savedOrderData['payment'])) {
|
||||
$uploadXmlToFtp = true;
|
||||
|
||||
$xml .= '<time>' . $this->patchTimestampForJS($data['DateTime'], -3, true, 'Y-m-d H:i:s') . '</time><paid>ok</paid><paid_summa>'.$data['Amount'].'</paid_summa><gateway>РНКБ</gateway>';
|
||||
} else {
|
||||
if (!$isTransactionAlreadyExists) {
|
||||
$uploadXmlToFtp = true;
|
||||
|
||||
$xml .= '<time>' . $this->patchTimestampForJS($data['DateTime'], -3, true, 'Y-m-d H:i:s') . '</time><paid>order_already</paid><paid_summa>'.$data['Amount'].'</paid_summa><gateway>РНКБ</gateway>';
|
||||
}
|
||||
}
|
||||
$xml .= '</orders>';
|
||||
$xml = mb_convert_encoding(str_replace("\n", "", $xml), "Windows-1251", "UTF-8");
|
||||
|
||||
if ($uploadXmlToFtp) {
|
||||
$ftpParams = Configure::read("ftpParams");
|
||||
$ftpConnectionId = ftp_connect($ftpParams['ip'], (!empty($ftpParams['port']) ? $ftpParams['port'] : 21), 5);
|
||||
if (!empty($ftpConnectionId)) {
|
||||
$ftpLoginResult = ftp_login($ftpConnectionId, $ftpParams['username'], $ftpParams['password']);
|
||||
ftp_pasv($ftpConnectionId, true);
|
||||
|
||||
if ($ftpLoginResult) {
|
||||
$ftpTargetDir = "";
|
||||
switch($savedOrderData['domain']) {
|
||||
case "apps.supersam24.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiring24Out'];
|
||||
break;
|
||||
|
||||
case "apps.supersamsev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringOut'];
|
||||
break;
|
||||
|
||||
case "apps.prometeysev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringPrometeyOut'];
|
||||
break;
|
||||
}
|
||||
|
||||
ftp_chdir($ftpConnectionId, $ftpTargetDir);
|
||||
|
||||
$tmpFile = tmpfile();
|
||||
fwrite($tmpFile, $xml);
|
||||
rewind($tmpFile);
|
||||
|
||||
$filename = 'acquiring_in_' . date('Y-m-d_H-i-s') . '_' . bin2hex(random_bytes(4)) . '.xml';
|
||||
if (ftp_fput($ftpConnectionId, $filename, $tmpFile, FTP_BINARY, 0)) {
|
||||
$tmpOrder = $orderPaymentTable->get($decryptedData['orderId']);
|
||||
|
||||
if (empty($tmpOrder->payment)) {
|
||||
$tmpOrder->payment = [];
|
||||
} else {
|
||||
$tmpOrder->payment = json_decode($tmpOrder->payment, true);
|
||||
}
|
||||
|
||||
if (!$isTransactionAlreadyExists) {
|
||||
$tmpOrder->payment[] = $data;
|
||||
$tmpOrder->summa_order_decimal_paid += $data['Amount'];
|
||||
}
|
||||
|
||||
$tmpOrder->paid_date = $tmpOrder->payment[count($tmpOrder->payment) - 1]['DateTime'];
|
||||
$tmpOrder->payment = json_encode($tmpOrder->payment);
|
||||
$tmpOrder->paymentGateway = "CloudPayments";
|
||||
|
||||
/*if (empty($tmpOrder->files)) {
|
||||
$tmpOrder->files = [];
|
||||
} else {
|
||||
$tmpOrder->files = json_decode($tmpOrder->files, true);
|
||||
}
|
||||
|
||||
if (empty($tmpOrder->files["payment"])) {
|
||||
$tmpOrder->files["payment"] = [];
|
||||
}
|
||||
$tmpOrder->files["payment"][] = [
|
||||
"date" => date('d.m.Y H:i'),
|
||||
"filename" => $filename,
|
||||
"xml" => $xml
|
||||
];
|
||||
|
||||
$tmpOrder->files = json_encode($tmpOrder->files);*/
|
||||
|
||||
$orderPaymentTable->save($tmpOrder);
|
||||
$result['code'] = 0;
|
||||
} else {
|
||||
//$result['code'] = 1;
|
||||
};
|
||||
fclose($tmpFile);
|
||||
|
||||
file_put_contents(TMP . $filename, $xml);
|
||||
TableRegistry::getTableLocator()->get('CutSheets')->putImportFileToArchive(TMP . $filename, false, $filename);
|
||||
}
|
||||
|
||||
ftp_close($ftpConnectionId);
|
||||
} else {
|
||||
//$result['code'] = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$savedOrderData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
public function callbackRefund() {
|
||||
$result = [
|
||||
'code' => 13
|
||||
];
|
||||
|
||||
|
||||
$data = $this->request->getData();
|
||||
|
||||
if (!empty($data['Data'])) {
|
||||
if (!is_array($data['Data'])) {
|
||||
$data['Data'] = @json_decode(html_entity_decode($data['Data']), true);
|
||||
}
|
||||
|
||||
file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.txt', json_encode($data));
|
||||
|
||||
$ordersTable = TableRegistry::getTableLocator()->get('CutOrders');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
$decryptedData = $ordersTable->decryptCustomData($data['Data']['encOrderId'], $this->config);
|
||||
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.1.txt', json_encode($decryptedData));
|
||||
|
||||
if (!empty($decryptedData['orderId'])) {
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $decryptedData['orderId'],
|
||||
])->first();
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.2.txt', json_encode($savedOrderData));
|
||||
|
||||
if (!empty($savedOrderData)) {
|
||||
$ftpParams = Configure::read("ftpParams");
|
||||
$ftpConnectionId = ftp_connect($ftpParams['ip'], (!empty($ftpParams['port']) ? $ftpParams['port'] : 21), 5);
|
||||
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.3.txt', json_encode($ftpConnectionId));
|
||||
|
||||
if (!empty($ftpConnectionId)) {
|
||||
$ftpLoginResult = ftp_login($ftpConnectionId, $ftpParams['username'], $ftpParams['password']);
|
||||
ftp_pasv($ftpConnectionId, true);
|
||||
|
||||
if ($ftpLoginResult) {
|
||||
$ftpTargetDir = "";
|
||||
switch($savedOrderData['domain']) {
|
||||
case "apps.supersam24.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiring24Out'];
|
||||
break;
|
||||
|
||||
case "apps.supersamsev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringOut'];
|
||||
break;
|
||||
|
||||
case "apps.prometeysev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringPrometeyOut'];
|
||||
break;
|
||||
}
|
||||
|
||||
ftp_chdir($ftpConnectionId, $ftpTargetDir);
|
||||
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.4.txt', json_encode($ftpTargetDir));
|
||||
|
||||
//$refundAmount = 0;
|
||||
$tmpOrder = $orderPaymentTable->get($decryptedData['orderId']);
|
||||
|
||||
$isTransactionAlreadyExists = false;
|
||||
if (!empty($tmpOrder->payment)) {
|
||||
$tmpOrder->payment = json_decode($tmpOrder->payment, true);
|
||||
//foreach ($tmpOrder->payment as $paymentKey => $payment) {
|
||||
// if ($payment['TransactionId'] == $data['PaymentTransactionId']) {
|
||||
// unset($tmpOrder->payment[$paymentKey]);
|
||||
|
||||
$isTransactionAlreadyExists = false;
|
||||
foreach ($tmpOrder->payment as $payment) {
|
||||
if ($payment['TransactionId'] == $data['TransactionId']) {
|
||||
$isTransactionAlreadyExists = true;
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
//}
|
||||
} else {
|
||||
$tmpOrder->payment = [];
|
||||
}
|
||||
$tmpOrder->payment[] = $data;
|
||||
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.5.txt', json_encode($isTransactionAlreadyExists));
|
||||
|
||||
if (!$isTransactionAlreadyExists) {
|
||||
$tmpOrder->summa_order_decimal_paid -= $data['Amount'];
|
||||
$refundAmount = $data['Amount'];
|
||||
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.6.txt', json_encode($tmpOrder));
|
||||
|
||||
$xml = '<?xml version="1.0" encoding="windows-1251"?><orders><invoice_no>' . $savedOrderData['order_num'] . '</invoice_no>';
|
||||
$xml .= '<time>' . $this->patchTimestampForJS($data['DateTime'], -3, true, 'Y-m-d H:i:s') . '</time><paid>refund</paid><paid_summa>' . $refundAmount . '</paid_summa><gateway>РНКБ</gateway>';
|
||||
$xml .= '</orders>';
|
||||
$xml = mb_convert_encoding(str_replace("\n", "", $xml), "Windows-1251", "UTF-8");
|
||||
|
||||
$tmpFile = tmpfile();
|
||||
fwrite($tmpFile, $xml);
|
||||
rewind($tmpFile);
|
||||
|
||||
$filename = 'acquiring_in_' . date('Y-m-d_H-i-s') . '_' . bin2hex(random_bytes(4)) . '.xml';
|
||||
if (ftp_fput($ftpConnectionId, $filename, $tmpFile, FTP_BINARY, 0)) {
|
||||
/*if (empty($tmpOrder->payment)) {
|
||||
$tmpOrder->payment = null;
|
||||
$tmpOrder->paid_date = null;
|
||||
} else {
|
||||
$tmpOrder->paid_date = $tmpOrder->payment[count($tmpOrder->payment) - 1]['DateTime'];
|
||||
$tmpOrder->payment = json_encode($tmpOrder->payment);
|
||||
}*/
|
||||
|
||||
if (empty($tmpOrder->summa_order_decimal_paid)) {
|
||||
//$tmpOrder->payment = null;
|
||||
$tmpOrder->paid_date = null;
|
||||
}
|
||||
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.7.txt', json_encode($tmpOrder));
|
||||
|
||||
/*if (empty($tmpOrder->files)) {
|
||||
$tmpOrder->files = [];
|
||||
} else {
|
||||
$tmpOrder->files = json_decode($tmpOrder->files, true);
|
||||
}
|
||||
|
||||
if (empty($tmpOrder->files["refund"])) {
|
||||
$tmpOrder->files["refund"] = [];
|
||||
}
|
||||
$tmpOrder->files["refund"][] = [
|
||||
"date" => date('d.m.Y H:i'),
|
||||
"filename" => $filename,
|
||||
"xml" => $xml
|
||||
];
|
||||
|
||||
$tmpOrder->files = json_encode($tmpOrder->files);*/
|
||||
|
||||
$tmpOrder->payment = json_encode($tmpOrder->payment);
|
||||
$orderPaymentTable->save($tmpOrder);
|
||||
$result['code'] = 0;
|
||||
} else {
|
||||
//$result['code'] = 1;
|
||||
//file_put_contents(TMP . 'callbackRefundData' . date('Y-m-d_H-i-s') . '.8.txt', json_encode($tmpOrder));
|
||||
};
|
||||
} else {
|
||||
$result['code'] = 0;
|
||||
}
|
||||
|
||||
fclose($tmpFile);
|
||||
|
||||
file_put_contents(TMP . $filename, $xml);
|
||||
TableRegistry::getTableLocator()->get('CutSheets')->putImportFileToArchive(TMP . $filename, false, $filename);
|
||||
}
|
||||
|
||||
ftp_close($ftpConnectionId);
|
||||
} else {
|
||||
//$result['code'] = 1;
|
||||
}
|
||||
} else {
|
||||
$savedOrderData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
|
||||
public function createElplatPaymentQr() {
|
||||
$result = [
|
||||
'status' => false
|
||||
];
|
||||
|
||||
$data = $this->request->getData();
|
||||
if(!empty($data['encOrderId'])) {
|
||||
$ordersTable = TableRegistry::getTableLocator()->get('CutOrders');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
$decryptedData = $ordersTable->decryptCustomData($data['encOrderId'], $this->config);
|
||||
|
||||
if (!empty($decryptedData['orderId'])) {
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $decryptedData['orderId'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
|
||||
if (!empty($savedOrderData)) {
|
||||
if (empty($savedOrderData['paid_date'])) {
|
||||
$elplatCredentials = Configure::read('elplat');
|
||||
$elplatCredentials = $elplatCredentials[$savedOrderData['domain']];
|
||||
|
||||
$elplat = new ElplatMerchantAPI();
|
||||
|
||||
$orderData = json_decode($savedOrderData['data'], true);
|
||||
|
||||
$paymentPurposeL1 = "";
|
||||
$paymentPurposeL2 = "";
|
||||
switch($savedOrderData['domain']) {
|
||||
case "apps.supersam24.ru":
|
||||
$paymentPurposeL1 = 'Оплата счета ' . $orderData['invoice_no'] . ', СуперСам';
|
||||
break;
|
||||
|
||||
case "apps.supersamsev.ru":
|
||||
$paymentPurposeL1 = 'Оплата счета ' . $orderData['invoice_no'] . ', СуперСам';
|
||||
break;
|
||||
|
||||
case "apps.prometeysev.ru":
|
||||
$paymentPurposeL1 = 'Оплата счета ' . $orderData['invoice_no'] . ', ';
|
||||
$paymentPurposeL2 = 'ООО ТЦ "Прометей"';
|
||||
break;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'login' => $elplatCredentials['login'],
|
||||
"passwd" => $elplatCredentials['passwd'],
|
||||
"callback" => "https://" . $savedOrderData['domain'] . Router::url(['controller' => 'OrderPayment', 'action' => 'callback_elplat']),
|
||||
"qrcType" => "02",
|
||||
"currency" => "RUB",
|
||||
"orgId" => $elplatCredentials['orgId'],
|
||||
"amount" => round($savedOrderData['summa_order_decimal'] * 100),
|
||||
"paymentPurpose" => $paymentPurposeL1.$paymentPurposeL2,
|
||||
"email" => (!empty($orderData['email']) ? $orderData['email'] : '')
|
||||
];
|
||||
|
||||
$hashId = $elplat->getElplatHashId($data);
|
||||
unset($data['passwd']);
|
||||
|
||||
$request = $elplat->createQr($elplatCredentials['apiUrl'], array_merge($data, [
|
||||
"type" => "createQr",
|
||||
'elplatPhone' => $elplatCredentials['elplatPhone'],
|
||||
'hashId' => $hashId
|
||||
]));
|
||||
|
||||
if (!empty($request['info']['status'])) {
|
||||
$elplatPaymentsTable = TableRegistry::getTableLocator()->get('ElplatPayments');
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$elplatPayment = $elplatPaymentsTable->newEntity([
|
||||
'orderPaymentId' => $decryptedData['orderId'],
|
||||
'qrData' => $request['info']['qrData'],
|
||||
'qrcId' => $request['info']['qrcId'],
|
||||
'responseData' => null,
|
||||
'status' => 'pending',
|
||||
'created' => $now,
|
||||
'updated' => $now,
|
||||
]);
|
||||
|
||||
$elplatPaymentsTable->save($elplatPayment);
|
||||
|
||||
$result['status'] = true;
|
||||
$result['qrInfo'] = $request['info'];
|
||||
$result['paymentPurposeL1'] = $paymentPurposeL1;
|
||||
$result['paymentPurposeL2'] = $paymentPurposeL2;
|
||||
$result['paymentAmount'] = $orderData['summa_order'].'р.';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$savedOrderData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
public function getElpatPaymentStatus() {
|
||||
$result = [
|
||||
'status' => 'failure'
|
||||
];
|
||||
|
||||
$data = $this->request->getData();
|
||||
if(!empty($data['qrcId'])) {
|
||||
$elplatPaymentsTable = TableRegistry::getTableLocator()->get('ElplatPayments');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
|
||||
$qrData = $elplatPaymentsTable->find('all')->where([
|
||||
'qrcId ' => $data['qrcId'],
|
||||
])->first();
|
||||
|
||||
if (!empty($qrData)) {
|
||||
$result['status'] = $qrData['status'];
|
||||
|
||||
$orderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $qrData['orderPaymentId'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
|
||||
if ($result['status'] != 'success') {
|
||||
//check for payments by other qr
|
||||
|
||||
if (!empty($orderData) && !empty($orderData['paid_date'])) {
|
||||
$result['status'] = 'success';
|
||||
|
||||
$result['payment'] = [
|
||||
'paid_date' => $this->patchTimestampForJS($orderData['paid_date'], -3, true, 'd.m.Y H:i')
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$result['payment'] = [
|
||||
'paid_date' => $this->patchTimestampForJS($orderData['paid_date'], -3, true, 'd.m.Y H:i')
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$result['status'] = 'success';
|
||||
echo $this->jsonSimpleResponse($result);
|
||||
}
|
||||
|
||||
public function callbackElplat() {
|
||||
if (!$this->checkIsElplatCallbackIpAllowed()) {
|
||||
$ipToCheck = $this->request->clientIP();
|
||||
if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
|
||||
$ipToCheck = $_SERVER['HTTP_X_REAL_IP'];
|
||||
}
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.error.txt', json_encode(['incorrect callback ip ' . $ipToCheck]));
|
||||
|
||||
die('NOTOK');
|
||||
}
|
||||
|
||||
$data = $this->request->getData();
|
||||
|
||||
if (empty($data)) {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
}
|
||||
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.txt', json_encode($data));
|
||||
|
||||
if(isset($data['payStatus'])) {
|
||||
$elplatPaymentsTable = TableRegistry::getTableLocator()->get('ElplatPayments');
|
||||
$orderPaymentTable = TableRegistry::getTableLocator()->get('OrderPayment');
|
||||
|
||||
$qrData = $elplatPaymentsTable->find('all')->where([
|
||||
'qrcId ' => $data['qrcId'],
|
||||
])->first();
|
||||
|
||||
if (empty($qrData)) {
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.error.qrnotfoundindb.txt', json_encode($data));
|
||||
|
||||
die('NOTOK');
|
||||
}
|
||||
|
||||
$savedOrderData = $orderPaymentTable->find('all')->where([
|
||||
'id' => $qrData['orderPaymentId'],
|
||||
'isDeleted' => false,
|
||||
])->first();
|
||||
|
||||
if (empty($savedOrderData)) {
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.error.ordernotfoundindb.txt', json_encode($data));
|
||||
|
||||
die('NOTOK');
|
||||
}
|
||||
|
||||
if (((int)$data['allAmount']) < ((int)($savedOrderData['summa_order_decimal'] * 100))) {
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.error.incorrectallamount.txt', json_encode($data));
|
||||
|
||||
die('NOTOK');
|
||||
}
|
||||
|
||||
$qrStatus = "failure";
|
||||
if ($data['payStatus'] == 1) {
|
||||
$qrStatus = "success";
|
||||
|
||||
$xml = '<?xml version="1.0" encoding="windows-1251"?><orders><invoice_no>' . $savedOrderData['order_num'] . '</invoice_no>';
|
||||
|
||||
$xml .= '<time>' . date('Y-m-d H:i:s') . '</time><paid>ok</paid><paid_summa>'.($data['allAmount']/100).'</paid_summa><gateway>СБП</gateway>';
|
||||
$xml .= '</orders>';
|
||||
$xml = mb_convert_encoding(str_replace("\n", "", $xml), "Windows-1251", "UTF-8");
|
||||
|
||||
$ftpParams = Configure::read("ftpParams");
|
||||
$ftpConnectionId = ftp_connect($ftpParams['ip'], (!empty($ftpParams['port']) ? $ftpParams['port'] : 21), 5);
|
||||
if (!empty($ftpConnectionId)) {
|
||||
$ftpLoginResult = ftp_login($ftpConnectionId, $ftpParams['username'], $ftpParams['password']);
|
||||
ftp_pasv($ftpConnectionId, true);
|
||||
|
||||
if ($ftpLoginResult) {
|
||||
$ftpTargetDir = "";
|
||||
switch($savedOrderData['domain']) {
|
||||
case "apps.supersam24.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiring24Out'];
|
||||
break;
|
||||
|
||||
case "apps.supersamsev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringOut'];
|
||||
break;
|
||||
|
||||
case "apps.prometeysev.ru":
|
||||
$ftpTargetDir = $ftpParams['acquiringPrometeyOut'];
|
||||
break;
|
||||
}
|
||||
|
||||
ftp_chdir($ftpConnectionId, $ftpTargetDir);
|
||||
|
||||
$tmpFile = tmpfile();
|
||||
fwrite($tmpFile, $xml);
|
||||
rewind($tmpFile);
|
||||
|
||||
$filename = 'acquiring_in_' . date('Y-m-d_H-i-s') . '_' . bin2hex(random_bytes(4)) . '.xml';
|
||||
if (ftp_fput($ftpConnectionId, $filename, $tmpFile, FTP_BINARY, 0)) {
|
||||
|
||||
$tmpOrder = $orderPaymentTable->get($savedOrderData['id']);
|
||||
|
||||
$tmpOrder->payment = [];
|
||||
$tmpOrder->payment[] = $data;
|
||||
$tmpOrder->summa_order_decimal_paid = $data['allAmount'] / 100;
|
||||
|
||||
$tmpOrder->paid_date = date('Y-m-d H:i:s', strtotime("-3 hours"));
|
||||
$tmpOrder->payment = json_encode($tmpOrder->payment);
|
||||
$tmpOrder->paymentGateway = "Elplat";
|
||||
|
||||
/*if (empty($tmpOrder->files)) {
|
||||
$tmpOrder->files = [];
|
||||
} else {
|
||||
$tmpOrder->files = json_decode($tmpOrder->files, true);
|
||||
}
|
||||
|
||||
if (empty($tmpOrder->files["payment"])) {
|
||||
$tmpOrder->files["payment"] = [];
|
||||
}
|
||||
$tmpOrder->files["payment"][] = [
|
||||
"date" => date('d.m.Y H:i'),
|
||||
"filename" => $filename,
|
||||
"xml" => $xml
|
||||
];
|
||||
|
||||
$tmpOrder->files = json_encode($tmpOrder->files);*/
|
||||
|
||||
$orderPaymentTable->save($tmpOrder);
|
||||
} else {
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.error.ftpuploaderror.txt', json_encode($data));
|
||||
};
|
||||
fclose($tmpFile);
|
||||
|
||||
file_put_contents(TMP . $filename, $xml);
|
||||
TableRegistry::getTableLocator()->get('CutSheets')->putImportFileToArchive(TMP . $filename, false, $filename);
|
||||
}
|
||||
|
||||
ftp_close($ftpConnectionId);
|
||||
} else {
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.error.ftpconnecterror.txt', json_encode($data));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$qrData->responseData = json_encode($data);
|
||||
$qrData->status = $qrStatus;
|
||||
$qrData->updated = date('Y-m-d H:i:s');
|
||||
$elplatPaymentsTable->save($qrData);
|
||||
|
||||
//file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.success.ftpuploadok.txt', json_encode($data));
|
||||
|
||||
ob_clean();
|
||||
header_remove();
|
||||
header("Content-type: application/json");
|
||||
http_response_code(200);
|
||||
echo json_encode(["status" => true]);
|
||||
exit;
|
||||
} else {
|
||||
file_put_contents(TMP . 'callbackElplatPayData' . date('Y-m-d_H-i-s') . '.error.paystatust0.txt', json_encode($data));
|
||||
|
||||
die('NOTOK');
|
||||
}
|
||||
}
|
||||
|
||||
public function checkIsElplatCallbackIpAllowed() {
|
||||
$allow = false;
|
||||
$allowedIps = ['91.223.44.0/24'];
|
||||
$ipToCheck = $this->request->clientIP();
|
||||
if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
|
||||
$ipToCheck = $_SERVER['HTTP_X_REAL_IP'];
|
||||
}
|
||||
|
||||
foreach($allowedIps as $ip_allow) {
|
||||
// If IP has / means CIDR notation
|
||||
if(strpos($ip_allow, '/') === false) {
|
||||
// Check Single IP
|
||||
if(inet_pton($ipToCheck) == inet_pton($ip_allow)) {
|
||||
$allow = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Check IP range
|
||||
list($subnet, $bits) = explode('/', $ip_allow);
|
||||
|
||||
// Convert subnet to binary string of $bits length
|
||||
$subnet = unpack('H*', inet_pton($subnet)); // Subnet in Hex
|
||||
|
||||
foreach($subnet as $i => $h) $subnet[$i] = base_convert($h, 16, 2); // Array of Binary
|
||||
$subnet = substr(implode('', $subnet), 0, $bits); // Subnet in Binary, only network bits
|
||||
|
||||
// Convert remote IP to binary string of $bits length
|
||||
$ip = unpack('H*', inet_pton($ipToCheck)); // IP in Hex
|
||||
foreach($ip as $i => $h) $ip[$i] = base_convert($h, 16, 2); // Array of Binary
|
||||
$ip = substr(implode('', $ip), 0, $bits); // IP in Binary, only network bits
|
||||
|
||||
// Check network bits match
|
||||
if($subnet == $ip) {
|
||||
$allow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $allow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
namespace App\Shell;
|
||||
|
||||
use Cake\Console\Shell;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Core\Configure\Engine\PhpConfig;
|
||||
use Cake\Datasource\ConnectionManager;
|
||||
use SMSRU;
|
||||
|
||||
class importOrdersReadySmsShell extends Shell {
|
||||
public function initialize() {
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
|
||||
public function main() {
|
||||
$lock_file = TMP."importOrdersReadySmsShell.lock" ;
|
||||
if ( isLocked($lock_file) ) {
|
||||
die( "Already running.\n" );
|
||||
}
|
||||
|
||||
ini_set('max_execution_time', 0);
|
||||
ini_set('memory_limit', '2048M');
|
||||
|
||||
|
||||
/*$smsRuApiKey = TableRegistry::getTableLocator()->get("Settings")->find('all')->where([
|
||||
'key' => 'smsRuApiKey'
|
||||
])->first();
|
||||
$smsRu = new SMSRU($smsRuApiKey['value']);
|
||||
$smsData = new \stdClass();
|
||||
$smsData->to = '79781462978';
|
||||
$smsData->text = 'я смс с сервера';
|
||||
$sendStatus = $smsRu->send_one($smsData);
|
||||
var_dump($sendStatus);exit;*/
|
||||
|
||||
|
||||
$ch = curl_init();
|
||||
//curl_setopt($ch, CURLOPT_URL, "https://sms.ru/?panel=log&csv=1&from=".date('d.m.Y', strtotime('-1 month')));
|
||||
curl_setopt($ch, CURLOPT_URL, "https://sms.ru/?panel=log&csv=1");
|
||||
|
||||
//curl_setopt($ch, CURLOPT_URL, "https://sms.ru/?panel=log&csv=1&from=01.01.2021&to=31.05.2021");
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36');
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Referer: https://sms.ru/?panel=log"
|
||||
]);
|
||||
|
||||
$cookie = "dev_id=206C04BA-3BBA-721D-B977-750BD664D3CC; tz=-180; screen_size=1920x937; authcookie=186784:5dfba6a17a273d16041c5a9a33bc48d7:new:; hasloggedin=1";
|
||||
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
||||
|
||||
$data = curl_exec($ch);
|
||||
$status = curl_getinfo($ch);
|
||||
|
||||
$mail = TableRegistry::getTableLocator()->get('CutOrders')->configurePHPMailer([], "Импорт SMS с информацией о готовности заказов");
|
||||
$mail->addAddress("admin@mail.supersamsev.ru");
|
||||
|
||||
$mail->Subject = "Импорт SMS с информацией о готовности заказов";
|
||||
$mail->Body = date("d.m.Y H:i")." - ";
|
||||
|
||||
if ($status['http_code'] != 200) {
|
||||
$mail->Body .= "ошибка импорта CSV файла с sms.ru.";
|
||||
$mail->Subject = "Ошибка::" . $mail->Subject;
|
||||
|
||||
file_put_contents(TMP.'sms_status', print_r($status, true));
|
||||
file_put_contents(TMP.'sms_data', print_r($data, true));
|
||||
} else {
|
||||
$tmpFile = TMP . "importOrdersReadySms.csv";
|
||||
file_put_contents($tmpFile, $data);
|
||||
|
||||
$importResult = TableRegistry::getTableLocator()->get("SmsOrdersReady")->importSms($tmpFile);
|
||||
|
||||
if ($importResult['totalCount'] > 0) {
|
||||
$mail->Body .= "импортировано " . $importResult['importCount'] . ' новых SMS' . (!empty($importResult['updateCount']) ? ", обновлены статусы у " . $importResult['updateCount'] . " SMS": "");
|
||||
|
||||
TableRegistry::getTableLocator()->get('Settings')->refreshSettingsUpdateDate("", 'smsOrdersReady', false);
|
||||
} else {
|
||||
$mail->Body .= "ошибка импорта: неверный формат файла или список информационных sms пуст.";
|
||||
}
|
||||
}
|
||||
$mail->send();
|
||||
|
||||
$mail->clearAddresses();
|
||||
$mail->addAddress("sbtestemail789@gmail.com");
|
||||
$mail->send();
|
||||
@unlink($lock_file);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
<div data-ng-controller="OrderPaymentController" class="order-payment">
|
||||
<div class="card card-order-payment">
|
||||
<div class="card-header">
|
||||
<div class="form-row">
|
||||
<div class="input-group col-12 col-sm-12 col-md-6 col-lg-3 col-xl-3">
|
||||
<input id="orderPaymentSearch" type="text" class="form-control" placeholder="Счет, телефон, ФИО или сумма" data-ng-enter="orderPayment.pagination.setPage(1)" data-ng-model="orderPayment.search">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" type="button" data-ng-click="orderPayment.pagination.setPage(1)"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group col-6 col-sm-6 col-md-3 col-lg-2 col-xl-2 datepickerWrap ">
|
||||
<input readonly="true" type="text" class="form-control" data-ng-click="orderPayment.openDateFromDatepicker()" data-ng-change="orderPayment.pagination.setPage(1)" uib-datepicker-popup="dd.MM.yyyy" data-ng-model="orderPayment.dateFrom" data-is-open="orderPayment.dateFromDatepicker.opened" data-datepicker-options="orderPayment.dateFromDatepickerOptions" data-ng-required="true" data-current-text="Сегодня" data-close-text="Закрыть" />
|
||||
<div class="input-group-append input-group-sm">
|
||||
<button type="button" class="btn btn-outline-secondary" data-ng-click="orderPayment.openDateFromDatepicker()">
|
||||
<i class="fa fa-calendar"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group col-6 col-sm-6 col-md-3 col-lg-2 col-xl-2 datepickerWrap ">
|
||||
<input readonly="true" type="text" class="form-control" data-ng-click="orderPayment.openDateToDatepicker()" data-ng-change="orderPayment.pagination.setPage(1)" uib-datepicker-popup="dd.MM.yyyy" data-ng-model="orderPayment.dateTo" data-is-open="orderPayment.dateToDatepicker.opened" data-datepicker-options="orderPayment.dateToDatepickerOptions" data-ng-required="true" data-current-text="Сегодня" data-close-text="Закрыть" />
|
||||
<div class="input-group-append input-group-sm">
|
||||
<button type="button" class="btn btn-outline-secondary" data-ng-click="orderPayment.openDateToDatepicker()">
|
||||
<i class="fa fa-calendar"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group col-12 col-md-11 col-lg-4 col-xl-4">
|
||||
<select data-ng-change="orderPayment.pagination.setPage(1)" class="custom-select col-6 col-md-5" data-ng-model="orderPayment.paymentStatus" data-ng-options="v.id as v.label for v in config.paymentStatusList"></select>
|
||||
<select data-ng-change="orderPayment.pagination.setPage(1)" class="custom-select col-6 col-md-5" data-ng-model="orderPayment.paymentGateway" data-ng-options="v.id as v.label for v in config.paymentGatewayList"></select>
|
||||
<select data-ng-change="orderPayment.pagination.setPage(1)" class="custom-select col-6 col-md-2" data-ng-model="orderPayment.pagination.numPerPage" data-ng-options="v.id as v.label for v in config.perPageList"></select>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-1 col-lg-1 col-md-1 col-sm-1 text-right d-none d-md-block">
|
||||
<i class="fa fa-refresh" data-ng-click="orderPayment.searchOrders()" title="Обновить" data-ng-class="{'loading': orderPayment.isSubmitting}"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group alert alert-danger" data-ng-if="orderPayment.errors.length">
|
||||
<div data-ng-repeat="errorMessage in orderPayment.errors">
|
||||
<span>{{errorMessage}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mh60">
|
||||
<div class="col-lg-12">
|
||||
<table class="table table-striped table-sm table-order-payment table-hover table-responsive-xl">
|
||||
<thead id="table-order-payment-head">
|
||||
<tr>
|
||||
<th data-ng-click="utilities.sortBy('ordersList', 'order_num', 'desc')" class="sortable" data-ng-class="utilities.getSortByClass('ordersList', 'order_num')">Счет</th>
|
||||
<th data-ng-click="utilities.sortBy('ordersList', 'name', 'asc')" class="sortable" data-ng-class="utilities.getSortByClass('ordersList', 'name')">Покупатель</th>
|
||||
<th data-ng-click="utilities.sortBy('ordersList', 'telephone', 'asc')" class="sortable" data-ng-class="utilities.getSortByClass('ordersList', 'telephone')">Телефон</th>
|
||||
<th data-ng-click="utilities.sortBy('ordersList', 'summa_order_decimal', 'desc')" class="sortable" data-ng-class="utilities.getSortByClass('ordersList', 'summa_order_decimal')">Сумма</th>
|
||||
<th data-ng-click="utilities.sortBy('ordersList', 'expiry_date', 'desc')" class="sortable text-center" data-ng-class="utilities.getSortByClass('ordersList', 'expiry_date')">Дата формирования</th>
|
||||
<th data-ng-click="utilities.sortBy('ordersList', 'statusJs', 'desc')" class="sortable text-center" data-ng-class="utilities.getSortByClass('ordersList', 'statusJs')">Статус</th>
|
||||
<th data-ng-click="utilities.sortBy('ordersList', 'paymentGateway', 'desc')" class="sortable text-center" data-ng-class="utilities.getSortByClass('ordersList', 'paymentGateway')">Шлюз</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr data-ng-repeat="order in orderPayment.ordersList" data-ng-if="(orderPayment.usedSearch != null) && orderPayment.ordersList.length ">
|
||||
<td class="no-wrap">{{order.order_num}}</td>
|
||||
<td class="no-wrap">{{order.name}}</span></td>
|
||||
<td class="no-wrap">
|
||||
<span data-ng-if="order.telephone && (order.telephone.length > 0)" data-toggle="tooltip" data-placement="top" title="{{order.telephoneOriginal}}" data-container="body" data-trigger="hover focus">
|
||||
{{order.telephone}}
|
||||
</span>
|
||||
</td>
|
||||
<td class="no-wrap">{{order.summa_order}}р.</td>
|
||||
<td class="text-center no-wrap">
|
||||
{{order.expiry_date | date: 'dd.MM.yyyy HH:mm'}}
|
||||
<a href="https://{{order.domain}}/order-payment/{{order.encryptOrderId}}" target="_blank"><i class="fa fa-external-link"></i></a>
|
||||
</td>
|
||||
<td class="text-center text-bolder no-wrap" data-ng-class="utilities.getPaymentStatusClass(order.status)">
|
||||
<span>{{order.status}}</span>
|
||||
<span data-ng-if="(order.status == 'Оплачен')">
|
||||
{{order.paidDate}}
|
||||
</span>
|
||||
</td>
|
||||
<td class="text-center no-wrap">
|
||||
{{orderPayment.getPaymentGatewayLabel(order.paymentGateway)}}
|
||||
</td>
|
||||
<td class="text-center no-wrap btn-td">
|
||||
<div class="btn-group btn-group-sm" >
|
||||
<button type="button" data-ng-click="orderPayment.adminShowElplatPaymentHistory(order.id, order.order_num)" title="Возврат средств" data-ng-if="(config.isAdmin || config.isKassir) && (order.paymentGateway == 'Elplat')" class="btn btn-warning"><i class='fa fa-reply' style="position: relative; top: 2px;"></i></button>
|
||||
<button type="button" data-ng-click="orderPayment.adminShowCloudPaymentsPaymentHistory(order.id, order.order_num)" title="Возврат средств" data-ng-if="(config.isAdmin || config.isKassir) && (order.paymentGateway == 'CloudPayments')" class="btn btn-warning"><i class='fa fa-reply' style="position: relative; top: 2px;"></i></button>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-right no-wrap btn-td">
|
||||
<div class="btn-group btn-group-sm" >
|
||||
<button type="button" data-ng-click="orderPayment.adminDeleteOrder(order)" title="Удалить" data-ng-if="config.isAdmin" class="btn btn-danger"><i class='fa fa-remove'></i></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr data-ng-if="!orderPayment.isSubmitting && (orderPayment.usedSearch != null) && !orderPayment.ordersList.length">
|
||||
<td colspan="8">
|
||||
Счета не найдены.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr data-ng-if="!orderPayment.isSubmitting && (orderPayment.usedSearch == null)">
|
||||
<td colspan="8">
|
||||
Укажите номер счета, телефон или ФИО для поиска.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr data-ng-if="orderPayment.isSubmitting" class="pagination-loader" data-ng-class="(!orderPayment.ordersList.length ? 'empty-paged-list' : '' )"></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" data-ng-if="(orderPayment.ordersList.length > 0)">
|
||||
<div class="col-12 col-sm-6 text-left" style="font-weight: 500; font-size: 0.95rem;" >
|
||||
<span data-ng-if="orderPayment.paidCount > 0" class="text-success" style="display: block;">
|
||||
Оплачено счетов - <b>{{orderPayment.paidCount}}</b>, на сумму <b>{{orderPayment.paidTotal}}р.</b>
|
||||
</span>
|
||||
|
||||
<span data-ng-if="orderPayment.unpaidCount > 0" class="text-danger" style="display: block;">
|
||||
Счетов, ожидающих оплаты - <b>{{orderPayment.unpaidCount}}</b>, на сумму <b>{{orderPayment.unpaidTotal}}р.</b>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-sm-6 text-right">
|
||||
<span data-ng-if="(orderPayment.ordersList.length <= orderPayment.pagination.numPerPage) && (orderPayment.totalOrders <= orderPayment.pagination.numPerPage)">
|
||||
Найдено счетов: <b>{{orderPayment.ordersList.length}}</b>
|
||||
</span>
|
||||
|
||||
<span data-ng-if="orderPayment.totalOrders > orderPayment.pagination.numPerPage">
|
||||
Всего найдено счетов - <b>{{orderPayment.totalOrders}}</b>,
|
||||
отображены <b>{{(orderPayment.pagination.currentPage - 1) * orderPayment.pagination.numPerPage + 1}}</b> - <b>{{(orderPayment.pagination.currentPage - 1) * orderPayment.pagination.numPerPage > (orderPayment.totalOrders - orderPayment.pagination.numPerPage) ? orderPayment.totalOrders : orderPayment.pagination.currentPage * orderPayment.pagination.numPerPage }}</b>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" data-ng-if="(orderPayment.pagination.totalPages > 1)">
|
||||
<div class="col-12">
|
||||
<ul class="pagination pagination-md justify-content-center"
|
||||
uib-pagination
|
||||
data-max-size="10"
|
||||
data-boundary-links="true"
|
||||
data-total-items="orderPayment.pagination.totalItems"
|
||||
data-items-per-page="orderPayment.pagination.numPerPage"
|
||||
data-ng-model="orderPayment.pagination.currentPage"
|
||||
data-previous-text="<"
|
||||
data-next-text=">"
|
||||
data-first-text="|<"
|
||||
data-last-text=">|">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pagination-full-width-loader" data-ng-if="orderPayment.isSubmitting"></div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="elplatPaymentHistoryModal">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
История движения средств по счету {{orderPayment.elplatPaymentModalData.order_num}}
|
||||
<img src="/img/payment/sbp-logo-black2.png" style="height: 36px; position: absolute; right: 48px; top: 15px;" class="d-none d-lg-block">
|
||||
</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table table-striped">
|
||||
<tbody>
|
||||
<tr data-ng-repeat="history in orderPayment.elplatPaymentModalData.history">
|
||||
<td>{{history.date}}</td>
|
||||
<td class="text-left">
|
||||
{{history.description}}
|
||||
<small data-ng-if="history.refundManager" class="text-muted"><br/>Возврат выполнен пользователем {{history.refundManager}}</small>
|
||||
</td>
|
||||
<td>{{history.amount}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr/>
|
||||
|
||||
<p>Если необходимо произвести возврат средств по данному счету, заполните назначение платежа и сумму к возврату и нажмите кнопку "Вернуть средства"</p>
|
||||
|
||||
<div class="row form-horizontal">
|
||||
<div class="col-12">
|
||||
<div class="form-group row">
|
||||
<label class="col-3 col-form-label" for="elplatPaymentModalDataRefundDescription">Назначение платежа: </label>
|
||||
<div class="col-9">
|
||||
<input type="text" class="form-control" id="elplatPaymentModalDataRefundDescription" data-ng-model="orderPayment.elplatPaymentModalData.refundDescription" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-3 col-form-label" for="elplatPaymentModalDataRefundAmount">Сумма к возврату, р.: </label>
|
||||
<div class="col-3">
|
||||
<input type="text" class="form-control" id="elplatPaymentModalDataRefundAmount" data-ng-model="orderPayment.elplatPaymentModalData.refundAmount" data-floating-number-only>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer justify-content-between">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-success" data-ng-click="orderPayment.makeElplatRefund()" data-ng-disabled="orderPayment.isMakingElplatRefundInProgress || !orderPayment.elplatPaymentModalData.refundDescription || !orderPayment.elplatPaymentModalData.refundAmount">
|
||||
Вернуть средства
|
||||
<span class="spinner-border spinner-border-sm" data-ng-if="orderPayment.isMakingElplatRefundInProgress"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="cloudPaymentsPaymentHistoryModal">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
История движения средств по счету {{orderPayment.cloudPaymentsPaymentModalData.order_num}}
|
||||
<img src="/img/payment/cloudpayments.svg" style="height: 22px; position: absolute; right: 48px; top: 20px;" class="d-none d-lg-block">
|
||||
</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table table-striped">
|
||||
<tbody>
|
||||
<tr data-ng-repeat="history in orderPayment.cloudPaymentsPaymentModalData.history">
|
||||
<td>{{history.date}}</td>
|
||||
<td class="text-left">
|
||||
{{history.description}}
|
||||
<small data-ng-if="history.refundManager" class="text-muted"><br/>Возврат выполнен пользователем {{history.refundManager}}</small>
|
||||
</td>
|
||||
<td>{{history.amount}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr/>
|
||||
|
||||
<p>Если необходимо произвести возврат средств по данному счету, заполните сумму к возврату и нажмите кнопку "Вернуть средства"</p>
|
||||
|
||||
<div class="row form-horizontal">
|
||||
<div class="col-12">
|
||||
<div class="form-group row">
|
||||
<label class="col-3 col-form-label" for="cloudPaymentsPaymentModalDataRefundAmount">Сумма к возврату, р.: </label>
|
||||
<div class="col-3">
|
||||
<input type="text" class="form-control" id="cloudPaymentsPaymentModalDataRefundAmount" data-ng-model="orderPayment.cloudPaymentsPaymentModalData.refundAmount" data-floating-number-only>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer justify-content-between">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-success" data-ng-click="orderPayment.makeCloudPaymentsRefund()" data-ng-disabled="orderPayment.isMakingCloudPaymentsRefundInProgress || !orderPayment.cloudPaymentsPaymentModalData.refundAmount">
|
||||
Вернуть средства
|
||||
<span class="spinner-border spinner-border-sm" data-ng-if="orderPayment.isMakingCloudPaymentsRefundInProgress"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php $this->Assign('title', $siteTitle . ' :: Оплата счета' );?>
|
||||
Reference in new issue
Block a user