Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token not found after payment - Query parameters are added on the callback url #12

Closed
adrienlamotte opened this issue Jan 2, 2023 · 2 comments

Comments

@adrienlamotte
Copy link

Hello!

I'm trying to use Axepta with your bundle. The payment is working, but there is an error on the callback:

// https://127.0.0.1:8000/admin/payment/callback?payum_token=J3ijH1J8RdhWAtPU4AWwxA-vUNAQIQggYGvwR132wk8?Len=655&Data=...
A token with hash `J3ijH1J8RdhWAtPU4AWwxA-vUNAQIQggYGvwR132wk8?Len=655` could not be found.

Has you can see, there is a ?Len=655&Data= after the callback url generated by Payum...

My prepare route is :

/**
     * @Route("/prepare", name="prepare", methods={"GET"})
     */
    public function prepare(Payum $payum)
    {
        $gatewayName = 'axepta';

        $storage = $payum->getStorage('App\Entity\Payment');

        $payment = $storage->create();
        $payment->setNumber(uniqid());
        $payment->setCurrencyCode('EUR');
        $payment->setTotalAmount(123); // 1.23 EUR
        $payment->setDescription('Test');
        $payment->setClientId('1');
        $payment->setClientEmail('myemail@gmail.com');

        $storage->update($payment);

        $captureToken = $payum->getTokenFactory()->createCaptureToken(
            $gatewayName,
            $payment,
            $this->generateUrl("admin_payment_callback", [], UrlGeneratorInterface::ABSOLUTE_URL) // the route to redirect after capture
        );

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

The callback route is simply :

    /**
     * @Route("/callback", name="callback", methods={"GET"})
     */
    public function callback(Request $request, Payum $payum)
    {
        $token = $payum->getHttpRequestVerifier()->verify($request);
    }

Do you have any idea on how it could be fixed?

@RomulusED69
Copy link
Collaborator

In order to solve this problem, I added, in my route, the parameter payum_token like this:

/**
* @Route("/callback/{payum_token}", name="callback", methods={"GET"})
*/

@adrienlamotte
Copy link
Author

Thank your for your answer @RomulusED69.

I already tried that yesterday, but I couldn't make it work. With your answer I digged a bit more in Payum an I saw:

if (0 === strpos($targetPath, 'http')) {
            $targetUri = HttpUri::createFromString($targetPath);
            $targetUri = $this->addQueryToUri($targetUri, $targetParameters);

            $token->setTargetUrl((string) $targetUri);
        } else {
            $token->setTargetUrl($this->generateUrl($targetPath, $targetParameters));
        }

So I needed to changed my capture to just use the target route name, and not the generated url:

$captureToken = $payum->getTokenFactory()->createCaptureToken(
            $gatewayName,
            $payment,
            "admin_payment_callback" // Do not generate url here
);

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants