3

I am trying to integrate Paypal in my web app using this package:

http://packalyst.com/packages/package/netshell/paypal

I have installed it following the instructions.

The controller is:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use PayPal;
use Redirect;

use Illuminate\Http\Request;

class PayPalController extends Controller {

    private $_apiContext;
    public function __construct() {
        $this->_apiContext = PayPal::ApiContext(
            config('services.paypal.client_id'),
            config('services.paypal.secret'));

        $this->_apiContext->setConfig(array(
            'mode' => 'sandbox',
            'service.EndPoint' => 'https://api.sandbox.paypal.com',
            'http.ConnectionTimeOut' => 30,
            'log.LogEnabled' => true,
            'log.FileName' => storage_path('logs/paypal.log'),
            'log.LogLevel' => 'FINE'
        ));
    }

    public function getCheckout() {
        $payer = PayPal::Payer();
        $payer->setPaymentMethod('paypal');

        $amount = PayPal:: Amount();
        $amount->setCurrency('EUR');
        $amount->setTotal(42); // This is the simple way,
        // you can alternatively describe everything in the order separately;
        // Reference the PayPal PHP REST SDK for details.

        $transaction = PayPal::Transaction();
        $transaction->setAmount($amount);
        $transaction->setDescription('What are you selling?');

        $redirectUrls = PayPal:: RedirectUrls();
        $redirectUrls->setReturnUrl(action('PayPalController@getDone'));
        $redirectUrls->setCancelUrl(action('PayPalController@getCancel'));

        $payment = PayPal::Payment();
        $payment->setIntent('sale');
        $payment->setPayer($payer);
        $payment->setRedirectUrls($redirectUrls);
        $payment->setTransactions(array($transaction));

        $response = $payment->create($this->_apiContext);
        $redirectUrl = $response->links[1]->href;

        return Redirect::to( $redirectUrl );
    }

    public function getDone(Request $request) {
        $id = $request->get('paymentId');
        $token = $request->get('token');
        $payer_id = $request->get('PayerID');

        $payment = PayPal::getById($id, $this->_apiContext);

        $paymentExecution = PayPal::PaymentExecution();

        $paymentExecution->setPayerId($payer_id);
        $executePayment = $payment->execute($paymentExecution, $this->_apiContext);

        // Clear the shopping cart, write to database, send notifications, etc.

        // Thank the user for the purchase
        return view('checkout.done');
    }

    public function getCancel() {
        // Curse and humiliate the user for cancelling this most sacred payment (yours)
        return view('checkout.cancel');
    }

}

I then created a route:

Route::get('/paypal/checkout', [
    'as' => 'get-paypal-checkout', 'uses' => 'PayPalController@getCheckout'
]);

But, when I go to that route I get:

FatalErrorException in PayPalController.php line 14: Class 'PayPal' not found in PayPalController.php line 14

From what I can see, I've done my namespacing and use correctly. New to all this.

Any help would be appreciated. Thanks!

EDIT:

I've changed the top of PayPalController.php to:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Netshell\PayPal;
use Redirect;
use Illuminate\Http\Request;

But it still doesn't work. Class 'Netshell\PayPal' not found

2
  • I think the Namespace is wrong, try use Netshell/Paypal in PayPalController
    – haakym
    Jun 8, 2015 at 12:03
  • Tried it and still get error. Check my edit on OP.
    – KriiV
    Jun 8, 2015 at 12:10

4 Answers 4

6

It might be because of the typo you have in the class name. use Paypal; rather than use PayPal;.

5
  • Also tried that: Class 'Netshell\Paypal' not found
    – KriiV
    Jun 8, 2015 at 12:24
  • @kriiV Use only use Paypal; without Netshell.
    – Mahozi
    Jun 8, 2015 at 12:26
  • That worked! Now I get: Action App\Http\Controllers\PayPalController@getDone not defined.
    – KriiV
    Jun 8, 2015 at 12:31
  • Hey did you solve your problem cause i got the same problem too. Action App\Http\Controllers\PayPalController@getDone not defined.
    – Grald
    Nov 25, 2015 at 13:00
  • The example code in git net-shell/laravel-paypal package should be updated. Thanks mate ! Jun 25, 2017 at 13:11
1

I have the same problem, but here is solution: add in providers list:

Anouar\Paypalpayment\PaypalpaymentServiceProvider::class,

and in aliases:

'Paypal' => Anouar\Paypalpayment\Facades\PaypalPayment::class,

and will works.

0

See the file PayPal.php here: https://github.com/net-shell/laravel-paypal/blob/master/src/Netshell/Paypal/Paypal.php (you could also find this in your project after adding it with composer here: vendor/Netshell/Paypal most likely)

The first line shows the namespace is: namespace Netshell\Paypal;

Update your PayPalController.php with use Netshell/Paypal instead of use Paypal and it should work.

1
  • Can you see the file in your vendor directory? What does your composer.json required array look like?
    – haakym
    Jun 8, 2015 at 12:26
0

check aliases and make sure its PayPal and not Paypal ('PayPal' => Netshell\Paypal\Facades\Paypal::class,)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.