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

Synchronising Commerce Integration partner_metadata weekly. #1079

Conversation

message-dimke
Copy link
Contributor

@message-dimke message-dimke commented Oct 22, 2024

Changes proposed in this Pull Request:

The PR adds a weekly commerce integration partner_metadata sync action. The action will attempt to create the integration if the one is still missing. The integration will also run through a set of retries if the API is not responding successfully, delaying the synchronization until the integration is finally created.

Detailed test instructions:

Commerce Integration Sync tries to create the integration if the one does not exist.

  1. Add a filter to make the APIV5::create_commerce_integration call fail.
add_filter(
	'pre_http_request',
	function ( $response, $parsed_args, $url ) {
		if (
			'https://api.pinterest.com/v5/integrations/commerce' === $url &&
			'POST' === $parsed_args['method']
		) {
			return array(
				'headers' => array(
					'content-type' => 'application/json',
				),
				'body' => json_encode(
					array(
						'code'    => 911,
						'message' => 'Oops! Something went wrong!',
					)
				),
				'response' => array(
					'code'    => 500,
					'message' => 'Unexpected error',
				),
				'cookies'  => array(),
				'filename' => '',
			);
		}

		return $response;
	},
	10,
	3
);

public static function create_commerce_integration( array $integration_data ): array {
return self::make_request(
'integrations/commerce',
'POST',
$integration_data
);
}

  1. If you are connected to Pinterest - disconnect. Otherwise, connect to your Pinterest account using the extension.
  2. Manually trigger the Commerce Integration retry pinterest-for-woocommerce-create-commerce-integration-retry actions so they will all run (fail to create the integration).
  3. Manually trigger the pinterest_for_woocommerce_weekly_heartbeat action.

Since integration was not created previously, the sync action will attempt to create it. Fail and start the same commerce integration retry cycle (three attempts).

Commerce Integration Sync updates the parent_metadata if it has changed.

  1. Clean up the codebase so there is no more commerce integration endpoint failure.
  2. Either manually run the pinterest_for_woocommerce_weekly_heartbeat action to create commerce integration or reconnect to your Pinterest account.
  3. Update the code that collects the current platform data, such as the extension, WP, and WC versions used by the installation.

Replace any partner_metadata array value with something to your taste

array(
'plugin_version' => PINTEREST_FOR_WOOCOMMERCE_VERSION,
'wc_version' => defined( 'WC_VERSION' ) ? WC_VERSION : 'unknown',
'wp_version' => $wp_version,
'locale' => get_locale(),
'currency' => get_woocommerce_currency(),
)

  1. Manually trigger the pinterest_for_woocommerce_weekly_heartbeat action from the Pending section of the ScheduledActions tab.
  2. Observe the database wp_options key with pinterest_for_woocommerce_data name updated.

NOTE: It is not possible to watch how the data goes to Pinterest API and gets saved there (under returning me the response with the updated data, I am assuming that Pinterest is saving it) without using a debugger and settings breakpoints.

Screenshots

WooCommerce_status_‹_WordPress_Pinterest_—_WordPress-8

Changelog entry

Add - Commerce Integration partner_metadata weekly sync.

… create the integration if the one is missing.
@message-dimke message-dimke added the changelog: add A new feature, function, or functionality was added. label Oct 22, 2024
@message-dimke message-dimke self-assigned this Oct 22, 2024
@github-actions github-actions bot added the type: enhancement The issue is a request for an enhancement. label Oct 22, 2024
@message-dimke message-dimke marked this pull request as ready for review October 22, 2024 19:47
Copy link
Collaborator

@budzanowski budzanowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one small nitpick, looks great, I think that we can try it.

…be changed in the future without paying attention to set a proper time frame for it.
@message-dimke message-dimke merged commit 3abdbbe into add/create-commerce-integration-retry Oct 23, 2024
4 checks passed
@message-dimke message-dimke deleted the add/a-weekly-commerce-integration-sync branch October 23, 2024 06:11
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. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants