7

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"

PHP User
  • 2,350
  • 6
  • 46
  • 87

4 Answers4

6

Same error here. Solved reading the documentation:

require('vendor/autoload.php');

$api = new \PayPal\Rest\ApiContext(
  new \PayPal\Auth\OAuthTokenCredential(
    $client_ID,
    $client_Secret
  )
);
Michael Mammoliti
  • 1,517
  • 13
  • 11
4

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;
Ahmed Numaan
  • 1,034
  • 1
  • 10
  • 26
3

I am not sure if you are still facing this issue, but I would recommend going through the documentation mentioned here. This should help you find the reason why you are getting this error.

Also, making your first call documentation would really help get you started.

Jay Patel - PayPal
  • 1,489
  • 1
  • 11
  • 20
0

This solution worked for me:

  1. Download the SDK using Composer
  2. Re-Upload the Vendor directory in the App root
  • There is a working solution described in https://stackoverflow.com/questions/39400764/fatal-error-class-paypal-api-payer-not-found-en-sdk-paypal/47776518#47776518 by Olga. – olga Dec 12 '17 at 15:50