WC_Payment_Gateways::record_gateway_eventprivateWC 1.0

Send a Tracks event.

By default, Woo adds url, blog_lang, blog_id, store_id, products_count, and wc_version properties to every event.

Method of the class: WC_Payment_Gateways{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->record_gateway_event( $name, $gateway );
$name(string) (required)
The event name. If it is not prefixed, it will be with the standard prefix.
$gateway(WC_Payment_Gateway) (required)
The payment gateway object.

WC_Payment_Gateways::record_gateway_event() code WC 10.5.0

private function record_gateway_event( string $name, $gateway ) {
	if ( ! function_exists( 'wc_admin_record_tracks_event' ) ) {
		return;
	}

	if ( ! is_a( $gateway, 'WC_Payment_Gateway' ) ) {
		// If the gateway is not a valid payment gateway, we don't record the event.
		return;
	}

	// If the event name is empty, we don't record it.
	if ( empty( $name ) ) {
		return;
	}

	// If the event name is not prefixed, we prefix it.
	$prefix = SettingsPaymentsService::EVENT_PREFIX . 'provider_';
	if ( ! str_starts_with( $name, $prefix ) ) {
		$name = $prefix . $name;
	}

	$properties = array(
		'provider_id'      => $gateway->id,
		'business_country' => WC()->countries->get_base_country(),
	);

	try {
		/**
		 * The Payments Settings [page] service.
		 *
		 * @var SettingsPaymentsService $settings_payments_service
		 */
		$settings_payments_service = wc_get_container()->get( SettingsPaymentsService::class );
		// Get the business country from the Payments Settings service.
		$properties['business_country'] = $settings_payments_service->get_country();

		/**
		 * The Payments Providers service.
		 *
		 * @var PaymentsProviders $payments_providers_service
		 */
		$payments_providers_service = wc_get_container()->get( PaymentsProviders::class );

		$gateway_details = $payments_providers_service->get_payment_gateway_details( $gateway, 0, $properties['business_country'] );
		// If the gateway details have a suggestion ID, we add it to the properties.
		if ( ! empty( $gateway_details['_suggestion_id'] ) ) {
			$properties['suggestion_id'] = $gateway_details['_suggestion_id'];
		}
		if ( ! empty( $gateway_details['plugin']['slug'] ) ) {
			$properties['provider_extension_slug'] = $gateway_details['plugin']['slug'];
		}
	} catch ( \Throwable $e ) {
		// Do nothing but log so we can investigate.
		SafeGlobalFunctionProxy::wc_get_logger()->debug(
			'Failed to gather provider-specific details for gateway: ' . $e->getMessage(),
			array(
				'gateway'   => $gateway->id,
				'source'    => 'settings-payments',
				'exception' => $e,
			)
		);
	}

	wc_admin_record_tracks_event( $name, $properties );
}