3
0

Compare commits

...

6 Commits

Author SHA1 Message Date
d1ac3d989b
Merge branch 'main' into 'release'
fix: changed check response from xml to json

See merge request products/cashier/cms/OpenCart3!12
2026-07-07 19:19:14 +03:00
d53430155a
fix: changed check response from xml to json 2026-07-07 19:19:14 +03:00
f94dc40eee
Merge branch 'feature/merge-main-to-release' into 'release'
Feature/merge main to release

See merge request products/cashier/cms/OpenCart3!10
2026-07-03 15:11:52 +03:00
c3189d2439
Feature/merge main to release 2026-07-03 15:11:52 +03:00
83f1d8d101
Merge branch 'main' into 'release'
feat: refactor callback

See merge request products/cashier/cms/OpenCart3!6
2026-05-19 18:13:11 +03:00
1e168ded8c
feat: refactor callback 2026-05-19 18:13:11 +03:00
9 changed files with 341 additions and 144 deletions

View File

@ -4,7 +4,7 @@
![PHP](https://img.shields.io/badge/PHP-5.6%2B-purple)
![License](https://img.shields.io/badge/License-MIT-green)
> **📦 Версия модуля: 1.0.0**
> **📦 Версия модуля: 1.0.3**
> ** Совместимость версий OpenCart:**
> 3.0.0.0, 3.0.1.1, 3.0.1.2, 3.0.2.0, 3.0.3.0, 3.0.3.1, 3.0.3.2, 3.0.3.3, 3.0.3.4, 3.0.3.5, 3.0.3.6, 3.0.3.7, 3.0.3.8, 3.0.3.9, 3.0.4.0, 3.0.4.1, 3.0.5.0
@ -76,7 +76,7 @@
| **Тестовый режим** | `Нет` |
| **Check URL** | `https://your_site_name/index.php?route=extension/payment/payanyway/callback` |
| **Pay URL** | `https://your_site_name/index.php?route=extension/payment/payanyway/callback` |
| **HTTP method** | `GET` / `POST` |
| **HTTP method** | `GET` |
| **Можно переопределять настройки в URL** | `Да` |
| **Подпись формы оплаты обязательна** | `Да` |
| **Код проверки целостности данных** | аш_код` (произвольный набор символов) |

View File

@ -2,7 +2,7 @@
<modification>
<name>PayAnyWay</name>
<code>payanyway</code>
<version>1.0.0</version>
<version>1.0.3</version>
<author>PayAnyWay</author>
<link>https://payanyway.ru/</link>
</modification>

View File

@ -9,7 +9,7 @@
class ControllerExtensionPaymentPayanyway extends Controller {
const CMS_NAME = 'OpenCart';
const MODULE_NAME = 'payanyway';
const MODULE_VERSION = '1.0.0';
const MODULE_VERSION = '1.0.3';
const MODULE_DEFAULT_SORT_ORDER = 0;
private $supportedCurrencies = array('RUB');
@ -289,9 +289,10 @@ class ControllerExtensionPaymentPayanyway extends Controller {
$cmsName = $this->detectCmsByPatterns($textFooter);
$cmsVersion = defined('VERSION') ? constant('VERSION') : '.unknown';
return sprintf('%s v%s | %s v%s',
return sprintf('%s v%s|PHP %s|%s v%s',
$cmsName,
$cmsVersion,
PHP_VERSION,
self::MODULE_NAME,
self::MODULE_VERSION
);

BIN
upload/admin/view/image/payment/payanyway.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -27,7 +27,7 @@
</div>
<div class="panel-heading text-center">
<a href="https://www.payanyway.ru/" target="_blank">
<img src="view/image/payment/payanyway.png" alt="PayAnyWay" title="PayAnyWay" width="250" height="29"/>
<img src="view/image/payment/payanyway.png" alt="PayAnyWay" title="PayAnyWay" width="336" height="50"/>
</a>
</div>
<div class="panel-body">

View File

@ -10,13 +10,20 @@ class ControllerExtensionPaymentPayanyway extends Controller {
const PAYMENT_URL_PROD = 'https://www.payanyway.ru/assistant.htm';
const PAYMENT_URL_DEMO = 'https://demo.moneta.ru/assistant.htm';
const FAIL_RESPONSE = 'FAIL';
const XML_CONTENT_TYPE = 'application/xml';
const JSON_CONTENT_TYPE = 'application/json';
const TEXT_CONTENT_TYPE = 'text/plain; charset=UTF-8';
const TRANSACTION_ID_STRING_DELIMITER = '|';
const DESCRIPTION_MAX_LENGTH = 500;
const INVENTORY_ITEM_NAME_MAX_LENGTH = 128;
const INVENTORY_ITEM_DEFAULT_PAYMENT_METHOD = 'full_payment';
const INVENTORY_ITEM_DEFAULT_PAYMENT_OBJECT = 'commodity';
const INVENTORY_ITEM_DEFAULT_MEASURE = 'unit';
const CLIENT_NAME_MAX_LENGTH = 256;
const ITEM_NAME_MAX_LENGTH = 128;
const DEFAULT_PAYMENT_METHOD = 'full_payment';
const DEFAULT_PAYMENT_OBJECT = 'commodity';
const SHIPPING_PAYMENT_OBJECT = 'service';
const DEFAULT_MEASURE = 'unit';
/** @var int */
private $mntId;
@ -91,14 +98,15 @@ class ControllerExtensionPaymentPayanyway extends Controller {
$this->integrityCode
);
$data['MNT_SIGNATURE'] = $signature;
$data['MNT_SUCCESS_URL'] = $this->url->link('extension/payment/payanyway/success', 'language=' . $this->config->get('config_language'), true);
$data['MNT_FAIL_URL'] = $this->url->link('extension/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_SUCCESS_URL'] = $this->url->link('extension/payment/payanyway/success', '', true);
$data['MNT_FAIL_URL'] = $this->url->link('extension/payment/payanyway/fail', '', true);
$data['MNT_RETURN_URL'] = $this->url->link('checkout/checkout', '', 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/payment/payanyway/confirm', 'language=' . $this->config->get('config_language'), true);
$data['confirm_url'] = $this->url->link('extension/payment/payanyway/confirm', '', true);
return $this->load->view('extension/payment/payanyway', $data);
}
@ -125,7 +133,11 @@ class ControllerExtensionPaymentPayanyway extends Controller {
*/
public function success() {
$this->load->language('extension/payment/payanyway');
$this->addOrderHistory($this->pendingOrderStatusId, $this->language->get('text_payment_processing'));
$orderStatusId = isset($this->orderInfo['order_status_id']) ? (int)$this->orderInfo['order_status_id'] : null;
if ((null !== $orderStatusId) && ($orderStatusId !== $this->successOrderStatusId)) {
$this->addOrderHistory($this->pendingOrderStatusId, $this->language->get('text_payment_processing'));
}
$this->response->redirect($this->url->link('checkout/success', '', true));
}
@ -166,7 +178,7 @@ class ControllerExtensionPaymentPayanyway extends Controller {
/** @return string */
private function createTransactionId() {
$date = (new \DateTimeImmutable())->format('YmdHis');
$date = date('YmdHis');
return $this->orderId . self::TRANSACTION_ID_STRING_DELIMITER . $date;
}
@ -180,14 +192,11 @@ class ControllerExtensionPaymentPayanyway extends Controller {
/** @return string */
private function getDescription() {
$clientFirstName = isset($this->orderInfo['firstname']) ? $this->orderInfo['firstname'] : '';
$clientLastName = isset($this->orderInfo['lastname']) ? $this->orderInfo['lastname'] : '';
$clientName = trim($clientFirstName . ' ' . $clientLastName);
$orderId = isset($this->orderInfo['order_id']) ? $this->orderInfo['order_id'] : null;
$description = "Оплата заказа" . (!empty($orderId) ? "{$orderId}" : '');
if ('' !== $clientName) {
$clientName = $this->getClientName();
if (null !== $clientName) {
$description .= " от {$clientName}";
}
@ -230,16 +239,14 @@ class ControllerExtensionPaymentPayanyway extends Controller {
/** @return string */
private function getSubscriberId() {
$email = isset($this->orderInfo['email'])
? filter_var($this->orderInfo['email'], FILTER_SANITIZE_EMAIL)
: '';
if ('' !== $email) {
$email = $this->getClientEmail();
if (null !== $email) {
return $email;
}
return isset($this->orderInfo['telephone'])
? preg_replace('/[^0-9+]/', '', $this->orderInfo['telephone'])
: '';
$phone = $this->getClientPhone();
return (null !== $phone) ? $phone : '';
}
/**
@ -258,19 +265,14 @@ class ControllerExtensionPaymentPayanyway extends Controller {
* @throws \Exception
*/
public function callback() {
if (null === $this->orderId) {
$this->sendResponse('FAIL');
}
if (false === $this->orderInfo) {
$this->sendResponse('FAIL');
}
$requestData = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET;
$callbackData = $this->getCallbackData($requestData);
$callback = $this->getCallbackData($requestData);
(isset($callbackData['MNT_COMMAND'])) && ('CHECK' === $callbackData['MNT_COMMAND'])
? $this->handleCheckCallback($callbackData)
: $this->handlePayCallback($callbackData);
$this->validateCallback($callback);
(isset($callback['MNT_COMMAND'])) && ('CHECK' === $callback['MNT_COMMAND'])
? $this->handleCheckCallback($callback)
: $this->handlePayCallback($callback);
}
/**
@ -296,7 +298,7 @@ class ControllerExtensionPaymentPayanyway extends Controller {
if (!isset($_REQUEST['MNT_TRANSACTION_ID'])) {
return null;
}
$transactionIdData = explode(self::TRANSACTION_ID_STRING_DELIMITER, $_REQUEST['MNT_TRANSACTION_ID']);
$transactionIdData = explode(self::TRANSACTION_ID_STRING_DELIMITER, $_REQUEST['MNT_TRANSACTION_ID'], 2);
return isset($transactionIdData[0]) ? (int)$transactionIdData[0] : null;
}
@ -307,23 +309,46 @@ class ControllerExtensionPaymentPayanyway extends Controller {
}
/**
* @param string $response
* @param int $statusCode
* @param array|string $response
* @param int $statusCode
* @return void
*/
private function sendResponse($response, $statusCode = 200) {
private function sendResponse($response, $statusCode = 200)
{
http_response_code($statusCode);
if (strpos($response, '<?xml') === 0 || strpos($response, '<MNT_RESPONSE') !== false) {
header('Content-Type: application/xml');
if (is_string($response)) {
header('Content-Type: ' . self::TEXT_CONTENT_TYPE);
echo $response;
} else {
header('Content-Type: text/plain; charset=UTF-8');
header('Content-Type: ' . $response['contentType']);
echo $response['data'];
}
echo $response;
exit();
}
/**
* @param array $callback
* @return void
*/
private function validateCallback(array $callback)
{
if (null === $this->orderId) {
$this->sendResponse(self::FAIL_RESPONSE);
}
if (false === $this->orderInfo) {
$this->sendResponse(self::FAIL_RESPONSE);
}
if (empty($this->mntId) || empty($this->integrityCode)) {
$this->sendResponse(self::FAIL_RESPONSE);
}
if ($this->mntId !== (int)$callback['MNT_ID']) {
$this->sendResponse(self::FAIL_RESPONSE);
}
}
/**
* @param array<string, mixed> $data
* @return bool
@ -343,7 +368,7 @@ class ControllerExtensionPaymentPayanyway extends Controller {
? array_merge(['MNT_COMMAND'], $baseFields)
: $baseFields;
$signatureString = array_reduce($fields, static function ($carry, $field) use ($data) {
$signatureString = array_reduce($fields, function ($carry, $field) use ($data) {
return $carry . $data[$field];
}, '') . $this->integrityCode;
@ -357,62 +382,19 @@ class ControllerExtensionPaymentPayanyway extends Controller {
*/
private function handleCheckCallback(array $callbackData) {
if (!$this->checkSignature($callbackData, $callbackData['MNT_SIGNATURE'])) {
$this->sendResponse('FAIL');
$this->sendResponse(self::FAIL_RESPONSE);
}
$this->load->model('account/order');
$products = $this->model_account_order->getOrderProducts($this->orderId);
$deliveryPrice = $this->getDeliveryPrice();
list($resultCode, $description) = $this->determineCheckResult($callbackData);
$responseData = $this->buildBaseResponseData($callbackData, $resultCode, $description);
$orderTotal = (float)(isset($this->orderInfo['total']) ? $this->orderInfo['total'] : 0);
$products = $this->getAccountOrderProducts();
$deliveryInfo = $this->getDeliveryInfo();
$xmlData = array(
'MNT_ID' => $this->mntId,
'MNT_TRANSACTION_ID' => $callbackData['MNT_TRANSACTION_ID'],
'MNT_AMOUNT' => $this->formatPrice($orderTotal),
'MNT_CURRENCY_CODE' => $callbackData['MNT_CURRENCY_CODE'],
'inventory' => $this->getInventoryJson($products) ?: null,
'client' => $callbackData['MNT_SUBSCRIBER_ID'],
'sno' => null,
'delivery' => (null !== $deliveryPrice) ? $this->formatPrice($deliveryPrice) : null,
);
$responseData['client'] = $this->getClientInfo();
$responseData['items'] = $this->getCheckItems($products, $deliveryInfo);
$orderStatusId = (int)(isset($this->orderInfo['order_status_id']) ? $this->orderInfo['order_status_id'] : 1);
list($xmlData['MNT_RESULT_CODE'], $xmlData['MNT_DESCRIPTION']) = $this->determineCheckResult($callbackData, $orderStatusId);
$xmlData['MNT_SIGNATURE'] = md5(
$xmlData['MNT_RESULT_CODE'] .
$xmlData['MNT_ID'] .
$xmlData['MNT_TRANSACTION_ID'] .
$this->integrityCode
);
$this->sendResponse($this->buildXMLResponse($xmlData));
}
/**
* @param array<string, mixed> $callbackData
* @param int $orderStatusId
* @return array
* @throws \Exception
*/
private function determineCheckResult(array $callbackData, $orderStatusId) {
$orderStatus = $this->getOrderStatusById($orderStatusId);
if (empty($callbackData['MNT_AMOUNT'])) {
return array(100, "Order status is '{$orderStatus}'");
}
if ($this->successOrderStatusId === $orderStatusId) {
return array(200, 'Order Paid');
}
if (in_array($orderStatusId, array(7, 9, 16), true)) {
return array(500, "Order status is '{$orderStatus}'");
}
return array(402, 'Order created, but not paid');
$this->sendResponse($this->buildJsonResponse($responseData));
}
/**
@ -422,7 +404,6 @@ class ControllerExtensionPaymentPayanyway extends Controller {
*/
private function handlePayCallback(array $callbackData) {
$orderTotal = (float)(isset($this->orderInfo['total']) ? $this->orderInfo['total'] : 0);
$currencyCode = isset($this->orderInfo['currency_code']) ? $this->orderInfo['currency_code'] : 'RUB';
$shopData = array(
'MNT_ID' => $this->mntId,
@ -435,37 +416,82 @@ class ControllerExtensionPaymentPayanyway extends Controller {
);
if (!$this->checkSignature($shopData, $callbackData['MNT_SIGNATURE'])) {
$this->sendResponse('FAIL');
$this->sendResponse(self::FAIL_RESPONSE);
}
$isPayedOrder = $this->isOrderPaid();
$resultCode = 200;
$this->load->model('account/order');
$products = $this->model_account_order->getOrderProducts($this->orderId);
$deliveryPrice = $this->getDeliveryPrice();
$xmlData = array(
'MNT_ID' => $this->mntId,
'MNT_TRANSACTION_ID' => $callbackData['MNT_TRANSACTION_ID'],
'MNT_RESULT_CODE' => $resultCode,
'MNT_SIGNATURE' => md5($resultCode . $this->mntId . $callbackData['MNT_TRANSACTION_ID'] . $this->integrityCode),
'MNT_AMOUNT' => $callbackData['MNT_AMOUNT'],
'MNT_CURRENCY_CODE' => $callbackData['MNT_CURRENCY_CODE'],
'MNT_DESCRIPTION' => $isPayedOrder ? 'Order already paid' : 'Order success paid',
'inventory' => $this->getInventoryJson($products),
'client' => $callbackData['MNT_SUBSCRIBER_ID'],
'sno' => null,
'delivery' => $deliveryPrice !== null ? $this->formatPrice($deliveryPrice) : null,
);
if (!$isPayedOrder) {
$this->load->language('extension/payment/payanyway');
$this->addOrderHistory($this->successOrderStatusId, $this->language->get('text_payment_completed'));
}
$this->sendResponse($this->buildXMLResponse($xmlData));
$resultCode = 200;
$description = $isPayedOrder ? 'Order already paid' : 'Order success paid';
$responseData = $this->buildBaseResponseData($callbackData, $resultCode, $description);
$products = $this->getAccountOrderProducts();
$deliveryInfo = $this->getDeliveryInfo();
$payInventoryJson = $this->getPayInventoryJson($products, $deliveryInfo);
$responseData['inventory'] = $payInventoryJson ?: null;
$clientInfo = $this->getClientInfo();
$responseData['client'] = $clientInfo
? json_encode([$clientInfo], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
: null;
$this->sendResponse($this->buildXmlResponse($responseData));
}
/**
* @param array $callbackData
* @param int $resultCode
* @param string $description
* @return array<string, mixed>
* @throws \Exception
*/
private function buildBaseResponseData(array $callbackData, $resultCode, $description) {
$orderTotal = (float)(isset($this->orderInfo['total']) ? $this->orderInfo['total'] : 0);
$data = array(
'MNT_ID' => $this->mntId,
'MNT_TRANSACTION_ID' => $callbackData['MNT_TRANSACTION_ID'],
'MNT_RESULT_CODE' => $resultCode,
'MNT_DESCRIPTION' => $this->validateString($description, self::DESCRIPTION_MAX_LENGTH),
'MNT_AMOUNT' => $this->formatPrice($orderTotal),
'MNT_CURRENCY_CODE' => $callbackData['MNT_CURRENCY_CODE'],
);
$signatureSource = $resultCode . $this->mntId . $callbackData['MNT_TRANSACTION_ID'] . $this->integrityCode;
$data['MNT_SIGNATURE'] = md5($signatureSource);
return $data;
}
/**
* @param array<string, mixed> $callbackData
* @return array<int|string>
* @throws \Exception
*/
private function determineCheckResult(array $callbackData) {
$orderStatusId = isset($this->orderInfo['order_status_id']) ? (int)$this->orderInfo['order_status_id'] : null;
if (null === $orderStatusId) {
return array(500, 'Order status not set');
}
$orderStatus = $this->getOrderStatusById($orderStatusId);
if (empty($callbackData['MNT_AMOUNT'])) {
return array(100, "Order status is {$orderStatus}");
}
if ($this->successOrderStatusId === $orderStatusId) {
return array(200, 'Order Paid');
}
if (in_array($orderStatusId, array(7, 9, 16), true)) {
return array(500, "Order status is {$orderStatus}");
}
return array(402, 'Order created, but not paid');
}
/** @return bool */
@ -478,15 +504,14 @@ class ControllerExtensionPaymentPayanyway extends Controller {
}
/**
* @return float|null
* @return array
* @throws \Exception
*/
private function getDeliveryPrice() {
private function getDeliveryInfo() {
$this->load->model('account/order');
foreach ($this->model_account_order->getOrderTotals($this->orderId) as $orderTotal) {
if (isset($orderTotal['code']) && ($orderTotal['code'] === 'shipping')) {
$deliveryPrice = isset($orderTotal['value']) ? (float)$orderTotal['value'] : 0;
return ($deliveryPrice !== 0.0) ? $deliveryPrice : null;
return $orderTotal;
}
}
@ -495,29 +520,125 @@ class ControllerExtensionPaymentPayanyway extends Controller {
/**
* @param array<string, mixed> $products
* @param array<string, mixed> $deliveryInfo
* @return false|string
*/
private function getInventoryJson(array $products) {
private function getPayInventoryJson(array $products, array $deliveryInfo) {
if (empty($products) && empty($deliveryInfo)) {
return false;
}
$inventory = array();
foreach ($products as $product) {
$name = isset($product['name']) ? $product['name'] : '';
$price = isset($product['price']) ? (float)$product['price'] : 0;
$quantity = isset($product['quantity']) ? (string)$product['quantity'] : '0';
$quantity = isset($product['quantity']) ? (float)$product['quantity'] : 0;
$inventory[] = array(
'name' => $this->validateString($name, self::INVENTORY_ITEM_NAME_MAX_LENGTH),
'name' => $this->validateString($name, self::ITEM_NAME_MAX_LENGTH),
'price' => $this->formatPrice($price),
'quantity' => $this->formatQuantity($quantity),
'vatTag' => $this->vatRate,
'pm' => self::INVENTORY_ITEM_DEFAULT_PAYMENT_METHOD,
'po' => self::INVENTORY_ITEM_DEFAULT_PAYMENT_OBJECT,
'measure' => self::INVENTORY_ITEM_DEFAULT_MEASURE,
'pm' => self::DEFAULT_PAYMENT_METHOD,
'po' => self::DEFAULT_PAYMENT_OBJECT,
'measure' => self::DEFAULT_MEASURE,
);
}
$name = isset($deliveryInfo['title']) ? $deliveryInfo['title'] : '';
$price = isset($deliveryInfo['value']) ? (float)$deliveryInfo['value'] : 0;
$inventory[] = array(
'name' => $this->validateString($name, self::ITEM_NAME_MAX_LENGTH),
'price' => $this->formatPrice($price),
'quantity' => '1',
'vatTag' => $this->vatRate,
'pm' => self::DEFAULT_PAYMENT_METHOD,
'po' => self::SHIPPING_PAYMENT_OBJECT,
'measure' => self::DEFAULT_MEASURE,
);
return json_encode($inventory, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
/** @return array */
private function getClientInfo() {
$clientInfo = array();
$name = $this->getClientName();
if (null !== $name) {
$clientInfo['name'] = $name;
}
$email = $this->getClientEmail();
if (null !== $email) {
$clientInfo['email'] = $email;
}
$phoneNumber = $this->getClientPhone();
if (null !== $phoneNumber) {
$clientInfo['phone'] = $phoneNumber;
}
return $clientInfo;
}
/**
* @param array<string, mixed> $products
* @param array<string, mixed> $deliveryInfo
* @return non-empty-array
*/
private function getCheckItems(array $products, array $deliveryInfo) {
$checkItems = array();
foreach ($products as $product) {
$name = isset($product['name']) ? $product['name'] : '';
$price = isset($product['price']) ? (float)$product['price'] : 0;
$quantity = isset($product['quantity']) ? (float)$product['quantity'] : 0;
$checkItems[] = array(
'name' => $this->validateString($name, self::ITEM_NAME_MAX_LENGTH),
'price' => $this->formatPrice($price),
'quantity' => $quantity,
'vat' => $this->getVat($this->vatRate),
'measure' => self::DEFAULT_MEASURE,
'paymentMethod' => self::DEFAULT_PAYMENT_METHOD,
'paymentObject' => self::DEFAULT_PAYMENT_OBJECT,
);
}
$name = isset($deliveryInfo['title']) ? $deliveryInfo['title'] : '';
$price = isset($deliveryInfo['value']) ? (float)$deliveryInfo['value'] : 0;
$checkItems[] = array(
'name' => $this->validateString($name, self::ITEM_NAME_MAX_LENGTH),
'price' => $this->formatPrice($price),
'quantity' => 1,
'vat' => $this->getVat($this->vatRate),
'measure' => self::DEFAULT_MEASURE,
'paymentMethod' => self::DEFAULT_PAYMENT_METHOD,
'paymentObject' => self::SHIPPING_PAYMENT_OBJECT,
);
return $checkItems;
}
/**
* @param string $vatRate
* @return string
*/
public function getVat($vatRate) {
$map = array(
'1104' => 'vat0',
'1108' => 'vat5',
'1109' => 'vat7',
'1103' => 'vat10',
'7000' => 'vat20',
'1113' => 'vat22',
'1110' => 'vat105',
'1111' => 'vat107',
'1107' => 'vat110',
'7001' => 'vat120',
'1114' => 'vat122',
);
return isset($map[$vatRate]) ? $map[$vatRate] : 'none';
}
/**
* @param int $orderStatusId
* @return string
@ -541,25 +662,48 @@ class ControllerExtensionPaymentPayanyway extends Controller {
}
/**
* @param string $quantity
* @param float $quantity
* @return string
*/
private function formatQuantity($quantity) {
$quantity = str_replace(',', '.', $quantity);
if (strpos($quantity, '.') === false && ctype_digit($quantity)) {
return (string)(int)$quantity;
}
$quantityString = number_format($quantity, 3, '.', '');
return rtrim(rtrim($quantityString, '0'), '.');
}
return number_format((float)$quantity, 3, '.', '');
/**
* @param array<non-empty-string, mixed> $data
* @return array
* @throws \JsonException
*/
public function buildJsonResponse(array $data) {
$jsonData = array(
'id' => $data['MNT_ID'],
'transactionId' => $data['MNT_TRANSACTION_ID'],
'amount' => $data['MNT_AMOUNT'],
'signature' => $data['MNT_SIGNATURE'],
'resultCode' => $data['MNT_RESULT_CODE'],
'description' => $data['MNT_DESCRIPTION'],
'externalId' => $data['MNT_TRANSACTION_ID'],
'receipt' => array(
'client' => $data['client'],
'items' => $data['items'],
),
);
$json = json_encode($jsonData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
return array(
'data' => $json ?: '',
'contentType' => self::JSON_CONTENT_TYPE,
);
}
/**
* @param array<string, mixed> $data
* @return false|string
* @return bool|string
* @return array
* @throws \Exception
*/
private function buildXMLResponse(array $data) {
private function buildXmlResponse(array $data) {
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = false;
@ -601,7 +745,47 @@ class ControllerExtensionPaymentPayanyway extends Controller {
}
}
return $dom->saveXML();
$xml = $dom->saveXML();
return array(
'data' => (false !== $xml) ? $xml : self::FAIL_RESPONSE,
'contentType' => (false !== $xml) ? self::XML_CONTENT_TYPE : self::TEXT_CONTENT_TYPE,
);
}
/**
* @return non-empty-string|null
*/
private function getClientName()
{
$firstname = isset($this->orderInfo['firstname']) ? $this->orderInfo['firstname'] : '';
$lastname = isset($this->orderInfo['lastname']) ? $this->orderInfo['lastname'] : '';
$name = trim($firstname . ' ' . $lastname);
return ('' !== $name) ? $this->validateString($name, self::CLIENT_NAME_MAX_LENGTH) : null;
}
/**
* @return non-empty-string|null
*/
private function getClientEmail()
{
$email = isset($this->orderInfo['email']) ? $this->orderInfo['email'] : '';
$email = trim((string)$email);
return ('' !== $email) ? filter_var($email, FILTER_SANITIZE_EMAIL) : null;
}
/**
* @return non-empty-string|null
*/
private function getClientPhone()
{
$telephone = isset($this->orderInfo['telephone']) ? $this->orderInfo['telephone'] : '';
$digits = preg_replace('/\D/', '', trim((string)$telephone));
return ('' !== $digits) ? '+' . $digits : null;
}
/**
@ -669,4 +853,13 @@ class ControllerExtensionPaymentPayanyway extends Controller {
$this->errorOrderStatusId = (int)$this->config->get('payment_payanyway_error_order_status_id');
$this->cmsModuleVersion = (string)$this->config->get('payment_payanyway_cms_module_version');
}
/**
* @return array
* @throws \Exception
*/
public function getAccountOrderProducts() {
$this->load->model('account/order');
return $this->model_account_order->getOrderProducts($this->orderId);
}
}

View File

@ -1,5 +1,6 @@
<?php
// Text
$_['text_locale'] = 'en';
$_['text_title'] = 'PayAnyWay (MIR, VISA, MasterCard and 30+ other ways)';
$_['text_ap_pay_with'] = 'Pay with';
$_['text_ap_and_other'] = 'or another payment method';

View File

@ -1,5 +1,6 @@
<?php
// Text
$_['text_locale'] = 'ru';
$_['text_title'] = 'PayAnyWay (МИР, Visa, MasterCard и более 30-и способов оплаты)';
$_['text_ap_pay_with'] = 'Оплатить с';
$_['text_ap_and_other'] = 'или другой способ оплаты';

View File

@ -10,6 +10,7 @@
<input type="hidden" name="MNT_SUCCESS_URL" value="{{ MNT_SUCCESS_URL }}"/>
<input type="hidden" name="MNT_FAIL_URL" value="{{ MNT_FAIL_URL }}"/>
<input type="hidden" name="MNT_RETURN_URL" value="{{ MNT_RETURN_URL }}"/>
<input type="hidden" name="moneta.locale" value="{{ moneta_locale }}"/>
<input type="hidden" name="MNT_CMS" value="{{ MNT_CMS }}"/>
<div class="buttons">
<div class="{% if ap_use %} text-center {% else %} pull-right {% endif %}">