I have a problem with the PayPal return url, my system has the concept of friendly URL for example:
http://outros.local/vendas/carrinhos/finalizada
But with PayPal's return the URL is getting like this:
http://outros.local/vendas/carrinhos/finalizada?token=myToken&PayerID=myID
So I can not get the attributes token
and PayerID
, my .htacess looks like this:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)$ index.php?url=$1
</IfModule>
I also have a file called dispenser.php , its function is to get the url parameter and transform it into controller
, method
and params
:
<?php
/**
* Created by PhpStorm.
* User: Leonardo Vilarinho
* Date: 09/07/2016
* Time: 22:05
*/
/**
* Resgata parametros da URL, separa controller de method, verificando também se o link
* representa um alias, se representar pega o controlador e metodo do alias, se não pega
* o padrao do link (site.com/controlador/metodo/parametros). Por fim resgata os demais parametros
* colocando-o em array para serem usados no controlador.
*
* Exemplo:
* URL -> site.com/pessoas/editar/51
* Resultado do script será:
* $_GET['controller'] = 'pessoas'
* $_GET['method'] = 'editar'
* $_GET['params'] = array(0 => 51)
*
*/
var_dump($_GET);
$url = isset($_GET['url']) ? $_GET['url'] : '';
unset($_GET['url']);
if(!empty($url))
{
$params = explode('/', $url);
$_GET['controller'] = isset($params[0]) ? $params[0] : '';
$alias = Alias::check($_GET['controller']);
if($alias != false)
{
$_GET['controller'] = explode('/', $alias)[0];
$_GET['method'] = explode('/', $alias)[1];
}
else
{
$_GET['method'] = isset($params[1]) ? $params[1] : '';
unset($params[1]);
}
unset($params[0]);
$get = array();
foreach ($params as $value)
array_push($get, $value);
$_GET['params'] = $get;
}
The error already appears in var_dump
, which is displayed:
/home/leonardo/www/outros/vendas/kernel/dispenser.php:23:
array (size=1)
'url' => string 'carrinhos/finalizada' (length=20)
I noticed that the problem is the question mark in the return url (?), it would look like this:
http://outros.local/vendas?url=carrinhos/finalizada?token=myToken&PayerID=myID
Soon I would just get the first parameter.
How do I get the rest of the URL?
It worked like this (because in this case Paypal returns with & and not?):
http://outros.local/vendas?controller=carrinhos&method=finalizada&token=myToken&PayerID=myID
But my system would be exposed and with this url different from the others .. Another one that worked out was:
http://outros.local/vendas/carrinhos/finalizada&token=myToken&PayerID=myID
But when I put PayPal's return link as http://outros.local/vendas/carrinhos/finalizada
it does not work because the PayPal system returns the query string starting with '?'.
How can I resolve this problem?