1

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.

Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63
  • Have you taken a look to the log file that PayPal creates ? – angelcool.net Jul 28 '15 at 02:34
  • @angelcool.net I'm getting this: [28-07-2015 02:43:39] PayPal\Core\PayPalHttpConnection: INFO : POST https://api.sandbox.paypal.com/v1/oauth2/token [28-07-2015 02:43:40] PayPal\Core\PayPalHttpConnection: INFO : Invalid or no certificate authority found - Retrying using bundled CA certs file – Hirad Roshandel Jul 28 '15 at 02:45
  • Check your CA cert file as the log suggests. I am afraid it is not updated. Update your CA bundle cert files, everything will be back to normal. – Maz Jul 28 '15 at 09:50
  • 1
    Also, this might help: [Issue with CA file missing](http://stackoverflow.com/questions/13574996/paypal-ipn-getting-blank-confirmation-should-be-verified-or-invalid) – Maz Jul 28 '15 at 09:57

1 Answers1

0

It turned out the problem was in add-funds.php which was redirecting user to another page and all parameters were getting lost in the process. The code I posted works properly.

Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63