btcpayserver / magento2-plugin

4 stars 5 forks source link

Long redirect #14

Open pbritka opened 1 year ago

pbritka commented 1 year ago

Has anyone experienced this problem?

When a user is redirected to the gateway (with QR code), there's a status javascript request that checks the status of the payment every 2 s. That is hardcoded in the BTC pay server, so not much we can do about it.

The user pays and the browser starts redirecting back to Magento btcpay/redirect/returnafterpayment (that's the URL ending with 61eaf8365c3629985bf582ad4a5d8e18c2c4ecf4). This redirects to checkout/onepage/success. However, these requests take more than 2 s. In the meantime, the status script sends another request back to Magento.

The result is that the browser tries redirecting for about 10 min, until it finally gives up and the user is redirected back to the success page.

Can we solve it somehow?

woutersamaey commented 1 year ago

Can you explain differently? It doesn't make much sense. If it redirecting or not? Why 10 minutes if it's only taking 2sec?

pbritka commented 1 year ago

Screenshot 2023-05-12 at 14 27 17

Sorry, I forgot to attach a screenshot.

Because the redirection hasn't finished and the status script initiated another redirect.

woutersamaey commented 1 year ago

So BTCPay is redirecting you every 2 seconds forever? is that what you are saying? If so, this would be a BTCPay issue and not a Magento issue.

pbritka commented 1 year ago

Yes, however there's nothing I can do with the BTC server. I just did a test on Magento side where in the ReturnAfterPayment controller I added simple exit() and it works for me. So a solution would be if I could process the whole request below 2 s. I'm just asking if anyone has faced a similar issue.

woutersamaey commented 1 year ago

Any idea why it is taking longer than 2 sec? Is it trying to connect to BTCPay API and getting a timeout perhaps? Not sure how long it should take, but 2sec may be an indication something is off. That said, Magento 2 can be very slow at times...

pbritka commented 1 year ago

Not at the moment. I'm going to look at the issue. It might be not related to BTC pay at all. Was just curious.

pbritka commented 1 year ago

I've fixed this issue. If anyone is interested, this is how I did it.

I've created a plugin for Storefront\BTCPay\Model\BTCPay\BTCPayService where I defined a different return after payment URL. This URL is just a simple controller with a template in our Magento installation. All it does is it shows a message "The payment is processing, don't close this window". There's a javascript on DOM load that redirects the customer to the original btcpay/redirect/returnafterpayment with all the needed params.

The purpose of this custom URL is that it sends out the response very quickly. It takes less than a second, which cause the status check script (which runs every 2 s) not to execute anymore and our customer is shown the checkout success page with all the code that needs to execute there.

woutersamaey commented 1 year ago

We just released v 2.0.6. Does this help your case?

pbritka commented 1 year ago

Thanks for the info. From the quick look in diff probably not, but I'll have a look when I work with this extension on our code next time. However the solution I posted last month solves the issue.