kilbot / WooCommerce-POS

:bangbang: All development now at https://github.com/wcpos.
http://wcpos.com
GNU General Public License v3.0
353 stars 125 forks source link

Conflict with WorldPay For WooCommerce #129

Closed ChromeOrange closed 8 years ago

ChromeOrange commented 8 years ago

One of your / our customers has reported that there is a conflict with the WooCommerce WorldPay gateway

He has been in contact with you and has reported the following

The problem is due to code in the WorldPay plugin. The developer is using the 'woocommerce_payment_complete' hook which is triggered during the order->payment_complete() method.

This hook is triggered for every order, regardless of whether it is a WorldPay order or some other gateway. The hook and associated code are attached in screenshots.

You should contact the author of the plugin (or WooThemes) and ask them to fix this code as it is interfering with other plugins.

The code he was using in the woocommerce_payment_complete function was

        function redirect ( $order ) {
            global $woocommerce;

            $order   = new WC_Order( (int) $order );

            $url = $this->get_return_url( $order );
            echo "<meta http-equiv='Refresh' content='1; Url=\"$url\"'>";

        }

Now he is using

        function redirect ( $order ) {
            global $woocommerce;

            $order   = new WC_Order( (int) $order );

            if( $order->payment_method === $this->id ) {
                $url = $this->get_return_url( $order );
                echo "<meta http-equiv='Refresh' content='1; Url=\"$url\"'>";
            }

        }

which means the woocommerce_payment_complete function isn't doing anything unless the payment gateway is WorldPay but the store owner is still reporting there is an issue.

Since the modified function is doing nothing unless WorldPay is used to pay for the order I can't see why he would still be having the issue but I'm not able to test your plugin on my site.

kilbot commented 8 years ago

The above code should fix the issue for non-WorldPay gateways. But that <meta http-equiv='Refresh' ... tag will mean WorldPay is not compatible with WooCommerce POS.

Are you sure that is the best way to achieve a gateway redirect? Couldn't you follow the standard redirect returned by gateway->process_payment() like PayPal Standard?

kilbot commented 8 years ago

Actually. scratch that comment about gateway->process_payment(), I see you are using a redirect there.

But then you are echoing a <meta http-equiv='Refresh' ... tag on woocommerce_payment_complete. When using the WC REST API, this meta tag is printed above the JSON response which causes the POS to barf.

ChromeOrange commented 8 years ago

I've been trying to come up with an alternative but no joy.

This is from the the WorldPay docs

If your system requires a full redirect to your own Webpage, you can include a META refresh (with a short delay) in the output of your payment response script (shopper response).

kilbot commented 8 years ago

No problem. Thanks for looking into the issue. It's likely that some gateways won't translate from WooCommerce to a point of sale situation.

I will add some information to docs.wcpos.com to let users know that WooCommerce POS is not compatible with WorldPay.