Sylius / Sylius

Open Source eCommerce Framework on Symfony
https://sylius.com
MIT License
7.95k stars 2.1k forks source link

Paypal Express Checkout fails with unable to find token #3494

Closed addersuk closed 8 years ago

addersuk commented 9 years ago

I've recently installed Sylis Standard edition and i'm really impressed with the system. However i'm having a problem with Paypal integration. The payment method is setup in admin as Paypay Express Checkout and i've set the 4 settings in parameters.yml.

When i return from Paypal after payment, i'm shown a 404 page and the following error appears in the Symfony2 log

http://site.com/payment/capture/xxx?token=tokenid&PayerID=payerid

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "A token with hash xxx could not be found." at sylius-standard/vendor/payum/payum/src/Payum/Core/Bridge/Symfony/Security/HttpRequestVerifier.php line 48 {"exception":"[object](Symfony\Component\HttpKernel\Exception\NotFoundHttpException%28code: 0%29: A token with hash xxx could not be found. at sylius-standard/vendor/payum/payum/src/Payum/Core/Bridge/Symfony/Security/HttpRequestVerifier.php:48)"} []

When i check the payment details in the admin panel the details appear to match, ie R e t u r n u r l: http://site.com/payment/capture/xxx C a n c e l u r l: http://site.com/payment/capture/xxx P a y m e n t r e q u e s t 0 n o t i f y u r l: http://site.com/payment/notify/yyy

Plus some fields seem to indicate that payment was successful: P a y m e n t i n f o 0 c u r r e n c y c o d e: GBP P a y m e n t i n f o 0 p a y m e n t s t a t u s: Completed P a y m e n t i n f o 0 p e n d i n g r e a s o n: None P a y m e n t i n f o 0 r e a s o n c o d e: None P a y m e n t i n f o 0 p r o t e c t i o n e l i g i b i l i t y: Eligible P a y m e n t i n f o 0 p r o t e c t i o n e l i g i b i l i t y t y p e: ItemNotReceivedEligible,UnauthorizedPaymentEligible P a y m e n t i n f o 0 e r r o r c o d e: 0 P a y m e n t i n f o 0 a c k: Success T r a n s a c t i o n i d: bbb L n a m e0: 1 P a y m e n t r e q u e s t 0 t r a n s a c t i o n i d: bbb P a y m e n t r e q u e s t 0 s o f t d e s c r i p t o r: PAYPAL ** L p a y m e n t r e q u e s t 0 n a m e0: 1 P a y m e n t r e q u e s t i n f o 0 t r a n s a c t i o n i d: bbb P a y m e n t r e q u e s t 0 t r a n s a c t i o n t y p e: cart P a y m e n t r e q u e s t 0 p a y m e n t t y p e: instant P a y m e n t r e q u e s t 0 o r d e r t i m e: 2015-10-26T21:05:20Z P a y m e n t r e q u e s t 0 f e e a m t: 0.?? P a y m e n t r e q u e s t 0 p a y m e n t s t a t u s: Completed P a y m e n t r e q u e s t 0 p e n d i n g r e a s o n: None P a y m e n t r e q u e s t 0 r e a s o n c o d e: None

However the status is still not complete. On paypal the order is complete, so am i missing something or is there a problem?

Composer package versions are: omnipay/2checkout v2.1.1 omnipay/authorizenet v2.3.0 omnipay/buckaroo v2.0.1 omnipay/cardsave 2.1.2
omnipay/coinbase v2.0.4 omnipay/common v2.3.4 omnipay/dummy v2.1.1 omnipay/eway v2.2.0 omnipay/firstdata v2.2.0 omnipay/gocardless 2.2.0 omnipay/manual v2.1.1 omnipay/migs v2.1.1
omnipay/mollie v3.0.4
omnipay/multisafepay V2.2.0 omnipay/netaxept v2.3.0
omnipay/netbanx v2.1.1
omnipay/omnipay 2.3.2
omnipay/payfast v2.1.1
omnipay/payflow v2.1.1 omnipay/paymentexpress v2.1.2 omnipay/paypal v2.4.3 omnipay/pin v2.1.0 omnipay/sagepay v2.2.0 omnipay/securepay v2.1.0 omnipay/stripe v2.2.1 omnipay/targetpay v2.2.1 omnipay/worldpay v2.1.1 pagerfanta/pagerfanta v1.0.3 paypal/rest-api-sdk-php V0.5.0 paypal/sdk-core-php V1.2.0
payum/omnipay-bridge 0.14.2 payum/payum 0.14.7 payum/payum-bundle 0.14.4 sylius/sylius dev-master 7db8df6 symfony/symfony v2.7.5

Let me know if you need further info

pjedrzejewski commented 9 years ago

/cc @makasim

makasim commented 9 years ago

Where do you store tokens? Seems like it was not persisted correctly. Could you please post payum configuration part.

addersuk commented 9 years ago

I am using the standard config provided by @SyliusCoreBundle/Resources/config/app/payum.yml, so using Doctrine with a postgres database. I can see a table sylius_payment_security_token being populated, but i can only see a row for code yyy and not the xxx code provided as a parameter to the page.

http://site.com/payment/capture/xxx?token=tokenid&PayerID=payerid R e t u r n u r l: http://site.com/payment/capture/xxx C a n c e l u r l: http://site.com/payment/capture/xxx P a y m e n t r e q u e s t 0 n o t i f y u r l: http://site.com/payment/notify/yyy

Should both tokens be recorded, or is the return url incorrect

makasim commented 9 years ago

they should both recorded at prepare stage, once you are back from the paypal side the capture token is removed

addersuk commented 9 years ago

Thanks for you help, I can see them being set as i leave the site for Paypal, I'll investigate and see if i can narrow down the problem.

addersuk commented 9 years ago

To debug this i've added the following to Payum\Bundle\PayumBundle\Controller/CaptureController public function doAction(Request $request) { $token = $this->getHttpRequestVerifier()->verify($request); $logger = $this->get('logger'); $logger->info($token->getPaymentName()); $payment = $this->getPayum()->getPayment($token->getPaymentName()); $logger->info('Got the payment.'); $payment->execute(new Capture($token)); $logger->info('Invalidate the token.'); $this->getHttpRequestVerifier()->invalidate($token); $logger->info($token->getAfterUrl()); return $this->redirect($token->getAfterUrl()); }

And the following is output to the logs [2015-10-28 20:18:54] app.INFO: paypal_express_checkout [] [] [2015-10-28 20:18:54] app.INFO: Got the payment. [] [] [2015-10-28 20:18:59] app.INFO: Invalidate the token. [] [] [2015-10-28 20:18:59] app.INFO: http://shop.com/checkout/purchase/forward?payum_token=aaa [] []

Instead the following requests are made and that redirect url is never followed. Yet if i enter that link into my browser the order is then completed.
1.2.3.4 - - [28/Oct/2015:20:18:54 +0000] "GET /payment/capture/xxx?token=token&PayerID=payerid HTTP/1.1" 302 671 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0" 1.2.3.4 - - [28/Oct/2015:20:18:59 +0000] "GET /payment/capture/xxx?token=token&PayerID=payerid HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"

Have you got ant ideas what could be wrong.

michalmarcinkowski commented 8 years ago

It's not Sylius related issue, if it's still relevant please post this question on StackOverflow (it is also the official support channel for Sylius) maybe someone will be able to help you there!

makasim commented 8 years ago

There was a bug, at least I can recall one which was fixed so there should not be a problem in 1.x.x

michalmarcinkowski commented 8 years ago

:+1: