Search code examples
phplaravellaravel-4paypalpaypal-rest-sdk

Laravel 4.2 and PayPal SDK


Can anyone tell me why I'm getting the following error:

exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'PayPal\Rest\ApiContext' not found'

Here is my Controller code:

<?php

use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\ExecutePayment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;

class PaypalPaymentController extends BaseController {

    private $_api_context;

    public function __construct() { 

        // setup PayPal api context
        $paypal_conf = Config::get('paypal');
        $this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
        $this->_api_context->setConfig($paypal_conf['settings']);

    }

I'm not sure what the Service Provider needs to be, either... could someone fill in that blank at least?


Solution

  • I just installed the package from composer on a L5 installation and it worked, so here's what I think will help you:

    If you're not using composer, remove everything related to paypal and use it, it helps.. a lot.

    Remove the paypal package from composer.json, composer update, composer dumpautoload, php artisan cache:clear.

    Add the package again, I did it with "paypal/rest-api-sdk-php": "1.3.*". composer update.

    Test it using php artisan tinker, like this: new PayPal\Rest\ApiContext(), should return some blue lines describing the object.

    I SERIOUSLY believe this is a composer problem, I had the same problem with another payment package, but nothing was namespaced, they used classmap loading, paypal uses psr-0. This was the question: Not namespaced, classmap loaded package required from composer makes php throw Class not found