vuestorefront / shopware-pwa

Shopware PWA for eCommerce. Headless storefront solution for Shopware 6, which communicates through the SalesChannel-API. Always Open Source, MIT license. Made with :blue_heart: by shopware AG & Vue Storefront.
https://frontends.shopware.com
MIT License
345 stars 103 forks source link

[BUG] Incorrect redirect url after payment with STRIPE #1445

Closed cruonline closed 2 years ago

cruonline commented 3 years ago

Describe the bug

After making a payment with STRIPE user is redirected to "http://shop.backend.url/payment/finalize-transaction instead of http://shop.frontent.url/order/###

The call to /pay endpoint contains the proper URL, however, stripe receives a payment object with the wrong redirect URL. In a result, user lands on "classic" storefront channel, not PWA Disabling this channel leads to 500 error on both redirect and webhook calls.

This may be problem with stripe plugin, not shopware-pwa, but any help will be greatly appreciated :)

Additional context

Shopware 6.3.5.4 phopware-pwa 0.8.1 PWA Integration (v0.2.1)

elkmod commented 3 years ago

Actually, this is working properly, you need the /payment/finalize-transaction endpoint to be available as it will eventually emit a 301 redirect back to your client, after updating the payment state. We are trying to figure out another day of doing this, but for the moment, it is the only way to inform Shopware about the payment status. Stripe should not redirect straight to your PWA, as Shopware wouldn't be able to know about anything that happened in the meantime.

cruonline commented 3 years ago

@elkmod I'm petty sure, webhooks are for this purpose and they are triggered async and headless in most cases. Webhooks are in fact most important way of communication between payment gates, as allow delayed approval, chargeback and other scenarios without user interaction. (eg. browser dies, user closes browser or navigates away)

Redirect is meant for end user consistent flow, and it is not needed for shopware to handle payment. Yes I know it contains payment details (if completed) but it is supplementary (and we can also decode it on PWA if we choose to)

As for the /payment/finalize-transaction endpoint, it redirects user to login screen, so there goes redirection to PWA... :(

If I am talking nonsense, I am sorry. But I have tested it, by blocking redirection in browser and payment was registered in shopware. Unless I messed up something :)

cruonline commented 3 years ago

any further comments, feedback? If I'm wrong, ELI5

cruonline commented 3 years ago

Anyone willing to help me? Bug or not aside, how to prevent user being stopped at login page after payment callback.

mkucmus commented 3 years ago

hi @cruonline, in the upcoming release we've got it done like it's here: https://github.com/vuestorefront/shopware-pwa/blob/master/packages/default-theme/src/pages/checkout.vue#L190

  1. we are calling handlePayment with success and failure page's provided as the parameters.
  2. notice we are using getAbsoluteUrl method that generates the whole PWA URL like "http://localhost:3000/en-US/success".

Under the hood, the handle-payment endpoint saves these URL to know what's the URL the customer has to be redirected in success/fail scenarios (special token is generated to identify the config). After the payment is done, the payment provider redirects the customer to finalize-transaction of API and then to the one of provided URLS (finishUrl or errorUrl in handle-payment method)

I recommend you to follow this flow and see what will happen 👍🏻 let us know if it's working :)

cruonline commented 3 years ago

thanks @mkucmus , I will give it a try. Keep up the good work!

mkucmus commented 3 years ago

@cruonline did it work? ;)

cruonline commented 3 years ago

@mkucmus I was decided (not by me) to skip PWA fronted for now, and focus on delivering "classic" SW6 experience first :( I will get back to it, just not now. If not for the current project, for sure next one, as I love the idea of SPA/PWA shop experience.

mkucmus commented 2 years ago

Ok then :) We've been using paypal & adyen payment plugins and no such error occured. So I'm closing the issue.