get_merchant_id() ) && ! empty( $payment_gateway->get_secret_key() ); } } catch ( Throwable $e ) { // Do nothing but log so we can investigate. SafeGlobalFunctionProxy::wc_get_logger()->debug( 'Failed to determine if gateway has an account connected: ' . $e->getMessage(), array( 'gateway' => $payment_gateway->id, 'source' => 'settings-payments', 'exception' => $e, ) ); } return parent::is_account_connected( $payment_gateway ); } /** * Try to determine if the payment gateway is in test mode. * * This is a best-effort attempt, as there is no standard way to determine this. * Trust the true value, but don't consider a false value as definitive. * * @param WC_Payment_Gateway $payment_gateway The payment gateway object. * * @return bool True if the payment gateway is in test mode, false otherwise. */ public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool { return $this->is_afterpay_clearpay_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode( $payment_gateway ); } /** * Try to determine if the payment gateway is in dev mode. * * This is a best-effort attempt, as there is no standard way to determine this. * Trust the true value, but don't consider a false value as definitive. * * @param WC_Payment_Gateway $payment_gateway The payment gateway object. * * @return bool True if the payment gateway is in dev mode, false otherwise. */ public function is_in_dev_mode( WC_Payment_Gateway $payment_gateway ): bool { return $this->is_afterpay_clearpay_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_dev_mode( $payment_gateway ); } /** * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive). * * This is a best-effort attempt, as there is no standard way to determine this. * Trust the true value, but don't consider a false value as definitive. * * @param WC_Payment_Gateway $payment_gateway The payment gateway object. * * @return bool True if the payment gateway is in test mode onboarding, false otherwise. */ public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool { return $this->is_afterpay_clearpay_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode_onboarding( $payment_gateway ); } /** * Check if the Afterpay/Clearpay payment gateway is in sandbox mode. * * There are two different environments: sandbox and production. * * @param WC_Payment_Gateway $payment_gateway The payment gateway object. * * @return ?bool True if the payment gateway is in sandbox mode, false otherwise. * Null if the environment could not be determined. */ private function is_afterpay_clearpay_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool { try { if ( is_callable( array( $payment_gateway, 'get_api_env' ) ) ) { return 'production' !== $payment_gateway->get_api_env(); } } 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; } }