Automattic\WooCommerce\Internal\Admin\Settings

Payments::maybe_track_provider_state_changeprivateWC 1.0

Track the payment provider state change.

Метод класса: Payments{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->maybe_track_provider_state_change( $provider, $old_snapshot, $new_snapshot ): void;
$provider(массив) (обязательный)
The payment provider details.
$old_snapshot(массив) (обязательный)
The old snapshot of the provider's state.
$new_snapshot(массив) (обязательный)
The new snapshot of the provider's state.

Код Payments::maybe_track_provider_state_change() WC 10.8.1

private function maybe_track_provider_state_change( array $provider, array $old_snapshot, array $new_snapshot ): void {
	// Note: Keep the order of the events in a way that makes sense for the onboarding flow.

	// Track extension_active change.
	if ( $old_snapshot['extension_active'] && ! $new_snapshot['extension_active'] ) {
		$this->record_event(
			'provider_extension_deactivated',
			array(
				'provider_id'             => $provider['id'],
				'suggestion_id'           => $provider['_suggestion_id'],
				'provider_extension_slug' => $provider['plugin']['slug'],
			)
		);

		// If the extension was also uninstalled, we can track that as well.
		if ( ! empty( $provider['plugin']['status'] ) && PaymentsProviders::EXTENSION_NOT_INSTALLED === $provider['plugin']['status'] ) {
			$this->record_event(
				'provider_extension_uninstalled',
				array(
					'provider_id'             => $provider['id'],
					'suggestion_id'           => $provider['_suggestion_id'],
					'provider_extension_slug' => $provider['plugin']['slug'],
				)
			);
		}
	} elseif ( ! $old_snapshot['extension_active'] && $new_snapshot['extension_active'] ) {
		$this->record_event(
			'provider_extension_activated',
			array(
				'provider_id'             => $provider['id'],
				'suggestion_id'           => $provider['_suggestion_id'],
				'provider_extension_slug' => $provider['plugin']['slug'],
			)
		);
	}

	// Track account_connected change.
	if ( $old_snapshot['account_connected'] && ! $new_snapshot['account_connected'] ) {
		$this->record_event(
			'provider_account_disconnected',
			array(
				'provider_id'                => $provider['id'],
				'suggestion_id'              => $provider['_suggestion_id'],
				'provider_extension_slug'    => $provider['plugin']['slug'],
				'provider_account_test_mode' => $old_snapshot['account_test_mode'] ? 'yes' : 'no',
			)
		);
	} elseif ( ! $old_snapshot['account_connected'] && $new_snapshot['account_connected'] ) {
		$this->record_event(
			'provider_account_connected',
			array(
				'provider_id'                => $provider['id'],
				'suggestion_id'              => $provider['_suggestion_id'],
				'provider_extension_slug'    => $provider['plugin']['slug'],
				'provider_account_test_mode' => $new_snapshot['account_test_mode'] ? 'yes' : 'no',
			)
		);
	}

	// Track needs_setup change.
	if ( $old_snapshot['needs_setup'] && ! $new_snapshot['needs_setup'] ) {
		$this->record_event(
			'provider_setup_completed',
			array(
				'provider_id'             => $provider['id'],
				'suggestion_id'           => $provider['_suggestion_id'],
				'provider_extension_slug' => $provider['plugin']['slug'],
			)
		);
	} elseif ( ! $old_snapshot['needs_setup'] && $new_snapshot['needs_setup'] ) {
		$this->record_event(
			'provider_setup_required',
			array(
				'provider_id'             => $provider['id'],
				'suggestion_id'           => $provider['_suggestion_id'],
				'provider_extension_slug' => $provider['plugin']['slug'],
			)
		);
	}

	// Track payments test_mode change, but only if an account is connected.
	if ( $new_snapshot['account_connected'] ) {
		if ( $old_snapshot['test_mode'] && ! $new_snapshot['test_mode'] ) {
			$this->record_event(
				'provider_live_payments_enabled',
				array(
					'provider_id'             => $provider['id'],
					'suggestion_id'           => $provider['_suggestion_id'],
					'provider_extension_slug' => $provider['plugin']['slug'],
				)
			);
		} elseif ( ! $old_snapshot['test_mode'] && $new_snapshot['test_mode'] ) {
			$this->record_event(
				'provider_test_payments_enabled',
				array(
					'provider_id'             => $provider['id'],
					'suggestion_id'           => $provider['_suggestion_id'],
					'provider_extension_slug' => $provider['plugin']['slug'],
				)
			);
		}
	}

	// Track account_test_mode change, but only if the account is connected.
	if ( $new_snapshot['account_connected'] ) {
		if ( $old_snapshot['account_test_mode'] && ! $new_snapshot['account_test_mode'] ) {
			$this->record_event(
				'provider_account_live_mode_enabled',
				array(
					'provider_id'             => $provider['id'],
					'suggestion_id'           => $provider['_suggestion_id'],
					'provider_extension_slug' => $provider['plugin']['slug'],
				)
			);
		} elseif ( ! $old_snapshot['account_test_mode'] && $new_snapshot['account_test_mode'] ) {
			$this->record_event(
				'provider_account_test_mode_enabled',
				array(
					'provider_id'             => $provider['id'],
					'suggestion_id'           => $provider['_suggestion_id'],
					'provider_extension_slug' => $provider['plugin']['slug'],
				)
			);
		}
	}
}