arasub
arasub

Reputation: 457

Woocommerce order key not passed to "order_pay" function. with the error message Sorry, this order is invalid and cannot be paid for

Woocommerce order fails with the error message, with the razorpay payment gatway.

Sorry, this order is invalid and cannot be paid for.

When a order is placed, the pay_url is generated as like below

https://dev-xyz.pantheonsite.io/checkout/order-pay/6339/?key=wc_order_5b421123a4g1r

But on the "order_pay" function in "WC_Shortcode_Checkout" throw error as below

Sorry, this order is invalid and cannot be paid for.

from the exception

throw new Exception( __( 'Sorry, this order is invalid and cannot be paid for.', 'woocommerce' ) );

Digging deep into this issue, woocommerce is expecting the order key from the $_GET

$order_key = $_GET['key'];

Any solution, what could be the issue?

Upvotes: 1

Views: 3847

Answers (1)

arasub
arasub

Reputation: 457

As a workaround solution:

      if($order_key === ''){
                    $order_key = get_post_meta( $order_id, '_order_key', true);
        }

If unable to get the value from the $_GET above additional code in the below which is part of class WC_Shortcode_Checkout in D:\MAMP\htdocs\webiste\wp-content\plugins\woocommerce\includes\shortcodes\class-wc-shortcode-checkout.php will solve this problem.

        } catch ( Exception $e ) {
            wc_add_notice( $e->getMessage(), 'error' );
        }
    } elseif ( $order_id ) {

        // Pay for order after checkout step
        $order_key            = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
        $order                = wc_get_order( $order_id );
      if($order_key === ''){
                    $order_key = get_post_meta( $order_id, '_order_key', true);
        }
        if ( $order && $order->get_id() === $order_id && $order->get_order_key() === $order_key ) {

One more Possible Root cause, issue can be on the Nginx config. By default the query sting might be missed in NGINX config, which could also cause issue in sending the values in $_GET

location / {
try_files $uri $uri/ /index.php?$query_string;
}

Upvotes: 2

Related Questions