Payum / PayumLaravelPackage

Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
https://payum.forma-pro.com/
MIT License
122 stars 38 forks source link

ReflectionException in Container.php line 737: Class payum does not exist #29

Closed cspreston closed 8 years ago

cspreston commented 8 years ago

using "payum/paypal-express-checkout-nvp":"0.15.*" laravel version 5.1

got this error.

ReflectionException in Container.php line 737: Class payum does not exist

in Container.php line 737
at ReflectionClass->__construct('payum') in Container.php line 737
at Container->build('payum', array()) in Container.php line 627
at Container->make('payum', array()) in Application.php line 674
at Application->make('payum') in Facade.php line 216
at Facade::__callStatic('make', array('payum')) in PaypalController.php line 22
at App::make('payum') in PaypalController.php line 22
at PaypalController->prepareExpressCheckout()
at call_user_func_array(array(object(PaypalController), 'prepareExpressCheckout'), array()) in Controller.php line 256
at Controller->callAction('prepareExpressCheckout', array()) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(PaypalController), object(Route), 'prepareExpressCheckout') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(PaypalController), object(Route), object(Request), 'prepareExpressCheckout') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\PaypalController', 'prepareExpressCheckout') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 712
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 714
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 679
at Router->dispatchToRoute(object(Request)) in Router.php line 639
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\xampp\htdocs\dailylunch\public\index.php') in index.php line 21
makasim commented 8 years ago

I've never got it, so not able to fix it, Could you investigate it further and fix,

BTW why not use 1.0?

ribagek commented 8 years ago

Facing the same issue. Laravel 5.1

From composer.json

    "payum/payum-laravel-package": "^1.0",
    "payum/payum": "^1.0"

My PaymentController:

namespace App\Http\Controllers;

use Payum\LaravelPackage\Controller\PayumController;

class PaymentController extends PayumController {

public function payum()
{
    $storage = $this->getPayum()->getStorage('Payum\Core\Model\Payment');
    dd($this->getPayum());
    $details = $storage->create();
    $details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
    $details['PAYMENTREQUEST_0_AMT'] = 1.23;
    $storage->update($details);

    $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('paypal_ec', $details, 'payment_done');

    return \Redirect::to($captureToken->getTargetUrl());
}
}
makasim commented 8 years ago

Hm, I am not sure but I suspect you haven't registered the payum service? Could you confirm you did it?

Btw, Do you use laravel 5?

ribagek commented 8 years ago

Yes, you're right, it was the reason. In Get it started there is no info about registering service. So I registered Payum\LaravelPackage\PayumServiceProvider and now getting "Token storage must be configured" error. And yes, I use 5.1 Laravel

makasim commented 8 years ago

Indeed the doc miss this part, gonna fix it. To solve token storage must be configure you have to add a token storage to the payum builder, most like you want to choose eloquent storage.

<?php

// bootstrap/start.php

use Payum\LaravelPackage\Storage\EloquentStorage;
use Payum\LaravelPackage\Model\Token;

App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
    $payumBuilder
        ->setTokenStorage(new EloquentStorage(Token::class))
    ;
});
ribagek commented 8 years ago

ok, but bootstrap/start.php is for Laravel 4. Where to put this config in L5.1?

makasim commented 8 years ago

Put in any other place which is similar to start.php and where you can do similar things. I am not laravel developer. I dont know

makasim commented 8 years ago

This what you have to do to fix the reflection bug: https://github.com/makasim/PayumLaravelBundleSandbox/blob/payum-examples2/app/config/app.php#L124

makasim commented 8 years ago

The doc is updated: https://github.com/Payum/PayumLaravelPackage/blob/master/docs/get-it-started.md

ribagek commented 8 years ago

Have succeeded with package setup. Here what you need to do if you use L5.1

  1. Piece of code that resolves PayumBuilder should go from bootstrap/start.php to some ServiceProvider, for example PayumServiceProvider:

    namespace App\Providers;
    
    use Illuminate\Support\ServiceProvider;
    
    use Payum\LaravelPackage\Storage\EloquentStorage;
    use Payum\LaravelPackage\Model\Token;
    //use Payum\LaravelPackage\Model\Payment;
    use \App\Payment;
    
    class PayumServiceProvider extends ServiceProvider {
    public function register()
    {
       \App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
           $payumBuilder
               ->setTokenStorage(new EloquentStorage(Token::class))
               ->addStorage(Payment::class, new EloquentStorage(Payment::class))
               ->addGateway('paypal_ec', [
                   'factory' => 'paypal_express_checkout',
                   'username' => config('payum.username'),
                   'password' => config('payum.password'),
                   'signature' => config('payum.signature'),
                   'sandbox' => config('payum.sandbox')
               ])
           ;
       });
    }
    
    }
  2. Here you can use Payment model from the package and API call should be successfull but it will give an error if using Payment done controller code from example: https://github.com/Payum/PayumLaravelPackage/blob/master/docs/payment_done_controller.md. Because it doesn't implement Iterator interface and iterator_to_array will crash. So we need to extend base model, implement IteratorAggregate and add method from the Interface:

    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use IteratorAggregate;
    use ArrayIterator;
    
    class Payment extends \Payum\LaravelPackage\Model\Payment implements IteratorAggregate
    {
    
       public function getIterator()
      {
           return new ArrayIterator($this->getDetails());
       }
    }

Good luck!

makasim commented 8 years ago

@ribagek Thank you for sharing. I'll adjust the docs with what you write here, do you want to do it maybe?

Though I am not sure about the second part. The done action is the action where you put your own logic, iterator_to_array is used just to show you that you have access to all payment details. Feel free to remove it completely and put there whatever you need. Do not implement IteratorAggregate interface until you need it in your business logic

ribagek commented 8 years ago

totaly agree about 2nd. Thanks, I will add this to docs