Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paypal sdk 'Class 'PayPal\Rest\ApiContext' not found'

I'm trying to implement paypal api sdk using this code

require('vendor/autoload.php');
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;

$api = new ApiContext(
 new OAuthTokenCredential(
    'client id',
    'secret'
 )
);

$api->setConfig([
 'mode'=>'sandbox',
 'http.ConnectionTimeOut'=>30,
 'log.LogEnabled'=>false,
 'log.FileName'=>'',
 'log.LogLevel'=>'FINE',
 'validation.level'=>'log'
]);

The Rest and Auth folders are subfolders of PayPal folder which exists inside the vendor folder. But I get this error "Class 'PayPal\Rest\ApiContext' not found"

like image 971
PHP User Avatar asked Jan 03 '15 13:01

PHP User


2 Answers

Same error here. Solved reading the documentation:

require('vendor/autoload.php');

$api = new \PayPal\Rest\ApiContext(
  new \PayPal\Auth\OAuthTokenCredential(
    $client_ID,
    $client_Secret
  )
);
like image 191
Michael Mammoliti Avatar answered Sep 28 '22 03:09

Michael Mammoliti


In my case of Laravel implementation, adding this solved my problem:

use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment;
use PayPal\Exception\PayPalConnectionException;
like image 32
Ahmed Numaan Avatar answered Sep 28 '22 01:09

Ahmed Numaan