fix: changed check response from xml to json

This commit is contained in:
2026-07-08 15:23:17 +03:00
committed by Git Moneta
parent 018f675acd
commit 6cc9866f24
11 changed files with 301 additions and 76 deletions
+63 -22
View File
@@ -4,8 +4,38 @@ declare(strict_types=1);
namespace Opencart\Catalog\Controller\Extension\PayAnyWay\Payment;
use Opencart\Catalog\Model\Account\Customer as ModelAccountCustomer;
use Opencart\Catalog\Model\Account\Order as ModelAccountOrder;
use Opencart\Catalog\Model\Checkout\Order as ModelCheckoutOrder;
use Opencart\System\Engine\Config;
use Opencart\System\Engine\Loader;
use Opencart\System\Library\Cart\Currency;
use Opencart\System\Library\Cart\Customer;
use Opencart\System\Library\Document;
use Opencart\System\Library\Language;
use Opencart\System\Library\Request;
use Opencart\System\Library\Response;
use Opencart\System\Library\Session;
use Opencart\System\Library\Url;
require_once DIR_EXTENSION . '/payanyway/catalog/library/payanyway/traits/payanyway.php';
/**
* @property Config $config
* @property Loader $load
* @property Request $request
* @property Response $response
* @property Document $document
* @property Session $session
* @property Language $language
* @property Url $url
* @property Currency $currency
* @property ModelCheckoutOrder $model_checkout_order
* @property ModelAccountOrder $model_account_order
* @property ModelAccountCustomer $model_account_customer
* @property Customer $customer
*/
class PayAnyWay extends \Opencart\System\Engine\Controller
{
use \Opencart\Catalog\Library\Extension\PayAnyWay\Traits\PayAnyWay;
@@ -13,7 +43,8 @@ class PayAnyWay extends \Opencart\System\Engine\Controller
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;
public const DESCRIPTION_MAX_LENGTH = 500;
private int $mntId;
private string $integrityCode;
@@ -71,14 +102,16 @@ class PayAnyWay extends \Opencart\System\Engine\Controller
$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,);
$customerToken = $this->session->data['customer_token'];
$data['MNT_SUCCESS_URL'] = $this->url->link('extension/payanyway/payment/payanyway.success', 'customer_token=' . $customerToken, true);
$data['MNT_FAIL_URL'] = $this->url->link('extension/payanyway/payment/payanyway.fail', 'customer_token=' . $customerToken, true);
$data['MNT_RETURN_URL'] = $this->url->link('checkout/checkout', 'customer_token=' . $customerToken, true);
$data['moneta_locale'] = $this->language->get('text_locale');
$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,);
$data['confirm_url'] = $this->url->link('extension/payanyway/payment/payanyway.confirm', 'customer_token=' . $customerToken, true,);
return $this->load->view('extension/payanyway/payment/payanyway', $data);
}
@@ -86,7 +119,11 @@ class PayAnyWay extends \Opencart\System\Engine\Controller
public function confirm(): void
{
$this->load->language('extension/payanyway/payment/payanyway');
$this->addOrderHistory($this->orderId, $this->pendingOrderStatusId, $this->language->get('text_order_confirmed'),);
$orderStatusId = isset($this->orderInfo['order_status_id']) ? (int)$this->orderInfo['order_status_id'] : null;
if ((null !== $orderStatusId) && ($orderStatusId !== $this->successOrderStatusId)) {
$this->addOrderHistory($this->orderId, $this->pendingOrderStatusId, $this->language->get('text_order_confirmed'),);
}
$json['success'] = true;
@@ -97,30 +134,41 @@ class PayAnyWay extends \Opencart\System\Engine\Controller
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));
$orderStatusId = isset($this->orderInfo['order_status_id']) ? (int)$this->orderInfo['order_status_id'] : null;
if ((null !== $orderStatusId) && ($orderStatusId !== $this->successOrderStatusId)) {
$this->addOrderHistory($this->orderId, $this->pendingOrderStatusId, $this->language->get('text_payment_processing'));
}
$customerToken = $this->request->get['customer_token'] ?? '';
$this->response->redirect($this->url->link('checkout/success', 'customer_token=' . $customerToken, true));
}
public function fail(): void
{
$this->load->language('extension/payanyway/payment/payanyway');
$this->addOrderHistory($this->orderId, $this->errorOrderStatusId, $this->language->get('text_payment_error'),);
$orderStatusId = isset($this->orderInfo['order_status_id']) ? (int)$this->orderInfo['order_status_id'] : null;
if ((null !== $orderStatusId) && ($orderStatusId !== $this->successOrderStatusId)) {
$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}";
$name = $this->getClientName();
if (null !== $name) {
$description .= " от {$name}";
}
$comment = $this->orderInfo['comment'] ?? '';
if ($comment !== '') {
if ('' !== $comment) {
$description .= ': ' . htmlspecialchars($comment, ENT_QUOTES, 'UTF-8');
}
@@ -129,13 +177,6 @@ class PayAnyWay extends \Opencart\System\Engine\Controller
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 ?: '';
return $this->getClientEmail() ?? $this->getClientPhone() ?? '';
}
}