select('max(id_order) as id'); $sql->from('orders'); $sql->where('id_customer = \'' . pSQL(Context::getContext()->customer->id) . '\''); $lastInsert = Db::getInstance()->getRow($sql->build()); if (is_array($lastInsert)) { $order = new Order($lastInsert['id']); } } if ($order && ((int) $order->current_state === (int) Configuration::get('P24_ORDER_STATE_2'))) { Tools::redirect($this->getSuccessUrl($order, $idCart, $confirm)); } else { if (($sleep < self::MAXIMUM_TRY) && !($order && ((int) $order->current_state === (int) Configuration::get('PS_OS_ERROR')))) { // paymentStatus not yet processed ++$sleep; $returnParamArray = ['sleep' => $sleep]; if ($idOrder) { $returnParamArray['id_order'] = $idOrder; } elseif ($idCart) { $returnParamArray['id_cart'] = $idCart; } if ($confirm) { $returnParamArray['confirmation'] = $confirm; } Tools::redirect( $this->context->link->getModuleLink( 'przelewy24', 'paymentFinished', $returnParamArray, '1' === (string) Configuration::get('PS_SSL_ENABLED') ) ); } else { Tools::redirect( $this->context->link->getModuleLink( 'przelewy24', 'paymentFailed', $order ? ['id_order' => $order->id] : [], '1' === (string) Configuration::get('PS_SSL_ENABLED') ) ); } } } /** * @param Order $cart * @param string $idCart * @param int $confirm * * @return string|null */ private function getSuccessUrl(Order $order, $idCart, $confirm): string { $ssl = '1' === (string) Configuration::get('PS_SSL_ENABLED'); if (0 === $confirm) { return $this->context->link->getModuleLink( 'przelewy24', 'paymentSuccessful', [], $ssl ); } return $this->context->link->getPageLink( 'order-confirmation', $ssl, null, [ 'id_cart' => $idCart, 'id_module' => Module::getInstanceByName('przelewy24')->id, 'id_order' => $order->id, 'key' => (new Customer((int) $order->id_customer))->secure_key, ] ); } }