I'm trying to use PayPal PHP SDK to integerate paypal into my website. Eveything seems to be working except after Success or Fail the return url doesn't include neither the parameters defined by me nor ones returned by paypal such as paymentId, PayerID & token. Here is my php file:
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Exception\PayPalConnectionException;
require './paypal.php';
$payer = new Payer();
$details= new Details();
$amount= new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls=new RedirectUrls();
//payer
$payer->setPaymentMethod('paypal');
//details
$details->setShipping('2.00')
->setTax('0.00')
->setSubtotal('20.00');
//amount
$amount->setCurrency('USD')
->setTotal('22.00')
->setDetails($details);
//transcation
$transaction->setAmount($amount)
->setDescription('Membership');
//payment
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions([$transaction]);
//redirect
$redirectUrls->setReturnUrl('http://localhost/test/add-funds.php?approved=true')
->setCancelUrl('http://localhost/test/add-funds.php?approved=false');
$payment->setRedirectUrls($redirectUrls);
try{
$payment->create($api);
//generate and store hash
//prepare and execute transaction storage
}catch(PayPalConnectionException $e){
echo $e->getData();
header('Location:../test/add-funds.php');
}
$approvalUrl = $payment->getApprovalLink();
header('Location:'.$approvalUrl);
this is my paypal.php file
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
$client='client';
$secret='secret';
$api= new ApiContext(new OAuthTokenCredential($client,$secret));
$api->setConfig([
'mode' => 'sandbox',
'http.ConnectionTimeOut'=> 30,
'log.LogEnabled' => false,
'log.FileName' => '',
'log.LogLevel' =>'FINE',
'validation.level'=>'log'
]);
Edit: After $payment->create($api); I also check $payment->getId() it has the proper value.