Automattic\WooCommerce\Internal\Admin\Settings

Payments::maybe_track_providers_state_changeprivateWC 1.0

Maybe track the payment providers state change.

This method will iterate through the new snapshots and compare them with the old ones. If there are any changes, it will track them.

Method of the class: Payments{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->maybe_track_providers_state_change( $providers, $old_snapshots, $new_snapshots ): void;
$providers(array) (required)
The list of payment provider details.
$old_snapshots(array) (required)
The old snapshots of the providers' states.
$new_snapshots(array) (required)
The new snapshots of the providers' states.

Payments::maybe_track_providers_state_change() code WC 10.9.4

private function maybe_track_providers_state_change( array $providers, array $old_snapshots, array $new_snapshots ): void {
	foreach ( $new_snapshots as $provider_extension_slug => $new_snapshot ) {
		if ( ! isset( $old_snapshots[ $provider_extension_slug ] ) ) {
			// If we don't have an old snapshot for this provider, we can't track the change.
			continue;
		}

		// If there are no changes, we don't need to track anything.
		if ( maybe_serialize( $old_snapshots[ $provider_extension_slug ] ) === maybe_serialize( $new_snapshot ) ) {
			continue;
		}

		// Search for the provider by its plugin slug.
		$provider = null;
		foreach ( $providers as $p ) {
			if ( isset( $p['plugin']['slug'] ) && $p['plugin']['slug'] === $provider_extension_slug ) {
				$provider = $p;
				break;
			}
		}
		if ( ! $provider ) {
			// If we couldn't find the provider in the list it means the extension was deactivated.
			// Get the matching suggestion by its slug.
			$provider = $this->providers->get_extension_suggestion_by_plugin_slug( $provider_extension_slug );
			if ( ! empty( $provider['id'] ) ) {
				// If we found the suggestion, we can use it as a replacement provider.
				// We need to set the `_suggestion_id` so we can handle the date more uniformly.
				$provider['_suggestion_id'] = $provider['id'];
			}
		}
		if ( ! $provider ) {
			continue;
		}

		$this->maybe_track_provider_state_change( $provider, $old_snapshots[ $provider_extension_slug ], $new_snapshot );
	}
}