From 4c54765e5e85379d3506bbd62a2ed27a5efdcdde Mon Sep 17 00:00:00 2001 From: Lazaro Date: Wed, 5 Aug 2020 20:57:57 -0300 Subject: [PATCH] =?UTF-8?q?:bug:=20Corrigido=20a=20chamada=20do=20m=C3=A9t?= =?UTF-8?q?odo=20checkLoginExist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site.php | 1050 +++++++++++++++++++++++++----------------------------- 1 file changed, 484 insertions(+), 566 deletions(-) diff --git a/site.php b/site.php index 150b23e..2162d65 100644 --- a/site.php +++ b/site.php @@ -1,736 +1,654 @@ -get('/', function() { +use Hcode\Model\Address; +use Hcode\Model\Cart; +use Hcode\Model\Category; +use Hcode\Model\Order; +use Hcode\Model\OrderStatus; +use Hcode\Model\Product; +use Hcode\Model\User; +use Hcode\Page; - $products = Product::listAll(); +$app->get('/', function () { + $products = Product::listAll(); - $page = new Page(); - - $page->setTpl("index", [ - 'products'=>Product::checkList($products) - ]); + $page = new Page(); + $page->setTpl('index', [ + 'products' => Product::checkList($products), + ]); }); -$app->get("/categories/:idcategory", function($idcategory){ - - $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; - - $category = new Category(); +$app->get('/categories/:idcategory', function ($idcategory) { + $page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1; - $category->get((int)$idcategory); + $category = new Category(); - $pagination = $category->getProductsPage($page); + $category->get((int) $idcategory); - $pages = []; + $pagination = $category->getProductsPage($page); - for ($i=1; $i <= $pagination['pages']; $i++) { - array_push($pages, [ - 'link'=>'/categories/'.$category->getidcategory().'?page='.$i, - 'page'=>$i - ]); - } + $pages = []; - $page = new Page(); + for ($i = 1; $i <= $pagination['pages']; ++$i) { + array_push($pages, [ + 'link' => '/categories/'.$category->getidcategory().'?page='.$i, + 'page' => $i, + ]); + } - $page->setTpl("category", [ - 'category'=>$category->getValues(), - 'products'=>$pagination["data"], - 'pages'=>$pages - ]); + $page = new Page(); + $page->setTpl('category', [ + 'category' => $category->getValues(), + 'products' => $pagination['data'], + 'pages' => $pages, + ]); }); -$app->get("/products/:desurl", function($desurl){ - - $product = new Product(); - - $product->getFromURL($desurl); +$app->get('/products/:desurl', function ($desurl) { + $product = new Product(); - $page = new Page(); + $product->getFromURL($desurl); - $page->setTpl("product-detail", [ - 'product'=>$product->getValues(), - 'categories'=>$product->getCategories() - ]); + $page = new Page(); + $page->setTpl('product-detail', [ + 'product' => $product->getValues(), + 'categories' => $product->getCategories(), + ]); }); -$app->get("/cart", function(){ +$app->get('/cart', function () { + $cart = Cart::getFromSession(); - $cart = Cart::getFromSession(); - - $page = new Page(); - - $page->setTpl("cart", [ - 'cart'=>$cart->getValues(), - 'products'=>$cart->getProducts(), - 'error'=>Cart::getMsgError() - ]); + $page = new Page(); + $page->setTpl('cart', [ + 'cart' => $cart->getValues(), + 'products' => $cart->getProducts(), + 'error' => Cart::getMsgError(), + ]); }); -$app->get("/cart/:idproduct/add", function($idproduct){ - - $product = new Product(); - - $product->get((int)$idproduct); +$app->get('/cart/:idproduct/add', function ($idproduct) { + $product = new Product(); - $cart = Cart::getFromSession(); + $product->get((int) $idproduct); - $qtd = (isset($_GET['qtd'])) ? (int)$_GET['qtd'] : 1; + $cart = Cart::getFromSession(); - for ($i = 0; $i < $qtd; $i++) { - - $cart->addProduct($product); + $qtd = (isset($_GET['qtd'])) ? (int) $_GET['qtd'] : 1; - } - - header("Location: /cart"); - exit; + for ($i = 0; $i < $qtd; ++$i) { + $cart->addProduct($product); + } + header('Location: /cart'); + exit; }); -$app->get("/cart/:idproduct/minus", function($idproduct){ - - $product = new Product(); +$app->get('/cart/:idproduct/minus', function ($idproduct) { + $product = new Product(); - $product->get((int)$idproduct); + $product->get((int) $idproduct); - $cart = Cart::getFromSession(); + $cart = Cart::getFromSession(); - $cart->removeProduct($product); - - header("Location: /cart"); - exit; + $cart->removeProduct($product); + header('Location: /cart'); + exit; }); -$app->get("/cart/:idproduct/remove", function($idproduct){ - - $product = new Product(); +$app->get('/cart/:idproduct/remove', function ($idproduct) { + $product = new Product(); - $product->get((int)$idproduct); + $product->get((int) $idproduct); - $cart = Cart::getFromSession(); + $cart = Cart::getFromSession(); - $cart->removeProduct($product, true); - - header("Location: /cart"); - exit; + $cart->removeProduct($product, true); + header('Location: /cart'); + exit; }); -$app->post("/cart/freight", function(){ - - $cart = Cart::getFromSession(); +$app->post('/cart/freight', function () { + $cart = Cart::getFromSession(); - $cart->setFreight($_POST['zipcode']); - - header("Location: /cart"); - exit; + $cart->setFreight($_POST['zipcode']); + header('Location: /cart'); + exit; }); -$app->get("/checkout", function(){ - - User::verifyLogin(false); - - $address = new Address(); - $cart = Cart::getFromSession(); - - if (!isset($_GET['zipcode'])) { - - $_GET['zipcode'] = $cart->getdeszipcode(); - - } - - if (isset($_GET['zipcode'])) { - - $address->loadFromCEP($_GET['zipcode']); - - $cart->setdeszipcode($_GET['zipcode']); - - $cart->save(); - - $cart->getCalculateTotal(); - - } - - if (!$address->getdesaddress()) $address->setdesaddress(''); - if (!$address->getdesnumber()) $address->setdesnumber(''); - if (!$address->getdescomplement()) $address->setdescomplement(''); - if (!$address->getdesdistrict()) $address->setdesdistrict(''); - if (!$address->getdescity()) $address->setdescity(''); - if (!$address->getdesstate()) $address->setdesstate(''); - if (!$address->getdescountry()) $address->setdescountry(''); - if (!$address->getdeszipcode()) $address->setdeszipcode(''); - - $page = new Page(); - - $page->setTpl("checkout", [ - 'cart'=>$cart->getValues(), - 'address'=>$address->getValues(), - 'products'=>$cart->getProducts(), - 'error'=>Address::getMsgError() - ]); - +$app->get('/checkout', function () { + User::verifyLogin(false); + + $address = new Address(); + $cart = Cart::getFromSession(); + + if (!isset($_GET['zipcode'])) { + $_GET['zipcode'] = $cart->getdeszipcode(); + } + + if (isset($_GET['zipcode'])) { + $address->loadFromCEP($_GET['zipcode']); + + $cart->setdeszipcode($_GET['zipcode']); + + $cart->save(); + + $cart->getCalculateTotal(); + } + + if (!$address->getdesaddress()) { + $address->setdesaddress(''); + } + if (!$address->getdesnumber()) { + $address->setdesnumber(''); + } + if (!$address->getdescomplement()) { + $address->setdescomplement(''); + } + if (!$address->getdesdistrict()) { + $address->setdesdistrict(''); + } + if (!$address->getdescity()) { + $address->setdescity(''); + } + if (!$address->getdesstate()) { + $address->setdesstate(''); + } + if (!$address->getdescountry()) { + $address->setdescountry(''); + } + if (!$address->getdeszipcode()) { + $address->setdeszipcode(''); + } + + $page = new Page(); + + $page->setTpl('checkout', [ + 'cart' => $cart->getValues(), + 'address' => $address->getValues(), + 'products' => $cart->getProducts(), + 'error' => Address::getMsgError(), + ]); }); -$app->post("/checkout", function(){ - - User::verifyLogin(false); - - if (!isset($_POST['zipcode']) || $_POST['zipcode'] === '') { - Address::setMsgError("Informe o CEP."); - header('Location: /checkout'); - exit; - } +$app->post('/checkout', function () { + User::verifyLogin(false); - if (!isset($_POST['desaddress']) || $_POST['desaddress'] === '') { - Address::setMsgError("Informe o endereço."); - header('Location: /checkout'); - exit; - } + if (!isset($_POST['zipcode']) || '' === $_POST['zipcode']) { + Address::setMsgError('Informe o CEP.'); + header('Location: /checkout'); + exit; + } - if (!isset($_POST['desdistrict']) || $_POST['desdistrict'] === '') { - Address::setMsgError("Informe o bairro."); - header('Location: /checkout'); - exit; - } + if (!isset($_POST['desaddress']) || '' === $_POST['desaddress']) { + Address::setMsgError('Informe o endereço.'); + header('Location: /checkout'); + exit; + } - if (!isset($_POST['descity']) || $_POST['descity'] === '') { - Address::setMsgError("Informe a cidade."); - header('Location: /checkout'); - exit; - } + if (!isset($_POST['desdistrict']) || '' === $_POST['desdistrict']) { + Address::setMsgError('Informe o bairro.'); + header('Location: /checkout'); + exit; + } - if (!isset($_POST['desstate']) || $_POST['desstate'] === '') { - Address::setMsgError("Informe o estado."); - header('Location: /checkout'); - exit; - } + if (!isset($_POST['descity']) || '' === $_POST['descity']) { + Address::setMsgError('Informe a cidade.'); + header('Location: /checkout'); + exit; + } - if (!isset($_POST['descountry']) || $_POST['descountry'] === '') { - Address::setMsgError("Informe o país."); - header('Location: /checkout'); - exit; - } + if (!isset($_POST['desstate']) || '' === $_POST['desstate']) { + Address::setMsgError('Informe o estado.'); + header('Location: /checkout'); + exit; + } - $user = User::getFromSession(); + if (!isset($_POST['descountry']) || '' === $_POST['descountry']) { + Address::setMsgError('Informe o país.'); + header('Location: /checkout'); + exit; + } - $address = new Address(); + $user = User::getFromSession(); - $_POST['deszipcode'] = $_POST['zipcode']; - $_POST['idperson'] = $user->getidperson(); + $address = new Address(); - $address->setData($_POST); + $_POST['deszipcode'] = $_POST['zipcode']; + $_POST['idperson'] = $user->getidperson(); - $address->save(); + $address->setData($_POST); - $cart = Cart::getFromSession(); + $address->save(); - $cart->getCalculateTotal(); + $cart = Cart::getFromSession(); - $order = new Order(); + $cart->getCalculateTotal(); - $order->setData([ - 'idcart'=>$cart->getidcart(), - 'idaddress'=>$address->getidaddress(), - 'iduser'=>$user->getiduser(), - 'idstatus'=>OrderStatus::EM_ABERTO, - 'vltotal'=>$cart->getvltotal() - ]); + $order = new Order(); - $order->save(); + $order->setData([ + 'idcart' => $cart->getidcart(), + 'idaddress' => $address->getidaddress(), + 'iduser' => $user->getiduser(), + 'idstatus' => OrderStatus::EM_ABERTO, + 'vltotal' => $cart->getvltotal(), + ]); - switch ((int)$_POST['payment-method']) { + $order->save(); - case 1: - header("Location: /order/".$order->getidorder()."/pagseguro"); - break; + switch ((int) $_POST['payment-method']) { + case 1: + header('Location: /order/'.$order->getidorder().'/pagseguro'); + break; - case 2: - header("Location: /order/".$order->getidorder()."/paypal"); - break; - - } - - exit; + case 2: + header('Location: /order/'.$order->getidorder().'/paypal'); + break; + } + exit; }); -$app->get("/order/:idorder/pagseguro", function($idorder){ - - User::verifyLogin(false); - - $order = new Order(); +$app->get('/order/:idorder/pagseguro', function ($idorder) { + User::verifyLogin(false); - $order->get((int)$idorder); + $order = new Order(); - $cart = $order->getCart(); + $order->get((int) $idorder); - $page = new Page([ - 'header'=>false, - 'footer'=>false - ]); - - $page->setTpl("payment-pagseguro", [ - 'order'=>$order->getValues(), - 'cart'=>$cart->getValues(), - 'products'=>$cart->getProducts(), - 'phone'=>[ - 'areaCode'=>substr($order->getnrphone(), 0, 2), - 'number'=>substr($order->getnrphone(), 2, strlen($order->getnrphone())) - ] - ]); + $cart = $order->getCart(); + $page = new Page([ + 'header' => false, + 'footer' => false, + ]); + $page->setTpl('payment-pagseguro', [ + 'order' => $order->getValues(), + 'cart' => $cart->getValues(), + 'products' => $cart->getProducts(), + 'phone' => [ + 'areaCode' => substr($order->getnrphone(), 0, 2), + 'number' => substr($order->getnrphone(), 2, strlen($order->getnrphone())), + ], + ]); }); -$app->get("/order/:idorder/paypal", function($idorder){ - - User::verifyLogin(false); - - $order = new Order(); - - $order->get((int)$idorder); +$app->get('/order/:idorder/paypal', function ($idorder) { + User::verifyLogin(false); - $cart = $order->getCart(); + $order = new Order(); - $page = new Page([ - 'header'=>false, - 'footer'=>false - ]); + $order->get((int) $idorder); - $page->setTpl("payment-paypal", [ - 'order'=>$order->getValues(), - 'cart'=>$cart->getValues(), - 'products'=>$cart->getProducts() - ]); + $cart = $order->getCart(); + $page = new Page([ + 'header' => false, + 'footer' => false, + ]); + $page->setTpl('payment-paypal', [ + 'order' => $order->getValues(), + 'cart' => $cart->getValues(), + 'products' => $cart->getProducts(), + ]); }); -$app->get("/login", function(){ - - $page = new Page(); - - $page->setTpl("login", [ - 'error'=>User::getError(), - 'errorRegister'=>User::getErrorRegister(), - 'registerValues'=>(isset($_SESSION['registerValues'])) ? $_SESSION['registerValues'] : ['name'=>'', 'email'=>'', 'phone'=>''] - ]); +$app->get('/login', function () { + $page = new Page(); + $page->setTpl('login', [ + 'error' => User::getError(), + 'errorRegister' => User::getErrorRegister(), + 'registerValues' => (isset($_SESSION['registerValues'])) ? $_SESSION['registerValues'] : ['name' => '', 'email' => '', 'phone' => ''], + ]); }); -$app->post("/login", function(){ - - try { - - User::login($_POST['login'], $_POST['password']); - - } catch(Exception $e) { - - User::setError($e->getMessage()); - - } - - header("Location: /checkout"); - exit; +$app->post('/login', function () { + try { + User::login($_POST['login'], $_POST['password']); + } catch (Exception $e) { + User::setError($e->getMessage()); + } + header('Location: /checkout'); + exit; }); -$app->get("/logout", function(){ - - User::logout(); - - header("Location: /login"); - exit; +$app->get('/logout', function () { + User::logout(); + header('Location: /login'); + exit; }); -$app->post("/register", function(){ - - $_SESSION['registerValues'] = $_POST; - - if (!isset($_POST['name']) || $_POST['name'] == '') { - - User::setErrorRegister("Preencha o seu nome."); - header("Location: /login"); - exit; - - } - - if (!isset($_POST['email']) || $_POST['email'] == '') { - - User::setErrorRegister("Preencha o seu e-mail."); - header("Location: /login"); - exit; - - } - - if (!isset($_POST['password']) || $_POST['password'] == '') { - - User::setErrorRegister("Preencha a senha."); - header("Location: /login"); - exit; - - } - - if (User::checkLoginExist($_POST['email']) === true) { - - User::setErrorRegister("Este endereço de e-mail já está sendo usado por outro usuário."); - header("Location: /login"); - exit; - - } - - $user = new User(); - - $user->setData([ - 'inadmin'=>0, - 'deslogin'=>$_POST['email'], - 'desperson'=>$_POST['name'], - 'desemail'=>$_POST['email'], - 'despassword'=>$_POST['password'], - 'nrphone'=>$_POST['phone'] - ]); - - $user->save(); - - User::login($_POST['email'], $_POST['password']); - - header('Location: /checkout'); - exit; - +$app->post('/register', function () { + $_SESSION['registerValues'] = $_POST; + + if (!isset($_POST['name']) || '' == $_POST['name']) { + User::setErrorRegister('Preencha o seu nome.'); + header('Location: /login'); + exit; + } + + if (!isset($_POST['email']) || '' == $_POST['email']) { + User::setErrorRegister('Preencha o seu e-mail.'); + header('Location: /login'); + exit; + } + + if (!isset($_POST['password']) || '' == $_POST['password']) { + User::setErrorRegister('Preencha a senha.'); + header('Location: /login'); + exit; + } + + if (true === User::checkLoginExist($_POST['email'])) { + User::setErrorRegister('Este endereço de e-mail já está sendo usado por outro usuário.'); + header('Location: /login'); + exit; + } + + $user = new User(); + + $user->setData([ + 'inadmin' => 0, + 'deslogin' => $_POST['email'], + 'desperson' => $_POST['name'], + 'desemail' => $_POST['email'], + 'despassword' => $_POST['password'], + 'nrphone' => $_POST['phone'], + ]); + + $user->save(); + + User::login($_POST['email'], $_POST['password']); + + header('Location: /checkout'); + exit; }); -$app->get("/forgot", function() { - - $page = new Page(); - - $page->setTpl("forgot"); +$app->get('/forgot', function () { + $page = new Page(); + $page->setTpl('forgot'); }); -$app->post("/forgot", function(){ - - $user = User::getForgot($_POST["email"], false); - - header("Location: /forgot/sent"); - exit; +$app->post('/forgot', function () { + $user = User::getForgot($_POST['email'], false); + header('Location: /forgot/sent'); + exit; }); -$app->get("/forgot/sent", function(){ - - $page = new Page(); - - $page->setTpl("forgot-sent"); +$app->get('/forgot/sent', function () { + $page = new Page(); + $page->setTpl('forgot-sent'); }); +$app->get('/forgot/reset', function () { + $user = User::validForgotDecrypt($_GET['code']); -$app->get("/forgot/reset", function(){ - - $user = User::validForgotDecrypt($_GET["code"]); - - $page = new Page(); - - $page->setTpl("forgot-reset", array( - "name"=>$user["desperson"], - "code"=>$_GET["code"] - )); + $page = new Page(); + $page->setTpl('forgot-reset', [ + 'name' => $user['desperson'], + 'code' => $_GET['code'], + ]); }); -$app->post("/forgot/reset", function(){ - - $forgot = User::validForgotDecrypt($_POST["code"]); +$app->post('/forgot/reset', function () { + $forgot = User::validForgotDecrypt($_POST['code']); - User::setFogotUsed($forgot["idrecovery"]); + User::setFogotUsed($forgot['idrecovery']); - $user = new User(); + $user = new User(); - $user->get((int)$forgot["iduser"]); + $user->get((int) $forgot['iduser']); - $password = User::getPasswordHash($_POST["password"]); + $password = User::getPasswordHash($_POST['password']); - $user->setPassword($password); + $user->setPassword($password); - $page = new Page(); - - $page->setTpl("forgot-reset-success"); + $page = new Page(); + $page->setTpl('forgot-reset-success'); }); -$app->get("/profile", function(){ - - User::verifyLogin(false); +$app->get('/profile', function () { + User::verifyLogin(false); - $user = User::getFromSession(); + $user = User::getFromSession(); - $page = new Page(); - - $page->setTpl("profile", [ - 'user'=>$user->getValues(), - 'profileMsg'=>User::getSuccess(), - 'profileError'=>User::getError() - ]); + $page = new Page(); + $page->setTpl('profile', [ + 'user' => $user->getValues(), + 'profileMsg' => User::getSuccess(), + 'profileError' => User::getError(), + ]); }); -$app->post("/profile", function(){ - - User::verifyLogin(false); - - if (!isset($_POST['desperson']) || $_POST['desperson'] === '') { - User::setError("Preencha o seu nome."); - header('Location: /profile'); - exit; - } - - if (!isset($_POST['desemail']) || $_POST['desemail'] === '') { - User::setError("Preencha o seu e-mail."); - header('Location: /profile'); - exit; - } +$app->post('/profile', function () { + User::verifyLogin(false); - $user = User::getFromSession(); + if (!isset($_POST['desperson']) || '' === $_POST['desperson']) { + User::setError('Preencha o seu nome.'); + header('Location: /profile'); + exit; + } - if ($_POST['desemail'] !== $user->getdesemail()) { + if (!isset($_POST['desemail']) || '' === $_POST['desemail']) { + User::setError('Preencha o seu e-mail.'); + header('Location: /profile'); + exit; + } - if (User::checkLoginExists($_POST['desemail']) === true) { + $user = User::getFromSession(); - User::setError("Este endereço de e-mail já está cadastrado."); - header('Location: /profile'); - exit; + if ($_POST['desemail'] !== $user->getdesemail()) { + if (true === User::checkLoginExist($_POST['desemail'])) { + User::setError('Este endereço de e-mail já está cadastrado.'); + header('Location: /profile'); + exit; + } + } - } + $_POST['inadmin'] = $user->getinadmin(); + $_POST['despassword'] = $user->getdespassword(); + $_POST['deslogin'] = $_POST['desemail']; - } + $user->setData($_POST); - $_POST['inadmin'] = $user->getinadmin(); - $_POST['despassword'] = $user->getdespassword(); - $_POST['deslogin'] = $_POST['desemail']; + $user->save(); - $user->setData($_POST); - - $user->save(); - - User::setSuccess("Dados alterados com sucesso!"); - - header('Location: /profile'); - exit; + User::setSuccess('Dados alterados com sucesso!'); + header('Location: /profile'); + exit; }); -$app->get("/order/:idorder", function($idorder){ - - User::verifyLogin(false); +$app->get('/order/:idorder', function ($idorder) { + User::verifyLogin(false); - $order = new Order(); + $order = new Order(); - $order->get((int)$idorder); + $order->get((int) $idorder); - $page = new Page(); - - $page->setTpl("payment", [ - 'order'=>$order->getValues() - ]); + $page = new Page(); + $page->setTpl('payment', [ + 'order' => $order->getValues(), + ]); }); -$app->get("/boleto/:idorder", function($idorder){ - - User::verifyLogin(false); - - $order = new Order(); - - $order->get((int)$idorder); - - // DADOS DO BOLETO PARA O SEU CLIENTE - $dias_de_prazo_para_pagamento = 10; - $taxa_boleto = 5.00; - $data_venc = date("d/m/Y", time() + ($dias_de_prazo_para_pagamento * 86400)); // Prazo de X dias OU informe data: "13/04/2006"; - - $valor_cobrado = formatPrice($order->getvltotal()); // Valor - REGRA: Sem pontos na milhar e tanto faz com "." ou "," ou com 1 ou 2 ou sem casa decimal - $valor_cobrado = str_replace(".", "", $valor_cobrado); - $valor_cobrado = str_replace(",", ".",$valor_cobrado); - $valor_boleto=number_format($valor_cobrado+$taxa_boleto, 2, ',', ''); - - $dadosboleto["nosso_numero"] = $order->getidorder(); // Nosso numero - REGRA: Máximo de 8 caracteres! - $dadosboleto["numero_documento"] = $order->getidorder(); // Num do pedido ou nosso numero - $dadosboleto["data_vencimento"] = $data_venc; // Data de Vencimento do Boleto - REGRA: Formato DD/MM/AAAA - $dadosboleto["data_documento"] = date("d/m/Y"); // Data de emissão do Boleto - $dadosboleto["data_processamento"] = date("d/m/Y"); // Data de processamento do boleto (opcional) - $dadosboleto["valor_boleto"] = $valor_boleto; // Valor do Boleto - REGRA: Com vírgula e sempre com duas casas depois da virgula - - // DADOS DO SEU CLIENTE - $dadosboleto["sacado"] = $order->getdesperson(); - $dadosboleto["endereco1"] = $order->getdesaddress() . " " . $order->getdesdistrict(); - $dadosboleto["endereco2"] = $order->getdescity() . " - " . $order->getdesstate() . " - " . $order->getdescountry() . " - CEP: " . $order->getdeszipcode(); - - // INFORMACOES PARA O CLIENTE - $dadosboleto["demonstrativo1"] = "Pagamento de Compra na Loja Hcode E-commerce"; - $dadosboleto["demonstrativo2"] = "Taxa bancária - R$ 0,00"; - $dadosboleto["demonstrativo3"] = ""; - $dadosboleto["instrucoes1"] = "- Sr. Caixa, cobrar multa de 2% após o vencimento"; - $dadosboleto["instrucoes2"] = "- Receber até 10 dias após o vencimento"; - $dadosboleto["instrucoes3"] = "- Em caso de dúvidas entre em contato conosco: suporte@hcode.com.br"; - $dadosboleto["instrucoes4"] = "  Emitido pelo sistema Projeto Loja Hcode E-commerce - www.hcode.com.br"; - - // DADOS OPCIONAIS DE ACORDO COM O BANCO OU CLIENTE - $dadosboleto["quantidade"] = ""; - $dadosboleto["valor_unitario"] = ""; - $dadosboleto["aceite"] = ""; - $dadosboleto["especie"] = "R$"; - $dadosboleto["especie_doc"] = ""; - - - // ---------------------- DADOS FIXOS DE CONFIGURAÇÃO DO SEU BOLETO --------------- // - - - // DADOS DA SUA CONTA - ITAÚ - $dadosboleto["agencia"] = "1690"; // Num da agencia, sem digito - $dadosboleto["conta"] = "48781"; // Num da conta, sem digito - $dadosboleto["conta_dv"] = "2"; // Digito do Num da conta - - // DADOS PERSONALIZADOS - ITAÚ - $dadosboleto["carteira"] = "175"; // Código da Carteira: pode ser 175, 174, 104, 109, 178, ou 157 - - // SEUS DADOS - $dadosboleto["identificacao"] = "Hcode Treinamentos"; - $dadosboleto["cpf_cnpj"] = "24.700.731/0001-08"; - $dadosboleto["endereco"] = "Rua Ademar Saraiva Leão, 234 - Alvarenga, 09853-120"; - $dadosboleto["cidade_uf"] = "São Bernardo do Campo - SP"; - $dadosboleto["cedente"] = "HCODE TREINAMENTOS LTDA - ME"; - - // NÃO ALTERAR! - $path = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR . "boletophp" . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR; - - require_once($path . "funcoes_itau.php"); - require_once($path . "layout_itau.php"); - +$app->get('/boleto/:idorder', function ($idorder) { + User::verifyLogin(false); + + $order = new Order(); + + $order->get((int) $idorder); + + // DADOS DO BOLETO PARA O SEU CLIENTE + $dias_de_prazo_para_pagamento = 10; + $taxa_boleto = 5.00; + $data_venc = date('d/m/Y', time() + ($dias_de_prazo_para_pagamento * 86400)); // Prazo de X dias OU informe data: "13/04/2006"; + + $valor_cobrado = formatPrice($order->getvltotal()); // Valor - REGRA: Sem pontos na milhar e tanto faz com "." ou "," ou com 1 ou 2 ou sem casa decimal + $valor_cobrado = str_replace('.', '', $valor_cobrado); + $valor_cobrado = str_replace(',', '.', $valor_cobrado); + $valor_boleto = number_format($valor_cobrado + $taxa_boleto, 2, ',', ''); + + $dadosboleto['nosso_numero'] = $order->getidorder(); // Nosso numero - REGRA: Máximo de 8 caracteres! + $dadosboleto['numero_documento'] = $order->getidorder(); // Num do pedido ou nosso numero + $dadosboleto['data_vencimento'] = $data_venc; // Data de Vencimento do Boleto - REGRA: Formato DD/MM/AAAA + $dadosboleto['data_documento'] = date('d/m/Y'); // Data de emissão do Boleto + $dadosboleto['data_processamento'] = date('d/m/Y'); // Data de processamento do boleto (opcional) + $dadosboleto['valor_boleto'] = $valor_boleto; // Valor do Boleto - REGRA: Com vírgula e sempre com duas casas depois da virgula + + // DADOS DO SEU CLIENTE + $dadosboleto['sacado'] = $order->getdesperson(); + $dadosboleto['endereco1'] = $order->getdesaddress().' '.$order->getdesdistrict(); + $dadosboleto['endereco2'] = $order->getdescity().' - '.$order->getdesstate().' - '.$order->getdescountry().' - CEP: '.$order->getdeszipcode(); + + // INFORMACOES PARA O CLIENTE + $dadosboleto['demonstrativo1'] = 'Pagamento de Compra na Loja Hcode E-commerce'; + $dadosboleto['demonstrativo2'] = 'Taxa bancária - R$ 0,00'; + $dadosboleto['demonstrativo3'] = ''; + $dadosboleto['instrucoes1'] = '- Sr. Caixa, cobrar multa de 2% após o vencimento'; + $dadosboleto['instrucoes2'] = '- Receber até 10 dias após o vencimento'; + $dadosboleto['instrucoes3'] = '- Em caso de dúvidas entre em contato conosco: suporte@hcode.com.br'; + $dadosboleto['instrucoes4'] = '  Emitido pelo sistema Projeto Loja Hcode E-commerce - www.hcode.com.br'; + + // DADOS OPCIONAIS DE ACORDO COM O BANCO OU CLIENTE + $dadosboleto['quantidade'] = ''; + $dadosboleto['valor_unitario'] = ''; + $dadosboleto['aceite'] = ''; + $dadosboleto['especie'] = 'R$'; + $dadosboleto['especie_doc'] = ''; + + // ---------------------- DADOS FIXOS DE CONFIGURAÇÃO DO SEU BOLETO --------------- // + + // DADOS DA SUA CONTA - ITAÚ + $dadosboleto['agencia'] = '1690'; // Num da agencia, sem digito + $dadosboleto['conta'] = '48781'; // Num da conta, sem digito + $dadosboleto['conta_dv'] = '2'; // Digito do Num da conta + + // DADOS PERSONALIZADOS - ITAÚ + $dadosboleto['carteira'] = '175'; // Código da Carteira: pode ser 175, 174, 104, 109, 178, ou 157 + + // SEUS DADOS + $dadosboleto['identificacao'] = 'Hcode Treinamentos'; + $dadosboleto['cpf_cnpj'] = '24.700.731/0001-08'; + $dadosboleto['endereco'] = 'Rua Ademar Saraiva Leão, 234 - Alvarenga, 09853-120'; + $dadosboleto['cidade_uf'] = 'São Bernardo do Campo - SP'; + $dadosboleto['cedente'] = 'HCODE TREINAMENTOS LTDA - ME'; + + // NÃO ALTERAR! + $path = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'res'.DIRECTORY_SEPARATOR.'boletophp'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR; + + require_once $path.'funcoes_itau.php'; + require_once $path.'layout_itau.php'; }); -$app->get("/profile/orders", function(){ - - User::verifyLogin(false); +$app->get('/profile/orders', function () { + User::verifyLogin(false); - $user = User::getFromSession(); + $user = User::getFromSession(); - $page = new Page(); - - $page->setTpl("profile-orders", [ - 'orders'=>$user->getOrders() - ]); + $page = new Page(); + $page->setTpl('profile-orders', [ + 'orders' => $user->getOrders(), + ]); }); -$app->get("/profile/orders/:idorder", function($idorder){ - - User::verifyLogin(false); +$app->get('/profile/orders/:idorder', function ($idorder) { + User::verifyLogin(false); - $order = new Order(); + $order = new Order(); - $order->get((int)$idorder); + $order->get((int) $idorder); - $cart = new Cart(); + $cart = new Cart(); - $cart->get((int)$order->getidcart()); + $cart->get((int) $order->getidcart()); - $cart->getCalculateTotal(); + $cart->getCalculateTotal(); - $page = new Page(); - - $page->setTpl("profile-orders-detail", [ - 'order'=>$order->getValues(), - 'cart'=>$cart->getValues(), - 'products'=>$cart->getProducts() - ]); + $page = new Page(); + $page->setTpl('profile-orders-detail', [ + 'order' => $order->getValues(), + 'cart' => $cart->getValues(), + 'products' => $cart->getProducts(), + ]); }); -$app->get("/profile/change-password", function(){ - - User::verifyLogin(false); +$app->get('/profile/change-password', function () { + User::verifyLogin(false); - $page = new Page(); - - $page->setTpl("profile-change-password", [ - 'changePassError'=>User::getError(), - 'changePassSuccess'=>User::getSuccess() - ]); + $page = new Page(); + $page->setTpl('profile-change-password', [ + 'changePassError' => User::getError(), + 'changePassSuccess' => User::getSuccess(), + ]); }); -$app->post("/profile/change-password", function(){ - - User::verifyLogin(false); - - if (!isset($_POST['current_pass']) || $_POST['current_pass'] === '') { - - User::setError("Digite a senha atual."); - header("Location: /profile/change-password"); - exit; - - } - - if (!isset($_POST['new_pass']) || $_POST['new_pass'] === '') { - - User::setError("Digite a nova senha."); - header("Location: /profile/change-password"); - exit; - - } +$app->post('/profile/change-password', function () { + User::verifyLogin(false); - if (!isset($_POST['new_pass_confirm']) || $_POST['new_pass_confirm'] === '') { + if (!isset($_POST['current_pass']) || '' === $_POST['current_pass']) { + User::setError('Digite a senha atual.'); + header('Location: /profile/change-password'); + exit; + } - User::setError("Confirme a nova senha."); - header("Location: /profile/change-password"); - exit; + if (!isset($_POST['new_pass']) || '' === $_POST['new_pass']) { + User::setError('Digite a nova senha.'); + header('Location: /profile/change-password'); + exit; + } - } + if (!isset($_POST['new_pass_confirm']) || '' === $_POST['new_pass_confirm']) { + User::setError('Confirme a nova senha.'); + header('Location: /profile/change-password'); + exit; + } - if ($_POST['current_pass'] === $_POST['new_pass']) { + if ($_POST['current_pass'] === $_POST['new_pass']) { + User::setError('A sua nova senha deve ser diferente da atual.'); + header('Location: /profile/change-password'); + exit; + } - User::setError("A sua nova senha deve ser diferente da atual."); - header("Location: /profile/change-password"); - exit; + $user = User::getFromSession(); - } + if (!password_verify($_POST['current_pass'], $user->getdespassword())) { + User::setError('A senha está inválida.'); + header('Location: /profile/change-password'); + exit; + } - $user = User::getFromSession(); + $user->setdespassword($_POST['new_pass']); - if (!password_verify($_POST['current_pass'], $user->getdespassword())) { - - User::setError("A senha está inválida."); - header("Location: /profile/change-password"); - exit; - - } - - $user->setdespassword($_POST['new_pass']); - - $user->update(); - - User::setSuccess("Senha alterada com sucesso."); - - header("Location: /profile/change-password"); - exit; - -}); + $user->update(); + User::setSuccess('Senha alterada com sucesso.'); - ?> \ No newline at end of file + header('Location: /profile/change-password'); + exit; +}); \ No newline at end of file