settings = $settings; $this->state = $state; $this->fields = $fields; $this->dcc_applies = $dcc_applies; $this->messages_apply = $messages_apply; $this->dcc_product_status = $dcc_product_status; $this->settings_status = $settings_status; $this->page_id = $page_id; } /** * Returns notices list. * * @return array */ public function messages() : array { $messages = array(); if ( $this->can_display_vaulting_admin_message() ) { $vaulting_title = __( 'PayPal vaulting', 'woocommerce-paypal-payments' ); $pay_later_messages_title = __( 'Pay Later Messaging', 'woocommerce-paypal-payments' ); $enabled = $this->paypal_vaulting_is_enabled() ? $vaulting_title : $pay_later_messages_title; $disabled = $this->settings_status->pay_later_messaging_is_enabled() ? $vaulting_title : $pay_later_messages_title; $pay_later_messages_or_vaulting_text = sprintf( // translators: %1$s and %2$s is translated PayPal vaulting and Pay Later Messaging strings. __( 'You have %1$s enabled, that\'s why %2$s options are unavailable now. You cannot use both features at the same time.', 'woocommerce-paypal-payments' ), $enabled, $disabled ); $messages[] = new Message( $pay_later_messages_or_vaulting_text, 'warning' ); } //phpcs:disable WordPress.Security.NonceVerification.Recommended //phpcs:disable WordPress.Security.NonceVerification.Missing if ( ! isset( $_GET['ppcp-onboarding-error'] ) || ! empty( $_POST ) ) { return $messages; } //phpcs:enable WordPress.Security.NonceVerification.Recommended //phpcs:enable WordPress.Security.NonceVerification.Missing $messages[] = new Message( __( 'We could not complete the onboarding process. Some features, such as card processing, will not be available. To fix this, please try again.', 'woocommerce-paypal-payments' ), 'error', false ); return $messages; } /** * Check whether vaulting is enabled. * * @return bool */ private function paypal_vaulting_is_enabled(): bool { return $this->settings->has( 'vault_enabled' ) && (bool) $this->settings->get( 'vault_enabled' ); } /** * Check if current screen is PayPal checkout settings screen. * * @return bool Whether is PayPal checkout screen or not. */ private function is_paypal_checkout_screen(): bool { return PayPalGateway::ID === $this->page_id; } /** * 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( ' ', isset( $config['input_class'] ) ? $config['input_class'] : array() ) ), 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 table row. * * @param array $data Values of the row cells. * @param string $tag HTML tag ('td', 'th'). * @return string */ public function render_table_row( array $data, string $tag = 'td' ): string { $cells = array_map( function ( $value ) use ( $tag ): string { return "<$tag>" . (string) $value . ""; }, $data ); return '' . implode( $cells ) . ''; } /** * Renders the table field. * * @param string $field The current field HTML. * @param string $key The key. * @param array $config The configuration of the field. * @param array $value The current value. * * @return string HTML. */ public function render_table( $field, $key, $config, $value ): string { if ( 'ppcp-table' !== $config['type'] ) { return $field; } $data = $value['data']; if ( empty( $data ) ) { $empty_placeholder = $value['empty_placeholder'] ?? ( $config['empty_placeholder'] ?? null ); if ( $empty_placeholder ) { return $empty_placeholder; } } $header_row_html = $this->render_table_row( $value['headers'], 'th' ); $data_rows_html = implode( array_map( array( $this, 'render_table_row' ), $data ) ); return " $header_row_html $data_rows_html
"; } /** * Renders the settings. */ public function render() { $is_dcc = CreditCardGateway::ID === $this->page_id; //phpcs:enable WordPress.Security.NonceVerification.Recommended //phpcs:enable WordPress.Security.NonceVerification.Missing $nonce = wp_create_nonce( SettingsListener::NONCE ); ?> fields as $field => $config ) : if ( ! in_array( $this->state->current_state(), $config['screens'], true ) ) { continue; } if ( ! $this->field_matches_page( $config, $this->page_id ) ) { continue; } if ( in_array( 'dcc', $config['requirements'], true ) && ! $this->dcc_applies->for_country_currency() ) { continue; } if ( in_array( 'dcc', $config['requirements'], true ) && ! $this->dcc_product_status->dcc_is_active() ) { 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; $colspan = 'ppcp-heading' !== $config['type'] ? 1 : 2; $classes = isset( $config['classes'] ) ? $config['classes'] : array(); $classes[] = sprintf( 'ppcp-settings-field-%s', str_replace( 'ppcp-', '', $config['type'] ) ); $description = isset( $config['description'] ) ? $config['description'] : ''; unset( $config['description'] ); ?> 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(); } elseif ( ! $this->dcc_product_status->dcc_is_active() ) { $this->render_dcc_not_active_yet(); } } 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 information that the PayPal account can not yet process DCC. */ private function render_dcc_not_active_yet() { ?>

state->current_state() ) { return false; } return $this->is_paypal_checkout_screen() && ( $this->paypal_vaulting_is_enabled() || $this->settings_status->pay_later_messaging_is_enabled() ); } }