From 530f34823d4d3961a5febf7f52d7d00c353fb259 Mon Sep 17 00:00:00 2001 From: David Remer Date: Fri, 14 Aug 2020 10:03:03 +0300 Subject: [PATCH 1/6] rearrange settings, add layout and size to button layout --- .../ppcp-button/src/Assets/SmartButton.php | 5 +- modules.local/ppcp-wc-gateway/services.php | 212 +++++++++++------- 2 files changed, 134 insertions(+), 83 deletions(-) diff --git a/modules.local/ppcp-button/src/Assets/SmartButton.php b/modules.local/ppcp-button/src/Assets/SmartButton.php index 42fa094db..845296766 100644 --- a/modules.local/ppcp-button/src/Assets/SmartButton.php +++ b/modules.local/ppcp-button/src/Assets/SmartButton.php @@ -330,7 +330,10 @@ class SmartButton implements SmartButtonInterface 'cancel_wrapper' => '#ppcp-cancel', 'url' => $this->url(), 'style' => [ - 'layout' => 'vertical', + 'layout' => ($this->settings->has('button_layout')) ? + $this->settings->get('button_layout') : 'vertical', + 'size' => ($this->settings->has('button_size')) ? + $this->settings->get('button_size') : 'responsive', 'color' => ($this->settings->has('button_color')) ? $this->settings->get('button_color') : null, 'shape' => ($this->settings->has('button_shape')) ? diff --git a/modules.local/ppcp-wc-gateway/services.php b/modules.local/ppcp-wc-gateway/services.php index fbaa78f3a..a506b4e2d 100644 --- a/modules.local/ppcp-wc-gateway/services.php +++ b/modules.local/ppcp-wc-gateway/services.php @@ -269,61 +269,6 @@ return [ ], 'requirements' => [], ], - 'button_single_product_enabled' => [ - 'title' => __('Buttons on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Single Product', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - ], - 'button_mini_cart_enabled' => [ - 'title' => __('Buttons on Mini Cart', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Mini Cart', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - ], - 'button_cart_enabled' => [ - 'title' => __('Buttons on Cart', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'checkbox', - 'label' => __('Enable on Cart', 'woocommerce-paypal-commerce-gateway'), - 'default' => true, - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - ], - 'button_label' => [ - 'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'select', - 'class' => ['wc-enhanced-select'], - 'default' => 'paypal', - 'desc_tip' => true, - 'description' => __( - 'This controls the label on the primary button.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'paypal' => __('PayPal', 'woocommerce-paypal-commerce-gateway'), - 'checkout' => __('PayPal Checkout', 'woocommerce-paypal-commerce-gateway'), - 'buynow' => __('PayPal Buy Now', 'woocommerce-paypal-commerce-gateway'), - 'pay' => __('Pay with PayPal', 'woocommerce-paypal-commerce-gateway'), - ], - 'screens' => [ - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ], - 'requirements' => [], - ], 'brand_name' => [ 'title' => __('Brand Name', 'woocommerce-paypal-commerce-gateway'), 'type' => 'text', @@ -359,6 +304,114 @@ return [ ], 'requirements' => [], ], + 'disable_funding' => [ + 'title' => __('Disable funding sources', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'ppcp-multiselect', + 'class' => ['wc-enhanced-select'], + 'default' => [], + 'desc_tip' => true, + 'description' => __( + 'By default all possible funding sources will be shown. You can disable some sources, if you wish.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => [ + 'card' => _x('Credit or debit cards', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'credit' => _x('PayPal Credit', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'sepa' => _x('SEPA-Lastschrift', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'bancontact' => _x('Bancontact', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'eps' => _x('eps', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'giropay' => _x('giropay', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'ideal' => _x('iDEAL', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'mybank' => _x('MyBank', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'p24' => _x('Przelewy24', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + 'sofort' => _x('Sofort', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), + ], + 'screens' => [ + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ], + 'requirements' => [], + ], + 'vault_enabled' => [ + 'title' => __('Vaulting', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'checkbox', + 'desc_tip' => true, + 'label' => __('Enable vaulting', 'woocommerce-paypal-commerce-gateway'), + 'description' => __('Enables you to store payment tokens for subscriptions.', 'woocommerce-paypal-commerce-gateway'), + 'default' => true, + 'screens' => [ + State::STATE_ONBOARDED, + ], + 'requirements' => [], + ], + + //General button styles + + // General button styles + 'button_layout' => [ + 'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'select', + 'class' => ['wc-enhanced-select'], + 'default' => 'vertical', + 'desc_tip' => true, + 'description' => __( + 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => [ + 'vertical' => __('Vertical', 'woocommerce-paypal-commerce-gateway'), + 'horizontal' => __('Horizontal', 'woocommerce-paypal-commerce-gateway'), + ], + 'screens' => [ + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ], + 'requirements' => [], + ], + 'button_size' => [ + 'title' => __('Button Size', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'select', + 'class' => ['wc-enhanced-select'], + 'default' => 'responsive', + 'desc_tip' => true, + 'description' => __( + 'PayPal offers different sizes of the "PayPal Checkout" buttons, allowing you to select a size that best fits your site\'s theme. This setting will allow you to choose which size button(s) appear on your page. (The "Responsive" option adjusts to container size, and is available and recommended for Smart Payment Buttons.)', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => [ + 'small' => __('Small', 'woocommerce-paypal-commerce-gateway'), + 'medium' => __('Medium', 'woocommerce-paypal-commerce-gateway'), + 'large' => __('Large', 'woocommerce-paypal-commerce-gateway'), + 'responsive' => __('Responsive', 'woocommerce-paypal-commerce-gateway'), + ], + 'screens' => [ + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ], + 'requirements' => [], + ], + 'button_label' => [ + 'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'select', + 'class' => ['wc-enhanced-select'], + 'default' => 'paypal', + 'desc_tip' => true, + 'description' => __( + 'This controls the label on the primary button.', + 'woocommerce-paypal-commerce-gateway' + ), + 'options' => [ + 'paypal' => __('PayPal', 'woocommerce-paypal-commerce-gateway'), + 'checkout' => __('PayPal Checkout', 'woocommerce-paypal-commerce-gateway'), + 'buynow' => __('PayPal Buy Now', 'woocommerce-paypal-commerce-gateway'), + 'pay' => __('Pay with PayPal', 'woocommerce-paypal-commerce-gateway'), + ], + 'screens' => [ + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ], + 'requirements' => [], + ], 'button_color' => [ 'title' => __('Color', 'woocommerce-paypal-commerce-gateway'), 'type' => 'select', @@ -401,46 +454,41 @@ return [ ], 'requirements' => [], ], - 'disable_funding' => [ - 'title' => __('Disable funding sources', 'woocommerce-paypal-commerce-gateway'), - 'type' => 'ppcp-multiselect', - 'class' => ['wc-enhanced-select'], - 'default' => [], - 'desc_tip' => true, - 'description' => __( - 'By default all possible funding sources will be shown. You can disable some sources, if you wish.', - 'woocommerce-paypal-commerce-gateway' - ), - 'options' => [ - 'card' => _x('Credit or debit cards', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'credit' => _x('PayPal Credit', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'sepa' => _x('SEPA-Lastschrift', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'bancontact' => _x('Bancontact', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'eps' => _x('eps', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'giropay' => _x('giropay', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'ideal' => _x('iDEAL', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'mybank' => _x('MyBank', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'p24' => _x('Przelewy24', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - 'sofort' => _x('Sofort', 'Name of payment method', 'woocommerce-paypal-commerce-gateway'), - ], + + 'button_single_product_enabled' => [ + 'title' => __('Enable buttons on Single Product', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'checkbox', + 'label' => __('enable on Single Product', 'woocommerce-paypal-commerce-gateway'), + 'default' => true, 'screens' => [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], 'requirements' => [], ], - 'vault_enabled' => [ - 'title' => __('Vaulting', 'woocommerce-paypal-commerce-gateway'), + 'button_mini_cart_enabled' => [ + 'title' => __('Buttons on Mini Cart', 'woocommerce-paypal-commerce-gateway'), 'type' => 'checkbox', - 'desc_tip' => true, - 'label' => __('Enable vaulting', 'woocommerce-paypal-commerce-gateway'), - 'description' => __('Enables you to store payment tokens for subscriptions.', 'woocommerce-paypal-commerce-gateway'), + 'label' => __('Enable on Mini Cart', 'woocommerce-paypal-commerce-gateway'), 'default' => true, 'screens' => [ + State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], 'requirements' => [], ], + 'button_cart_enabled' => [ + 'title' => __('Buttons on Cart', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'checkbox', + 'label' => __('Enable on Cart', 'woocommerce-paypal-commerce-gateway'), + 'default' => true, + 'screens' => [ + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ], + 'requirements' => [], + ], + 'dcc_cart_enabled' => [ 'title' => __('Enable credit card on cart', 'woocommerce-paypal-commerce-gateway'), 'type' => 'checkbox', From 13d8c61b2a87d1eb27b2964923c4205d53095b30 Mon Sep 17 00:00:00 2001 From: David Remer Date: Fri, 14 Aug 2020 10:06:05 +0300 Subject: [PATCH 2/6] rearrange render methods for fields --- .../ppcp-wc-gateway/src/WcGatewayModule.php | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php b/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php index 2a93f195b..5d60689a4 100644 --- a/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php +++ b/modules.local/ppcp-wc-gateway/src/WcGatewayModule.php @@ -117,22 +117,10 @@ class WcGatewayModule implements ModuleInterface /** * @var SettingsRenderer $renderer */ - return $renderer->renderPassword( - $renderer->renderTextInput( - $renderer->renderMultiSelect( - $field, - $key, - $args, - $value - ), - $key, - $args, - $value - ), - $key, - $args, - $value - ); + $field = $renderer->renderMultiSelect($field, $key, $args, $value); + $field = $renderer->renderPassword($field, $key, $args, $value); + $field = $renderer->rendrenderTextInputerMultiSelect($field, $key, $args, $value); + return $field; }, 10, 4 From e24fc0d7abfec33c86755ea0b8899e44160a088d Mon Sep 17 00:00:00 2001 From: David Remer Date: Fri, 14 Aug 2020 10:09:11 +0300 Subject: [PATCH 3/6] add heading field --- modules.local/ppcp-wc-gateway/services.php | 11 ++++++++-- .../src/Settings/SettingsRenderer.php | 21 ++++++++++++++++++- .../ppcp-wc-gateway/src/WcGatewayModule.php | 3 ++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/modules.local/ppcp-wc-gateway/services.php b/modules.local/ppcp-wc-gateway/services.php index a506b4e2d..f6562353a 100644 --- a/modules.local/ppcp-wc-gateway/services.php +++ b/modules.local/ppcp-wc-gateway/services.php @@ -346,8 +346,15 @@ return [ ], //General button styles - - // General button styles + 'button_style_heading' => [ + 'heading' => __('General styles', 'woocommerce-paypal-commerce-gateway'), + 'type' => 'ppcp-heading', + 'screens' => [ + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ], + 'requirements' => [], + ], 'button_layout' => [ 'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'), 'type' => 'select', diff --git a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php index 411b59d75..d8d609cef 100644 --- a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php +++ b/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php @@ -104,6 +104,22 @@ class SettingsRenderer return $html; } + + public function renderHeading($field, $key, $config, $value): string + { + + if ($config['type'] !== 'ppcp-heading') { + return $field; + } + + $html = sprintf( + '

%s

', + esc_attr(implode(' ', $config['class'])), + esc_html($config['heading']) + ); + + return $html; + } //phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType public function render() @@ -122,9 +138,11 @@ class SettingsRenderer } $value = $this->settings->has($field) ? $this->settings->get($field) : null; $id = 'ppcp[' . $field . ']'; + $colspan = $config['type'] !== 'ppcp-heading' ? 1 : 2; ?> +