Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pseudo coupons causing Invalid discount type error during webhook execution #774

Open
kaushikasomaiya opened this issue Jan 29, 2025 · 5 comments

Comments

@kaushikasomaiya
Copy link

kaushikasomaiya commented Jan 29, 2025

9274503-zen

We've discussed it here.

Webhooks failing with "invalid discount type" message when a pseudo coupon is present in the order.

https://github.com/Automattic/woocommerce-subscriptions-core/blob/fd5f568407a797ae18d1fbcbb06c037312d0ee58/includes/class-wc-subscriptions-coupon.php#L86C1-L89C4

This is because we have a condition here to declare them only on non admin pages so when an async request is triggered through an admin page - the webhook execution will fail with

action failed via Async Request: Invalid discount type

Full Trace

2025-01-29T07:01:29+00:00 Info #0 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/class-wc-coupon.php(1194): WC_Coupon->set_discount_type('renewal_percent')
#1 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php(298): WC_Coupon->set_short_info(Array)
#2 [internal function]: WC_REST_Orders_V2_Controller->get_order_item_data(Object(WC_Order_Item_Coupon))
#3 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php(476): array_map(Array, Array)
#4 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php(573): WC_REST_Orders_V2_Controller->get_formatted_item_data(Object(Automattic\WooCommerce\Admin\Overrides\Order))
#5 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php(438): WC_REST_Orders_V2_Controller->prepare_object_for_response_core(Object(Automattic\WooCommerce\Admin\Overrides\Order), Object(WP_REST_Request))
#6 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php(541): WC_REST_Orders_Controller->prepare_object_for_response_core(Object(Automattic\WooCommerce\Admin\Overrides\Order), Object(WP_REST_Request))
#7 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php(143): WC_REST_Orders_V2_Controller->prepare_object_for_response(Object(Automattic\WooCommerce\Admin\Overrides\Order), Object(WP_REST_Request))
#8 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/rest-api/class-wp-rest-server.php(1292): WC_REST_CRUD_Controller->get_item(Object(WP_REST_Request))
#9 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/rest-api/class-wp-rest-server.php(1125): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wc/v3/orders/(...', Array, NULL)
#10 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/rest-api.php(576): WP_REST_Server->dispatch(Object(WP_REST_Request))
#11 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/src/Utilities/RestApiUtil.php(25): rest_do_request(Object(WP_REST_Request))
#12 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/class-wc-webhook.php(386): Automattic\WooCommerce\Utilities\RestApiUtil->get_endpoint_data('/wc/v3/orders/1...')
#13 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/class-wc-webhook.php(429): WC_Webhook->get_wp_api_payload('order', 164, 'updated')
#14 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/class-wc-webhook.php(326): WC_Webhook->build_payload(164)
#15 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/wc-webhook-functions.php(83): WC_Webhook->deliver(164)
#16 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/class-wp-hook.php(324): wc_deliver_webhook_async(1, 164)
#17 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#18 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#19 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/packages/action-scheduler/classes/actions/ActionScheduler_Action.php(86): do_action_ref_array('woocommerce_del...', Array)
#20 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php(102): ActionScheduler_Action->execute()
#21 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(188): ActionScheduler_Abstract_QueueRunner->process_action(2442, 'Async Request')
#22 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(158): ActionScheduler_QueueRunner->do_batch(25, 'Async Request')
#23 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/class-wp-hook.php(324): ActionScheduler_QueueRunner->run('Async Request')
#24 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#25 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#26 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php(48): do_action('action_schedule...', 'Async Request')
#27 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-content/plugins/woocommerce/includes/libraries/wp-async-request.php(147): ActionScheduler_AsyncRequest_QueueRunner->handle()
#28 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/class-wp-hook.php(324): WP_Async_Request->maybe_handle('')
#29 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#30 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#31 /Applications/MAMP/htdocs/woogenerator/sites/wp-5327027/wp-admin/admin-ajax.php(192): do_action('wp_ajax_as_asyn...')
#32 {main}
@kaushikasomaiya kaushikasomaiya added the type: bug The issue is a confirmed bug. label Jan 29, 2025
@kaushikasomaiya
Copy link
Author

I've reported it in core as well because it would happen in case a plugin declaring custom coupon type is deactivated woocommerce/woocommerce#54953

@FawadNL
Copy link

FawadNL commented Feb 26, 2025

Any updates on this?

@kaushikasomaiya
Copy link
Author

@mattallan Wondering if merchants facing this issue could consider disabling WP Cron and deploying a real cron so that is_admin is always false?

@FawadNL
Copy link

FawadNL commented Mar 1, 2025

We are using real cron and disabled WP cron but issue persists.

@kaushikasomaiya
Copy link
Author

@FawadNL Okay I feel like the async queue runner might be only running on Admin screen and is independent of the WP Cron. I suppose setting the action_scheduler_allow_async_request_runner filter to false should help as a workaround but will wait for our developers to confirm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants