formData['cart_orderNumber']); if (!Order::getIdByCartId($cart->id)) { if ( $cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active ) { Tools::redirect('index.php?controller=order&step=1'); } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { Tools::redirect('index.php?controller=order&step=1'); } $currency = $this->context->currency; $total = (float)$cart->getOrderTotal(true, Cart::BOTH); $this->module->validateOrder( (int)$cart->id, Configuration::get('PAYMENT_NEW_STATE'), $total, $this->module->displayName, null, null, (int)$currency->id, false, $customer->secure_key ); } } catch (\Exception $exception) { PrestaShopLogger::addLog('CaConfirmation::confirmOrder() - ' . $exception->getMessage(), 3); } } /** * @return array|null */ private function prepareFormData() { try { $cart = $this->context->cart; $orderId = Order::getOrderByCartId((int)($cart->id)); $data = []; foreach ($this->formData as $key => $value) { $verified = false; foreach ($this->formattedIdentifiers as $identifier) { if ($key == $identifier) { $verified = true; } } if ($verified === true) { $data[$key] = $value; } else { $verifiedKey = str_replace('_', '.', $key); $data[$verifiedKey] = $value; } } if($data['cart.itemName1'] === 'Zamówienie numer ' . $cart->id) { $data['cart.itemName1'] = 'Zamówienie numer ' . $orderId; } $data['PARAM_HASH'] = $this->generateHash($data); $data['cart.orderNumber'] = ''; if (Configuration::get('CARATY_ORDER_NUMBER_REPLACE')) { $sql = 'SELECT reference' . ' FROM ' . _DB_PREFIX_ . 'orders' . ' ORDER BY date_add DESC'; $data['cart.orderNumber'] = Db::getInstance()->getRow($sql)['reference']; } if (empty($data['cart.orderNumber'])) { // $data['cart.orderNumber'] = Order::getOrderByCartId($data['cart.orderNumber']); $data['cart.orderNumber'] = $orderId; } $order = new Order((int)$orderId); $customer = new Customer($order->id_customer); $data['email.address'] = $customer->email; return $data; } catch (\Exception $exception) { PrestaShopLogger::addLog('CaConfirmation::prepareFormData() - ' . $exception->getMessage(), 3); } return null; } /** * @return bool */ private function validate() { if ( isset($this->formData) && isset($this->formData['PARAM_TYPE']) && isset($this->formData['PARAM_PROFILE']) && isset($this->formData['POST_ATTR']) && isset($this->formData['PARAM_CREDIT_AMOUNT']) && isset($this->formData['PARAM_AUTH']) && $this->validateCartId() ) { return true; } PrestaShopLogger::addLog('CaConfirmation::validate() - form validation failed', 3); return false; } /** * @return bool */ private function validateCartId() { if ($this->isCartIdValidated) { $cartId = $this->formData['cart_orderNumber']; if ( !is_numeric($cartId) && strlen($cartId) != 9 ) { PrestaShopLogger::addLog('CaConfirmation::validateCartId() - form validation failed. Cart ID:' . $cartId, 3); return false; } } return true; } /** * @return void */ public function init() { parent::init(); $this->isCartIdValidated = Configuration::get('CARATY_VALIDATE_CART_ID'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST)) { $this->formData = $_POST; $this->confirmOrder(); } } else { Tools::redirect('index'); } } /** * @return void */ public function initContent() { parent::initContent(); try { $formLogo = Configuration::get('CARATY_LOGO_SEND'); if ($formLogo == null) { $formLogo = $this->formButtonUrl; } } catch (Exception $exception) { $formLogo = $this->formButtonUrl; } if ($this->validate()) { $this->context->smarty->assign( 'caraty', [ 'formUrl' => $this->formUrl, 'formButtonUrl' => $formLogo, 'inputVars' => $this->prepareFormData(), ] ); } $this->setTemplate('../../../modules/caraty/views/templates/front/confirm_order.tpl'); } private function generateHash($data) { $hash = Configuration::get('CARATY_PSP_ID') . 'RAT2' . $data['PARAM_CREDIT_AMOUNT'] . $data['cart.itemName1'] . $data['cart.itemPrice1'] . $data['randomizer'] . Configuration::get('CARATY_PASSWORD'); return md5($hash); } }