publishableKey() && '' !== $this->secretKey(); } public function renderPage(): void { if ( ! current_user_can( RoleManager::CAP_MANAGE_BILLING ) ) { wp_die( esc_html__( 'You do not have permission to manage billing settings.', 'unsupervised-schedular' ) ); } if ( isset( $_POST['usc_action'] ) && check_admin_referer( 'usc_settings_action' ) ) { $this->save(); } $publishableKey = $this->publishableKey(); // Secrets are write-only in the UI: never echo a stored secret back into the // page. We only surface whether one is set so the field can be left blank to // keep the existing value. $secretKeySet = '' !== $this->secretKey(); $webhookSecretSet = '' !== $this->webhookSecret(); $webhookUrl = rest_url( 'us-scheduler/v1/payments/webhook' ); $mode = $this->mode(); $currency = $this->currency(); $etransferEmail = $this->etransferEmail(); $hstRate = $this->hstRate(); $stripeConfigured = $this->isStripeConfigured(); include USC_PLUGIN_DIR . 'templates/admin/settings.php'; } private function save(): void { // Nonce is verified by the caller (renderPage) before this method runs. // phpcs:disable WordPress.Security.NonceVerification.Missing $mode = sanitize_key( Val::string( wp_unslash( $_POST['mode'] ?? 'test' ) ) ); update_option( self::OPT_PUBLISHABLE, sanitize_text_field( Val::string( wp_unslash( $_POST['publishable_key'] ?? '' ) ) ) ); // Secret fields are write-only: a blank submission keeps the stored secret, // so an admin saving other settings never wipes the keys. $secretKey = sanitize_text_field( Val::string( wp_unslash( $_POST['secret_key'] ?? '' ) ) ); if ( '' !== $secretKey ) { update_option( self::OPT_SECRET, $secretKey ); } $webhookSecret = sanitize_text_field( Val::string( wp_unslash( $_POST['webhook_secret'] ?? '' ) ) ); if ( '' !== $webhookSecret ) { update_option( self::OPT_WEBHOOK_SECRET, $webhookSecret ); } update_option( self::OPT_MODE, 'live' === $mode ? 'live' : 'test' ); update_option( self::OPT_CURRENCY, strtoupper( sanitize_text_field( Val::string( wp_unslash( $_POST['currency'] ?? 'CAD' ) ) ) ) ); update_option( self::OPT_ETRANSFER_EMAIL, sanitize_email( Val::string( wp_unslash( $_POST['etransfer_email'] ?? '' ) ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Val::float() coerces to float; slashes cannot survive numeric coercion. $hstRate = isset( $_POST['hst_rate'] ) ? Val::float( $_POST['hst_rate'] ) : 0.0; update_option( self::OPT_HST_RATE, max( 0.0, $hstRate ) ); // phpcs:enable WordPress.Security.NonceVerification.Missing } }