Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders

Komoju::is_komoju_in_sandbox_mode │ private │ WC 1.0

Check if the KOMOJU payment gateway is in sandbox mode.

Method of the class: Komoju{}

No Hooks.

Returns

?bool. True if the payment gateway is in sandbox mode, false otherwise. Null if the environment could not be determined.

Usage

// private - for code of main (parent) class only
$result = $this->is_komoju_in_sandbox_mode( $payment_gateway ): ?bool;
$payment_gateway(WC_Payment_Gateway) (required)
The payment gateway object.

Komoju::is_komoju_in_sandbox_mode() code WC 11.1.2

private function is_komoju_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool {
	try {
		// Check for a saved key first. The extension's helper below reports a store with no
		// key at all as live, but we want that case to stay undetermined so the caller decides.
		$secret_key = $this->get_secret_key( $payment_gateway );
		if ( empty( $secret_key ) ) {
			return null;
		}

		// Prefer the extension's own helper so we keep tracking how KOMOJU determines its
		// environment, should that ever stop being a secret key check.
		if ( class_exists( 'WC_Gateway_Komoju' ) && is_callable( 'WC_Gateway_Komoju::komoju_is_test_mode' ) ) {
			return wc_string_to_bool( \WC_Gateway_Komoju::komoju_is_test_mode() );
		}

		// The helper only exists since extension version 3.2.9, so reproduce it for older
		// versions: KOMOJU has no dedicated test-mode setting and infers the environment from
		// whether the stored secret key has the `sk_test_` (vs. `sk_live_`) prefix.
		return str_starts_with( $secret_key, 'sk_test_' );
	} catch ( Throwable $e ) {
		// Do nothing but log so we can investigate.
		SafeGlobalFunctionProxy::wc_get_logger()->debug(
			'Failed to determine if gateway is in sandbox mode: ' . $e->getMessage(),
			array(
				'gateway'   => $payment_gateway->id,
				'source'    => 'settings-payments',
				'exception' => $e,
			)
		);
	}

	// Let the caller know that we couldn't determine the environment.
	return null;
}