pronamic / wp-pay-core

Core components for the WordPress payment processing library. This library is used in the WordPress plugin Pronamic Pay: https://www.pronamicpay.com/, but also allows other plugin developers to set up a payment plugin.
https://www.wp-pay.org/
GNU General Public License v3.0
27 stars 3 forks source link

Issue while closing Home URL change notice. #175

Closed knit-pay closed 5 months ago

knit-pay commented 5 months ago

In Pronamic Pay version 9.7.1, when we change home URL, admin sees notice sometime like this.

Pronamic Pay — We noticed the WordPress home URL has changed from "https://dev.localdomain/wordpress-dev" to "http://dev.localdomain/wordpress-dev". Please verify the payment gateway settings. For example, you might want to switch between live and test mode or need to update an URL at the gateway to continue receiving payment status updates. Also keep an eye on pending payments to discover possible configuration issues.

when we try to close this box, box does not get closed. We are getting this error

Action failed. Please refresh the page and retry.

Is this a known issue? Is it already fixed in the new version?

remcotolsma commented 5 months ago

This is not a known issue, i also can't reproduce this issue. Testen this on a fresh wp-env test environment with WordPress 6.4.3 and a production site also with WordPress 6.4.3. You can test this by going to /wp-admin/options.php and change the pronamic_pay_home_url option to a value other than the home option value. Perhaps the website in question has a problem with handling nonces?

https://github.com/pronamic/wp-pay-core/blob/c38da296b71c866d16d89b3273ac27bc0aab72e4/src/HomeUrlController.php#L146-L148

rvdsteege commented 5 months ago

The 'Action failed' message also occurs if the new value for the URL is the same as the current value. This can occur if there are filters in play for the home option. Did you notice the difference in https:// and http:// in the mentioned URLs? You might want to update your site URL to https:// if it is now using http://.

remcotolsma commented 5 months ago

Thanks, I suggest that we clarify the error messages:

https://github.com/pronamic/wp-pay-core/blob/c38da296b71c866d16d89b3273ac27bc0aab72e4/src/HomeUrlController.php#L145-L159

For example:

The security code (nonce) to verify your dismiss action expired or was invalid, please refresh and try again.

Unable to dismiss the home URL change because the home URL option could not be updated, please refresh and try again.

knit-pay commented 5 months ago

The 'Action failed' message also occurs if the new value for the URL is the same as the current value. This can occur if there are filters in play for the home option. Did you notice the difference in https:// and http:// in the mentioned URLs? You might want to update your site URL to https:// if it is now using http://.

Yes, this error is getting occurred in the websites who are using http instead of https. When we try to close the box, we are getting this error. When we change the URL in settings from http to https. error goes away.

If you want to reproduce the error. Just change the https to http on any of your test website. You will not be able to close the box in this case.

remcotolsma commented 5 months ago

Thanks, for the update, this is already improved in https://github.com/pronamic/wp-pay-core/commit/52e5d375e57e79930118d5120fa6c36ed4eb20c9. In this scenario, the following error occurred:

https://github.com/pronamic/wp-pay-core/blob/c38da296b71c866d16d89b3273ac27bc0aab72e4/src/HomeUrlController.php#L154-L158

Instead of \home_url() we now use \get_option( 'home' ), so that we always work with the unfiltered home URL link. You can of course still wonder whether it would not be better to also change the home URL to the 'https://' URL. Also improved the error messages in https://github.com/pronamic/wp-pay-core/commit/b1c50c2c74947c200650d7b0538b18c8963cb4bb.