This is my code:
<?php require 'paypal/autoload.php'; define('URL_SITIO', 'http://localhost:8083/gdlwebcamp(UltimoProyecto AVANZADO)'); $apiContext = new PayPalRestApiContext( new PayPalAuthOAuthTokenCredential( 'ClienteID', 'Secret' ) ); //Redireccionar $redireccionar = new RedirectUrls(); $redireccionar->setReturnUrl(URL_SITIO . "/pago-finalizado.php?exito=true&id_pago={$ID_registro}") ->setCancelUrl(URL_SITIO . "/pago-finalizado.php?exito=false&id_pago={$ID_registro}"); //Procesar el PAGO $pago = new Payment(); $pago->setIntent("sale") ->setPayer($compra) ->setRedirectUrls($redireccionar) ->setTransactions(array($transaccion)); try { $pago->create($apiContext); } catch (PaypalExceptionPaypalConnectionException $pce) { echo "<pre>"; print_r(json_decode($pce->getData())); exit; echo "</pre>"; } $aprobado = $pago->getApprovalLink(); header("Location: {$aprobado}");
I read around there that it could be the backslashes but I have them well and also that it could be the localhost but I also did a basic test previously, and it worked, and now in the project I’m working on it doesn’t work.
Advertisement
Answer
Try to set your properties like this (change to your real domain):
$redireccionar->setReturnUrl("https://MYDAMAIN.COM/pago-finalizado.php?exito=true&id_pago={$ID_registro}") ->setCancelUrl("https://MYDAMAIN.COM/pago-finalizado.php?exito=false&id_pago={$ID_registro}");
Or make sure that your constant URL_SITIO
does represent the full qualified domain.