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; $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', 'customer_token=' . $customerToken, true,); return $this->load->view('extension/payanyway/payment/payanyway', $data); } public function confirm(): void { $this->load->language('extension/payanyway/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->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'); $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'); $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 { $orderId = $this->orderInfo['order_id'] ?? null; $description = "Оплата заказа" . (!empty($orderId) ? " №{$orderId}" : ''); $name = $this->getClientName(); if (null !== $name) { $description .= " от {$name}"; } $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 { return $this->getClientEmail() ?? $this->getClientPhone() ?? ''; } }