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

Add notices for important api exceptions #1089

Open
wants to merge 8 commits into
base: update/actions-to-fail-with-exceptions
Choose a base branch
from

Conversation

message-dimke
Copy link
Contributor

@message-dimke message-dimke commented Nov 20, 2024

Changes proposed in this Pull Request:

Adding an action to hook into Pinterest API exceptions to control Admin Notices. Adding an account failure notice into WooCommerce admin area in case there is a problem with the account while registering the feed (the most common scenario at the moment).

The note is dismissable and will show itself only once per connect-disconnect cycle. The note is removed on the disconnect event.

Detailed test instructions:

  1. Download the extension and connect to your Pinterest account.
  2. Edit the code lines below by adding a filter to emulate the request failure

public static function create_feed( array $data, string $ad_account_id ): array {
return self::make_request(
"catalogs/feeds?ad_account_id={$ad_account_id}",
'POST',
$data
);
}

add exactly before the return statement:

add_filter(
	'pre_http_request',
	function ( $response, $parsed_args, $url ) use ( $ad_account_id ) {
		if ( "https://api.pinterest.com/v5/catalogs/feeds?ad_account_id={$ad_account_id}" === $url ) {
			return array(
				'headers'  => array(
					'content-type' => 'application/json',
				),
				'body'     => json_encode(
					array(
						'code'    => 2625,
						'message' => 'Sorry, you cannot perform this action as your account has been disapproved. Please see business hub for more details. https://www.pinterest.com/business/hub/',
					)
				),
				'response' => array(
					'code'    => 403,
					'message' => 'Forbidden',
				),
				'cookies'  => array(),
				'filename' => '',
			);
		}
	},
	10,
	3
);
  1. Go to WooCommerce - Status - Scheduler Actions - Pending
WooCommerce_status_‹_WordPress_Pinterest_—_WordPress
  1. Force run the pinterest-for-woocommerce-handle-feed-registration action.
  2. Go to WooCommerce - Status - Scheduler Actions - Failed
  3. Observe there is the failed action.
  4. Observe there is an admin error notice duplicating the error of the action.
WooCommerce_status_‹_WordPress_Pinterest_—_WordPress-4

Changelog entry

Add - Admin notice of a failed Pinterest account status.

@message-dimke message-dimke added the changelog: update Big changes to something that wasn't broken. label Nov 20, 2024
@message-dimke message-dimke self-assigned this Nov 20, 2024
@github-actions github-actions bot added changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement. labels Nov 20, 2024
…o account error.

- Hooking into admin exception admin notice and disconnect actions within feed generation action to show and hide account failure notices.
@message-dimke message-dimke requested a review from a team November 21, 2024 09:56
@message-dimke message-dimke marked this pull request as ready for review November 21, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. changelog: update Big changes to something that wasn't broken. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant