creagia / laravel-redsys

Integrate your Laravel application with Redsys, the lead payment gateway in Spain.
MIT License
10 stars 2 forks source link

InvalidArgumentException Action App\Http\Controllers\Creagia\LaravelRedsys\Controllers\RedsysNotificationController not defined. #39

Closed edu27 closed 8 months ago

edu27 commented 8 months ago

Hi!,

I'm getting this error while making the request, and I can't figure out what is the cause. I don't know if I missing something after following the instructions. Using Laravel 10 the error happens in both local with local environment and production server using test environment.

InvalidArgumentException Action App\Http\Controllers\Creagia\LaravelRedsys\Controllers\RedsysNotificationController not defined. 
    vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:520 Illuminate\Routing\UrlGenerator::action
    vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:102 action
    vendor/creagia/laravel-redsys/src/RequestBuilder.php:44 Creagia\LaravelRedsys\RequestBuilder::__construct
    vendor/creagia/laravel-redsys/src/RequestBuilder.php:69 Creagia\LaravelRedsys\RequestBuilder::newRequest
    vendor/creagia/laravel-redsys/src/Concerns/CanCreateRedsysRequests.php:31 App\StudentPayment::createRedsysRequest
    app/Http/Controllers/PaymentsStudents.php:1198 App\Http\Controllers\PaymentsStudents::studentPay

This is the code generating the request.

$redsysRequest = $payment->createRedsysRequest(
    productDescription: $payment->paymentConcept->name,
    payMethod: PayMethod::Card,
);
return $redsysRequest->redirect();

Thanks!

dtorras commented 8 months ago

Can you execute composer dump-autoload and try again? It seems your application can't find the RedsysNotificationController package class.

if (! $this->requestParameters->merchantUrl) {
    $this->requestParameters->merchantUrl = action(RedsysNotificationController::class);
}

If it continues to fail, can you provide a way to reproduce the problem with a fresh Laravel installation? I wasn't able to reproduce it.

edu27 commented 8 months ago

I already done that and the issue still persist.

I've tried with this piece of code and I almost got it working. I can see the payment verification and the succcessful view but the OK and KO url should have the request UUID but if I do not set them I have the same error as before with the Notification Controller.

$redsysRequest = RequestBuilder::newRequest(
    new \Creagia\Redsys\Support\RequestParameters(
        transactionType: \Creagia\Redsys\Enums\TransactionType::Autorizacion,
        productDescription: $payment->paymentConcept->name,
        amountInCents: $payment->getTotalAmount(),
        currency: Currency::EUR,
        payMethods: \Creagia\Redsys\Enums\PayMethod::Card,
        merchantUrl: 'http://devmysuite.test/redsys/notification',
        urlOk: 'http://devmysuite.test/redsys/successful-payment/{uuid}',
        urlKo: 'http://devmysuite.test/redsys/unsuccessful-payment/{uuid}'
    )
)->associateWithModel($payment);
return $redsysRequest->redirect();

Also, I'll try fresh Laravel installation and see if it works.

edu27 commented 8 months ago

Tested on a fresh Laravel installation without problems. I have to figure out why isn't working in my current project.

dtorras commented 8 months ago

I'm closing the issue for now. Feel free to reopen it if you find anything.

edu27 commented 8 months ago

Finally found the problem. I replaced my current "app/Providers/RouteServicesProvider.php" with the content of the default Laravel 10 new project one. The project started in Laravel 5, a lot have changed since then.