settings = $settings; $this->state = $state; $this->fields = $fields; $this->dcc_applies = $dcc_applies; $this->messages_apply = $messages_apply; } /** * Renders the multiselect field. * * @param string $field The current field HTML. * @param string $key The current key. * @param array $config The configuration array. * @param string $value The current value. * * @return string */ public function render_multiselect( $field, $key, $config, $value ): string { if ( 'ppcp-multiselect' !== $config['type'] ) { return $field; } $options = array(); foreach ( $config['options'] as $option_key => $option_value ) { $selected = ( in_array( $option_key, $value, true ) ) ? 'selected="selected"' : ''; $options[] = ''; } $html = sprintf( '', esc_attr( implode( ' ', $config['class'] ) ), esc_attr( $key ) . '[]', implode( '', $options ) ); return $html; } /** * Renders the password input field. * * @param string $field The current field HTML. * @param string $key The current key. * @param array $config The configuration array. * @param string $value The current value. * * @return string */ public function render_password( $field, $key, $config, $value ): string { if ( 'ppcp-password' !== $config['type'] ) { return $field; } $html = sprintf( '', esc_attr( implode( ' ', $config['class'] ) ), esc_attr( $key ), esc_attr( $value ) ); return $html; } /** * Renders the text input field. * * @param string $field The current field HTML. * @param string $key The current key. * @param array $config The configuration array. * @param string $value The current value. * * @return string */ public function render_text_input( $field, $key, $config, $value ): string { if ( 'ppcp-text-input' !== $config['type'] ) { return $field; } $html = sprintf( '', esc_attr( implode( ' ', $config['class'] ) ), esc_attr( $key ), esc_attr( $value ) ); return $html; } /** * Renders the heading field. * * @param string $field The current field HTML. * @param string $key The current key. * @param array $config The configuration array. * @param string $value The current value. * * @return string */ public function render_heading( $field, $key, $config, $value ): string { if ( 'ppcp-heading' !== $config['type'] ) { return $field; } $html = sprintf( '

%s

', esc_attr( implode( ' ', $config['class'] ) ), esc_html( $config['heading'] ) ); return $html; } /** * Renders the settings. */ public function render() { //phpcs:ignore WordPress.Security.NonceVerification.Recommended $is_dcc = isset( $_GET[ SectionsRenderer::KEY ] ) && CreditCardGateway::ID === sanitize_text_field( wp_unslash( $_GET[ SectionsRenderer::KEY ] ) ); $nonce = wp_create_nonce( SettingsListener::NONCE ); ?> fields as $field => $config ) : if ( ! in_array( $this->state->current_state(), $config['screens'], true ) ) { continue; } if ( $is_dcc && ! in_array( $config['gateway'], array( 'all', 'dcc' ), true ) ) { continue; } if ( ! $is_dcc && ! in_array( $config['gateway'], array( 'all', 'paypal' ), true ) ) { continue; } if ( in_array( 'dcc', $config['requirements'], true ) && ! $this->dcc_applies->for_country_currency() ) { continue; } if ( in_array( 'messages', $config['requirements'], true ) && ! $this->messages_apply->for_country() ) { continue; } $value = $this->settings->has( $field ) ? $this->settings->get( $field ) : null; $key = 'ppcp[' . $field . ']'; $id = 'ppcp-' . $field; $config['id'] = $id; $th_td = 'ppcp-heading' !== $config['type'] ? 'td' : 'th'; $colspan = 'ppcp-heading' !== $config['type'] ? 1 : 2; ?> < colspan=""> render_text( $config ) : woocommerce_form_field( $key, $config, $value ); ?> > dcc_applies->for_country_currency() ) { if ( State::STATE_ONBOARDED > $this->state->current_state() ) { $this->render_dcc_onboarding_info(); } if ( State::STATE_ONBOARDED === $this->state->current_state() ) { $this->render_3d_secure_info(); } } else { $this->render_dcc_does_not_apply_info(); } } } /** * Renders the ppcp-text field given a configuration. * * @param array $config The configuration array. */ private function render_text( array $config ) { echo wp_kses_post( $config['text'] ); if ( isset( $config['hidden'] ) ) { $value = $this->settings->has( $config['hidden'] ) ? (string) $this->settings->get( $config['hidden'] ) : ''; echo ' '; } } /** * Renders the 3d secure info text. */ private function render_3d_secure_info() { ?>

', '' ) ); ?>