Compare commits
4 Commits
v1.0.1_pay
...
release
| Author | SHA1 | Date | |
|---|---|---|---|
| d1ac3d989b | |||
| d53430155a | |||
| f94dc40eee | |||
| c3189d2439 |
@ -4,7 +4,7 @@
|
||||

|
||||

|
||||
|
||||
> **📦 Версия модуля: 1.0.1**
|
||||
> **📦 Версия модуля: 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** | `Да` |
|
||||
| **Подпись формы оплаты обязательна** | `Да` |
|
||||
| **Код проверки целостности данных** | `ваш_код` (произвольный набор символов) |
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<modification>
|
||||
<name>PayAnyWay</name>
|
||||
<code>payanyway</code>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.3</version>
|
||||
<author>PayAnyWay</author>
|
||||
<link>https://payanyway.ru/</link>
|
||||
</modification>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
const CMS_NAME = 'OpenCart';
|
||||
const MODULE_NAME = 'payanyway';
|
||||
const MODULE_VERSION = '1.0.1';
|
||||
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
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 |
@ -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">
|
||||
|
||||
@ -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');
|
||||
|
||||
$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));
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -307,23 +309,46 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $response
|
||||
* @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
|
||||
@ -357,13 +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);
|
||||
}
|
||||
|
||||
list($resultCode, $description) = $this->determineCheckResult($callbackData);
|
||||
$responseData = $this->buildResponseData($callbackData, $resultCode, $description);
|
||||
$responseData = $this->buildBaseResponseData($callbackData, $resultCode, $description);
|
||||
|
||||
$this->sendResponse($this->buildXMLResponse($responseData));
|
||||
$products = $this->getAccountOrderProducts();
|
||||
$deliveryInfo = $this->getDeliveryInfo();
|
||||
|
||||
$responseData['client'] = $this->getClientInfo();
|
||||
$responseData['items'] = $this->getCheckItems($products, $deliveryInfo);
|
||||
|
||||
$this->sendResponse($this->buildJsonResponse($responseData));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,7 +416,7 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
);
|
||||
|
||||
if (!$this->checkSignature($shopData, $callbackData['MNT_SIGNATURE'])) {
|
||||
$this->sendResponse('FAIL');
|
||||
$this->sendResponse(self::FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
$isPayedOrder = $this->isOrderPaid();
|
||||
@ -396,9 +427,19 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
|
||||
$resultCode = 200;
|
||||
$description = $isPayedOrder ? 'Order already paid' : 'Order success paid';
|
||||
$responseData = $this->buildResponseData($callbackData, $resultCode, $description);
|
||||
$responseData = $this->buildBaseResponseData($callbackData, $resultCode, $description);
|
||||
|
||||
$this->sendResponse($this->buildXMLResponse($responseData));
|
||||
$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));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -408,14 +449,14 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
* @return array<string, mixed>
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function buildResponseData(array $callbackData, $resultCode, $description) {
|
||||
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' => $description,
|
||||
'MNT_DESCRIPTION' => $this->validateString($description, self::DESCRIPTION_MAX_LENGTH),
|
||||
'MNT_AMOUNT' => $this->formatPrice($orderTotal),
|
||||
'MNT_CURRENCY_CODE' => $callbackData['MNT_CURRENCY_CODE'],
|
||||
);
|
||||
@ -423,15 +464,6 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
$signatureSource = $resultCode . $this->mntId . $callbackData['MNT_TRANSACTION_ID'] . $this->integrityCode;
|
||||
$data['MNT_SIGNATURE'] = md5($signatureSource);
|
||||
|
||||
$this->load->model('account/order');
|
||||
$products = $this->model_account_order->getOrderProducts($this->orderId);
|
||||
$deliveryPrice = $this->getDeliveryPrice();
|
||||
|
||||
$data['inventory'] = $this->getInventoryJson($products) ?: null;
|
||||
$data['client'] = $callbackData['MNT_SUBSCRIBER_ID'];
|
||||
$data['sno'] = null;
|
||||
$data['delivery'] = (null !== $deliveryPrice) ? $this->formatPrice($deliveryPrice) : null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -448,7 +480,7 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
$orderStatus = $this->getOrderStatusById($orderStatusId);
|
||||
|
||||
if (empty($callbackData['MNT_AMOUNT'])) {
|
||||
return array(100, "Order status is '{$orderStatus}'");
|
||||
return array(100, "Order status is {$orderStatus}");
|
||||
}
|
||||
|
||||
if ($this->successOrderStatusId === $orderStatusId) {
|
||||
@ -456,7 +488,7 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
}
|
||||
|
||||
if (in_array($orderStatusId, array(7, 9, 16), true)) {
|
||||
return array(500, "Order status is '{$orderStatus}'");
|
||||
return array(500, "Order status is {$orderStatus}");
|
||||
}
|
||||
|
||||
return array(402, 'Order created, but not paid');
|
||||
@ -472,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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -489,10 +520,11 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $products
|
||||
* @param array<string, mixed> $deliveryInfo
|
||||
* @return false|string
|
||||
*/
|
||||
private function getInventoryJson(array $products) {
|
||||
if (empty($products)) {
|
||||
private function getPayInventoryJson(array $products, array $deliveryInfo) {
|
||||
if (empty($products) && empty($deliveryInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -503,19 +535,110 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
$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
|
||||
@ -547,13 +670,40 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
return rtrim(rtrim($quantityString, '0'), '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
@ -596,7 +746,46 @@ class ControllerExtensionPaymentPayanyway extends Controller {
|
||||
}
|
||||
|
||||
$xml = $dom->saveXML();
|
||||
return (false !== $xml) ? $xml : 'FAIL';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -664,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
// Text
|
||||
$_['text_locale'] = 'ru';
|
||||
$_['text_title'] = 'PayAnyWay (МИР, Visa, MasterCard и более 30-и способов оплаты)';
|
||||
$_['text_ap_pay_with'] = 'Оплатить с';
|
||||
$_['text_ap_and_other'] = 'или другой способ оплаты';
|
||||
|
||||
@ -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 %}">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user