{"action":"created","issue":{"url":"https://api.github.com/repos/woocommerce/woocommerce/issues/17833","repository_url":"https://api.github.com/repos/woocommerce/woocommerce","labels_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/17833/labels{/name}","comments_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/17833/comments","events_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/17833/events","html_url":"https://github.com/woocommerce/woocommerce/issues/17833","id":275641707,"number":17833,"title":"Ajax error when proceeding to pay from a payment link (#order_review form)","user":{"login":"lvl99","id":238480,"avatar_url":"https://avatars0.githubusercontent.com/u/238480?v=4","gravatar_id":"","url":"https://api.github.com/users/lvl99","html_url":"https://github.com/lvl99","followers_url":"https://api.github.com/users/lvl99/followers","following_url":"https://api.github.com/users/lvl99/following{/other_user}","gists_url":"https://api.github.com/users/lvl99/gists{/gist_id}","starred_url":"https://api.github.com/users/lvl99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lvl99/subscriptions","organizations_url":"https://api.github.com/users/lvl99/orgs","repos_url":"https://api.github.com/users/lvl99/repos","events_url":"https://api.github.com/users/lvl99/events{/privacy}","received_events_url":"https://api.github.com/users/lvl99/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-11-21T09:33:25Z","updated_at":"2017-11-27T15:10:57Z","closed_at":"2017-11-21T11:42:39Z","author_association":"NONE","body":"I'm using v3.2.4 on WordPress 4.9\r\n\r\nI have a blocking AJAX error on the `#order_review` form when customer is given payment link (e.g. `https://example.com/checkout/order-pay/14889/?pay_for_order=true&key=wc_order_5a0f2aaf28e2e`) to then pay with PayPal. Once pressing \"Proceed to payment\" there is an \"Internal Server Error\" on non-debug environments, and with my developer environment it outputs:\r\n\r\n```\r\n[21-Nov-2017 08:37:45 UTC] PHP Notice:  Undefined index: key in /Users/mattscheurich/Sites/example.com/site/web/app/plugins/woocommerce/includes/class-wc-form-handler.php on line 305\r\n[21-Nov-2017 08:37:45 UTC] PHP Stack trace:\r\n[21-Nov-2017 08:37:45 UTC] PHP   1. {main}() /Users/mattscheurich/Sites/example.com/site/web/index.php:0\r\n[21-Nov-2017 08:37:45 UTC] PHP   2. require() /Users/mattscheurich/Sites/example.com/site/web/index.php:17\r\n[21-Nov-2017 08:37:45 UTC] PHP   3. wp() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-blog-header.php:16\r\n[21-Nov-2017 08:37:45 UTC] PHP   4. WP->main() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/functions.php:960\r\n[21-Nov-2017 08:37:45 UTC] PHP   5. do_action_ref_array() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp.php:726\r\n[21-Nov-2017 08:37:45 UTC] PHP   6. WP_Hook->do_action() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/plugin.php:515\r\n[21-Nov-2017 08:37:45 UTC] PHP   7. WP_Hook->apply_filters() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp-hook.php:310\r\n[21-Nov-2017 08:37:45 UTC] PHP   8. WC_Form_Handler::pay_action() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp-hook.php:286\r\n[21-Nov-2017 08:37:45 UTC] PHP Notice:  Undefined index: order-pay in /Users/mattscheurich/Sites/example.com/site/web/app/plugins/woocommerce/includes/class-wc-form-handler.php on line 306\r\n[21-Nov-2017 08:37:45 UTC] PHP Stack trace:\r\n[21-Nov-2017 08:37:45 UTC] PHP   1. {main}() /Users/mattscheurich/Sites/example.com/site/web/index.php:0\r\n[21-Nov-2017 08:37:45 UTC] PHP   2. require() /Users/mattscheurich/Sites/example.com/site/web/index.php:17\r\n[21-Nov-2017 08:37:45 UTC] PHP   3. wp() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-blog-header.php:16\r\n[21-Nov-2017 08:37:45 UTC] PHP   4. WP->main() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/functions.php:960\r\n[21-Nov-2017 08:37:45 UTC] PHP   5. do_action_ref_array() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp.php:726\r\n[21-Nov-2017 08:37:45 UTC] PHP   6. WP_Hook->do_action() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/plugin.php:515\r\n[21-Nov-2017 08:37:45 UTC] PHP   7. WP_Hook->apply_filters() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp-hook.php:310\r\n[21-Nov-2017 08:37:45 UTC] PHP   8. WC_Form_Handler::pay_action() /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp-hook.php:286\r\n[21-Nov-2017 08:37:45 UTC] PHP Fatal error:  Uncaught Error: Call to a member function get_id() on boolean in /Users/mattscheurich/Sites/example.com/site/web/app/plugins/woocommerce/includes/class-wc-form-handler.php:309\r\nStack trace:\r\n#0 /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp-hook.php(286): WC_Form_Handler::pay_action(Object(WP))\r\n#1 /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(false, Array)\r\n#2 /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/plugin.php(515): WP_Hook->do_action(Array)\r\n#3 /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/class-wp.php(726): do_action_ref_array('wp', Array)\r\n#4 /Users/mattscheurich/Sites/example.com/site/web/cms/wp-includes/functions.php(960): WP->main('')\r\n#5 /Users/mattscheurich/Sites/example.com/site/web/cms/wp-blog-header.php(16): wp()\r\n#6 /Users/mattscheurich/Sites/example.com/site/web/index.php(17): require('/Users/mattsche...')\r\n#7 {main}\r\n  thrown in /Users/mattscheurich/Sites/example.com/site/web/app/plugins/woocommerce/includes/class-wc-form-handler.php on line 309\r\n```\r\n\r\nLooking at the code, it seems to be breaking in `class-wc-form-handler.php` on these lines:\r\nhttps://github.com/woocommerce/woocommerce/blob/8801279c103c0bc77749d6e9163ede5ba0e8cf43/includes/class-wc-form-handler.php#L304-L307\r\n\r\nIt seems that the AJAX request itself doesn't have the `key` passed as a `$_GET` query variable, so the operation fails to fetch the order ID:\r\n![image](https://user-images.githubusercontent.com/238480/33063754-b2726c36-cea3-11e7-83e6-8782df5331e3.png)\r\n\r\nI see that the key is available in the `_wp_http_referer` so I attempted this minor rewrite to ensure that I could get it based on the order key:\r\n```php\r\n      // Pay for existing order\r\n      parse_str( preg_replace( '/^[^\\?]*\\?/', '', $_POST['_wp_http_referer'] ), $extracted );\r\n      $order_key  = isset( $_GET['key'] ) ? $_GET['key'] : $extracted['key'];\r\n      $order_id   = ! empty( $wp->query_vars['order-pay'] ) ? absint( $wp->query_vars['order-pay'] ) : wc_get_order_id_by_order_key( $order_key );\r\n      $order      = wc_get_order( $order_id );\r\n```\r\n\r\nI'm not sure if that is a good rewrite, as there might be other use cases for this particular action. It seems that I now don't get the errors about the undefined `key` and `order-pay` variables (good!), but the action still doesn't go through (bad!) and I get an error message in the frontend:\r\n```json\r\n{\"result\":\"failure\",\"messages\":\"<div class=\\\"site-message-error\\\">\\n  <ul class=\\\"site-message-inner\\\">\\n\\t\\t\\t<li>We were unable to process your order, please try again.<\\/li>\\n\\t  <\\/ul>\\n<\\/div>\\n\",\"refresh\":true,\"reload\":false}\r\n```\r\n\r\nAny ideas?"},"comment":{"url":"https://api.github.com/repos/woocommerce/woocommerce/issues/comments/347211253","html_url":"https://github.com/woocommerce/woocommerce/issues/17833#issuecomment-347211253","issue_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/17833","id":347211253,"user":{"login":"lvl99","id":238480,"avatar_url":"https://avatars0.githubusercontent.com/u/238480?v=4","gravatar_id":"","url":"https://api.github.com/users/lvl99","html_url":"https://github.com/lvl99","followers_url":"https://api.github.com/users/lvl99/followers","following_url":"https://api.github.com/users/lvl99/following{/other_user}","gists_url":"https://api.github.com/users/lvl99/gists{/gist_id}","starred_url":"https://api.github.com/users/lvl99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lvl99/subscriptions","organizations_url":"https://api.github.com/users/lvl99/orgs","repos_url":"https://api.github.com/users/lvl99/repos","events_url":"https://api.github.com/users/lvl99/events{/privacy}","received_events_url":"https://api.github.com/users/lvl99/received_events","type":"User","site_admin":false},"created_at":"2017-11-27T15:10:57Z","updated_at":"2017-11-27T15:10:57Z","author_association":"NONE","body":"Fair enough 🙌. That might also explain the variety of different types of CSS class names used throughout the templates too."}}
{"actor":{"display_login":"lvl99"}}