142 lines
4.7 KiB
PHP
Executable File
142 lines
4.7 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Opencart\Catalog\Controller\Extension\PayAnyWay\Payment;
|
|
|
|
require_once DIR_EXTENSION . '/payanyway/catalog/library/payanyway/traits/payanyway.php';
|
|
|
|
class PayAnyWay extends \Opencart\System\Engine\Controller
|
|
{
|
|
use \Opencart\Catalog\Library\Extension\PayAnyWay\Traits\PayAnyWay;
|
|
|
|
private const PAYMENT_SERVER_PROD = 'prod';
|
|
private const PAYMENT_URL_PROD = 'https://www.payanyway.ru/assistant.htm';
|
|
private const PAYMENT_URL_DEMO = 'https://demo.moneta.ru/assistant.htm';
|
|
private const DESCRIPTION_MAX_LENGTH = 500;
|
|
|
|
private int $mntId;
|
|
private string $integrityCode;
|
|
private string $server;
|
|
private string $vatRate;
|
|
private string $currency;
|
|
private int $pendingOrderStatusId;
|
|
private int $successOrderStatusId;
|
|
private int $errorOrderStatusId;
|
|
private int $geoZoneId;
|
|
private int $sortOrder;
|
|
private string $cmsModuleVersion;
|
|
|
|
private array $orderInfo;
|
|
private ?int $orderId;
|
|
|
|
public function __construct(\Opencart\System\Engine\Registry $registry)
|
|
{
|
|
parent::__construct($registry);
|
|
|
|
if (!$this->validateOrder()) {
|
|
$this->response->redirect($this->url->link('account/login', '', true));
|
|
}
|
|
|
|
$this->initializeModule();
|
|
}
|
|
|
|
/**
|
|
* @throws \Exception
|
|
*/
|
|
public function index(): string
|
|
{
|
|
$this->load->language('extension/payanyway/payment/payanyway');
|
|
$this->document->setTitle($this->language->get('heading_title'));
|
|
|
|
$data['action'] = (self::PAYMENT_SERVER_PROD === $this->server)
|
|
? self::PAYMENT_URL_PROD
|
|
: self::PAYMENT_URL_DEMO;
|
|
|
|
$data['MNT_ID'] = $this->mntId;
|
|
$data['MNT_TRANSACTION_ID'] = $this->createTransactionId($this->orderId);
|
|
$data['MNT_AMOUNT'] = $this->formatPrice((float)($this->orderInfo['total'] ?? 0));
|
|
$data['MNT_CURRENCY_CODE'] = $this->currency;
|
|
$data['MNT_TEST_MODE'] = '0';
|
|
$data['MNT_DESCRIPTION'] = $this->getDescription();
|
|
$data['MNT_SUBSCRIBER_ID'] = $this->getSubscriberId();
|
|
|
|
$signature = md5(
|
|
$data['MNT_ID'] .
|
|
$data['MNT_TRANSACTION_ID'] .
|
|
$data['MNT_AMOUNT'] .
|
|
$data['MNT_CURRENCY_CODE'] .
|
|
$data['MNT_SUBSCRIBER_ID'] .
|
|
$data['MNT_TEST_MODE'] .
|
|
$this->integrityCode,
|
|
);
|
|
$data['MNT_SIGNATURE'] = $signature;
|
|
$data['MNT_SUCCESS_URL'] = $this->url->link('extension/payanyway/payment/payanyway.success', 'language=' . $this->config->get('config_language'), true,);
|
|
$data['MNT_FAIL_URL'] = $this->url->link('extension/payanyway/payment/payanyway.fail', 'language=' . $this->config->get('config_language'), true,);
|
|
$data['MNT_RETURN_URL'] = $this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'), true,);
|
|
$data['MNT_CMS'] = $this->cmsModuleVersion;
|
|
|
|
$data['btn_confirm'] = $this->language->get('text_paw_pay');
|
|
|
|
$data['confirm_url'] = $this->url->link('extension/payanyway/payment/payanyway.confirm', 'language=' . $this->config->get('config_language'), true,);
|
|
|
|
return $this->load->view('extension/payanyway/payment/payanyway', $data);
|
|
}
|
|
|
|
public function confirm(): void
|
|
{
|
|
$this->load->language('extension/payanyway/payment/payanyway');
|
|
$this->addOrderHistory($this->orderId, $this->pendingOrderStatusId, $this->language->get('text_order_confirmed'),);
|
|
|
|
$json['success'] = true;
|
|
|
|
$this->response->addHeader('Content-Type: application/json');
|
|
$this->response->setOutput(json_encode($json));
|
|
}
|
|
|
|
public function success(): void
|
|
{
|
|
$this->load->language('extension/payanyway/payment/payanyway');
|
|
$this->addOrderHistory($this->orderId, $this->pendingOrderStatusId, $this->language->get('text_payment_processing'),);
|
|
$this->response->redirect($this->url->link('checkout/success', '', true));
|
|
}
|
|
|
|
public function fail(): void
|
|
{
|
|
$this->load->language('extension/payanyway/payment/payanyway');
|
|
$this->addOrderHistory($this->orderId, $this->errorOrderStatusId, $this->language->get('text_payment_error'),);
|
|
$this->response->redirect($this->url->link('checkout/failure', '', true));
|
|
}
|
|
|
|
private function getDescription(): string
|
|
{
|
|
$clientName = trim(($this->orderInfo['firstname'] ?? '') . ' ' . ($this->orderInfo['lastname'] ?? ''));
|
|
|
|
$orderId = $this->orderInfo['order_id'] ?? null;
|
|
$description = "Оплата заказа" . (!empty($orderId) ? " №{$orderId}" : '');
|
|
|
|
if ('' !== $clientName) {
|
|
$description .= " от {$clientName}";
|
|
}
|
|
|
|
$comment = $this->orderInfo['comment'] ?? '';
|
|
if ($comment !== '') {
|
|
$description .= ': ' . htmlspecialchars($comment, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
return $this->validateString($description, self::DESCRIPTION_MAX_LENGTH);
|
|
}
|
|
|
|
private function getSubscriberId(): string
|
|
{
|
|
$email = filter_var($this->orderInfo['email'] ?? '', FILTER_SANITIZE_EMAIL);
|
|
if ('' !== $email) {
|
|
return $email;
|
|
}
|
|
|
|
$phoneNumber = preg_replace('/[^0-9+]/', '', $this->orderInfo['telephone'] ?? '');
|
|
|
|
return $phoneNumber ?: '';
|
|
}
|
|
}
|