|
|
|
@@ -92,39 +92,21 @@ class Callback extends \Opencart\System\Engine\Controller
|
|
|
|
|
$this->sendResponse('FAIL');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->load->model('account/order');
|
|
|
|
|
$products = $this->model_account_order->getProducts($this->orderId);
|
|
|
|
|
$deliveryPrice = $this->getDeliveryPrice();
|
|
|
|
|
[$resultCode, $description] = $this->determineCheckResult();
|
|
|
|
|
$responseData = $this->buildResponseData($resultCode, $description);
|
|
|
|
|
|
|
|
|
|
$xmlData = [
|
|
|
|
|
'MNT_ID' => $this->mntId,
|
|
|
|
|
'MNT_TRANSACTION_ID' => $this->callbackData['MNT_TRANSACTION_ID'],
|
|
|
|
|
'MNT_AMOUNT' => $this->formatPrice((float)($this->orderInfo['total'] ?? 0)),
|
|
|
|
|
'MNT_CURRENCY_CODE' => $this->callbackData['MNT_CURRENCY_CODE'],
|
|
|
|
|
'inventory' => $this->getInventoryJson($products) ?: null,
|
|
|
|
|
'client' => $this->callbackData['MNT_SUBSCRIBER_ID'],
|
|
|
|
|
'sno' => null,
|
|
|
|
|
'delivery' => (null !== $deliveryPrice) ? $this->formatPrice($deliveryPrice) : null,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
[$xmlData['MNT_RESULT_CODE'], $xmlData['MNT_DESCRIPTION']] = $this->determineCheckResult();
|
|
|
|
|
|
|
|
|
|
$xmlData['MNT_SIGNATURE'] = md5(
|
|
|
|
|
$xmlData['MNT_RESULT_CODE'] .
|
|
|
|
|
$xmlData['MNT_ID'] .
|
|
|
|
|
$xmlData['MNT_TRANSACTION_ID'] .
|
|
|
|
|
$this->integrityCode,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->sendResponse($this->buildXMLResponse($xmlData));
|
|
|
|
|
$this->sendResponse($this->buildXMLResponse($responseData));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @throws \Exception */
|
|
|
|
|
/**
|
|
|
|
|
* @return array<int|string>
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
private function determineCheckResult(): array
|
|
|
|
|
{
|
|
|
|
|
$orderStatusId = isset($this->orderInfo['order_status_id']) ? (int)$this->orderInfo['order_status_id'] : null;
|
|
|
|
|
if (null === $orderStatusId) {
|
|
|
|
|
return [500, "Order status not set"];
|
|
|
|
|
return [500, 'Order status not set'];
|
|
|
|
|
}
|
|
|
|
|
$orderStatus = $this->getOrderStatusById($orderStatusId);
|
|
|
|
|
|
|
|
|
@@ -150,8 +132,8 @@ class Callback extends \Opencart\System\Engine\Controller
|
|
|
|
|
'MNT_ID' => $this->mntId,
|
|
|
|
|
'MNT_TRANSACTION_ID' => $this->callbackData['MNT_TRANSACTION_ID'],
|
|
|
|
|
'MNT_OPERATION_ID' => $this->callbackData['MNT_OPERATION_ID'],
|
|
|
|
|
'MNT_AMOUNT' => $this->formatPrice((float)$this->orderInfo['total']),
|
|
|
|
|
'MNT_CURRENCY_CODE' => $this->orderInfo['currency_code'],
|
|
|
|
|
'MNT_AMOUNT' => $this->formatPrice((float)($this->orderInfo['total'] ?? 0)),
|
|
|
|
|
'MNT_CURRENCY_CODE' => $this->orderInfo['currency_code'] ?? 'RUB',
|
|
|
|
|
'MNT_SUBSCRIBER_ID' => $this->callbackData['MNT_SUBSCRIBER_ID'],
|
|
|
|
|
'MNT_TEST_MODE' => $this->callbackData['MNT_TEST_MODE'],
|
|
|
|
|
];
|
|
|
|
@@ -161,32 +143,50 @@ class Callback extends \Opencart\System\Engine\Controller
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$isPayedOrder = $this->isOrderPaid();
|
|
|
|
|
$resultCode = 200;
|
|
|
|
|
|
|
|
|
|
$this->load->model('account/order');
|
|
|
|
|
$products = $this->model_account_order->getProducts($this->orderId);
|
|
|
|
|
$deliveryPrice = $this->getDeliveryPrice();
|
|
|
|
|
|
|
|
|
|
$xmlData = [
|
|
|
|
|
'MNT_ID' => $this->mntId,
|
|
|
|
|
'MNT_TRANSACTION_ID' => $this->callbackData['MNT_TRANSACTION_ID'],
|
|
|
|
|
'MNT_RESULT_CODE' => $resultCode,
|
|
|
|
|
'MNT_SIGNATURE' => md5($resultCode . $this->mntId . $this->callbackData['MNT_TRANSACTION_ID'] . $this->integrityCode),
|
|
|
|
|
'MNT_AMOUNT' => $this->callbackData['MNT_AMOUNT'],
|
|
|
|
|
'MNT_CURRENCY_CODE' => $this->callbackData['MNT_CURRENCY_CODE'],
|
|
|
|
|
'MNT_DESCRIPTION' => $isPayedOrder ? 'Order already paid' : 'Order success paid',
|
|
|
|
|
'inventory' => $this->getInventoryJson($products),
|
|
|
|
|
'client' => $this->callbackData['MNT_SUBSCRIBER_ID'],
|
|
|
|
|
'sno' => null,
|
|
|
|
|
'delivery' => $deliveryPrice !== null ? $this->formatPrice($deliveryPrice) : null,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (!$isPayedOrder) {
|
|
|
|
|
$this->load->language('extension/payanyway/payment/payanyway');
|
|
|
|
|
$this->addOrderHistory($this->orderId, $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->buildResponseData($resultCode, $description);
|
|
|
|
|
|
|
|
|
|
$this->sendResponse($this->buildXMLResponse($responseData));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $resultCode
|
|
|
|
|
* @param string $description
|
|
|
|
|
* @return array<string, mixed>
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
private function buildResponseData(int $resultCode, string $description): array
|
|
|
|
|
{
|
|
|
|
|
$orderTotal = (float)($this->orderInfo['total'] ?? 0);
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'MNT_ID' => $this->mntId,
|
|
|
|
|
'MNT_TRANSACTION_ID' => $this->callbackData['MNT_TRANSACTION_ID'],
|
|
|
|
|
'MNT_RESULT_CODE' => $resultCode,
|
|
|
|
|
'MNT_DESCRIPTION' => $description,
|
|
|
|
|
'MNT_AMOUNT' => $this->formatPrice($orderTotal),
|
|
|
|
|
'MNT_CURRENCY_CODE' => $this->callbackData['MNT_CURRENCY_CODE'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$signatureSource = $resultCode . $this->mntId . $this->callbackData['MNT_TRANSACTION_ID'] . $this->integrityCode;
|
|
|
|
|
$data['MNT_SIGNATURE'] = md5($signatureSource);
|
|
|
|
|
|
|
|
|
|
$this->load->model('account/order');
|
|
|
|
|
$products = $this->model_account_order->getProducts($this->orderId);
|
|
|
|
|
$deliveryPrice = $this->getDeliveryPrice();
|
|
|
|
|
|
|
|
|
|
$data['inventory'] = $this->getInventoryJson($products) ?: null;
|
|
|
|
|
$data['client'] = $this->callbackData['MNT_SUBSCRIBER_ID'];
|
|
|
|
|
$data['sno'] = null;
|
|
|
|
|
$data['delivery'] = (null !== $deliveryPrice) ? $this->formatPrice($deliveryPrice) : null;
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function isOrderPaid(): bool
|
|
|
|
@@ -237,12 +237,16 @@ class Callback extends \Opencart\System\Engine\Controller
|
|
|
|
|
*/
|
|
|
|
|
private function getInventoryJson(array $products): false|string
|
|
|
|
|
{
|
|
|
|
|
if (empty($products)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$inventory = [];
|
|
|
|
|
foreach ($products as $product) {
|
|
|
|
|
$inventory[] = [
|
|
|
|
|
'name' => $this->validateString($product['name'] ?? '', self::INVENTORY_ITEM_NAME_MAX_LENGTH),
|
|
|
|
|
'price' => $this->formatPrice((float)($product['price'] ?? 0)),
|
|
|
|
|
'quantity' => $this->formatQuantity((string)($product['quantity'] ?? '0')),
|
|
|
|
|
'quantity' => $this->formatQuantity((float)($product['quantity'] ?? 0)),
|
|
|
|
|
'vatTag' => $this->vatRate,
|
|
|
|
|
'pm' => self::INVENTORY_ITEM_DEFAULT_PAYMENT_METHOD,
|
|
|
|
|
'po' => self::INVENTORY_ITEM_DEFAULT_PAYMENT_OBJECT,
|
|
|
|
@@ -276,15 +280,10 @@ class Callback extends \Opencart\System\Engine\Controller
|
|
|
|
|
return $orderStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function formatQuantity(string $quantity): string
|
|
|
|
|
private function formatQuantity(float $quantity): string
|
|
|
|
|
{
|
|
|
|
|
$quantity = str_replace(',', '.', $quantity);
|
|
|
|
|
|
|
|
|
|
if (!str_contains($quantity, '.') && ctype_digit($quantity)) {
|
|
|
|
|
return (string)(int)$quantity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return number_format((float)$quantity, 3, '.', '');
|
|
|
|
|
$quantityString = number_format($quantity, 3, '.', '');
|
|
|
|
|
return rtrim(rtrim($quantityString, '0'), '.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -334,7 +333,8 @@ class Callback extends \Opencart\System\Engine\Controller
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dom->saveXML();
|
|
|
|
|
$xml = $dom->saveXML();
|
|
|
|
|
return (false !== $xml) ? $xml : 'FAIL';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @param array<string, mixed> $params */
|
|
|
|
|