Payum / PayumBundle

Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
https://payum.gitbook.io/payum
MIT License
569 stars 142 forks source link

Symfony3 - Unable to generate a URL for the named route #328

Closed cklm closed 8 years ago

cklm commented 8 years ago

Hi,

I'm using Payum-Bundle dev-master with Symfony 3.0.1.

I stick to the documentation and created an controller for an offline-capture:

class PaymentController extends Controller {

    /**
     * @Route("/start-payment", name="payment_start")
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function prepareAction() {

        $gatewayName='offline';

        $storage=$this->get('payum')->getStorage('AppBundle\Entity\Payment');

        /** @var Payment $payment */
        $payment=$storage->create();
        $payment->setNumber(uniqid());
        $payment->setCurrencyCode('EUR');
        $payment->setTotalAmount(12300);
        $payment->setDescription('Description');
        $payment->setClientId('12345');
        $payment->setClientEmail('test@test.com');
        $storage->update($payment);

        $captureToken=$this->get('payum.security.token_factory')->createCaptureToken(
            $gatewayName,
            $payment,
            'payment_done'
        );

        return $this->redirect($captureToken->getTargetUrl());

    }

    /**
     * @Route("/finished-payment", name="payment_done")
     * @param Request $request
     */
    public function doneAction(Request $request) {
        $token=$this->get('payum.security.http_request_verifier')->verify($request);
        $gateway=$this->get('payum')->getGateway($token->getGatewayName());
        [...]
    }
}

When I want to test that, the following error occures: Unable to generate a URL for the named route "/projects/payum-test/web/app_dev.php/finished-payment?payum_token=a0xg5VoNHazlHh1eee3clZD9vV5HCvOTuX2TRs-Jqa4" as such route does not exist. Thats correct - the name of the route is "payment_done". So it seems, that createCaptureToken() already generates the url, which leads to the error, when the router tries to generate the same route/the url again.


The error seems to be in AbstractTokenFactory, Line 39: if (0 === strpos($targetPath, 'http')) { as the generated path doesn't start with http, this if is false and triggers the url-generation in Line 49.


Replacing the payment_done with a self generated url in createCaptureToken works for me:

$captureToken=$this->get('payum.security.token_factory')->createCaptureToken(
    $gatewayName,
    $payment,
    $this->get('router')->generate('payment_done',array(),0)
);

Next error - using PaypalExpress the following error is thrown: The given URL: "///projects/payum-test/web/app_dev.php/payment/capture/K2Dp0GW-NeypqWkcL-4p0uwx1TC6zblXYZkejVZguLk" could not be parse in vendor\league\url\src\AbstractUrl.php at line 26. There seems to be a bigger problem with urls...

Komet commented 8 years ago

Have a look at this commit: https://github.com/Payum/Payum/commit/716821215c8154920355fa53b9bfe16d2df9fda7 It should fix at least your last problem and maybe also the first one.

makasim commented 8 years ago

@cklm could you confirm you use the latest available version of payum/payum and payum/payum-bundle. the master branch.

cklm commented 8 years ago

Thanks for the hint - using payum/payum dev-master fixes both problems.

makasim commented 8 years ago

closing then. Feel free to reopen if there is something left.