From 16a48156a50e68c98e5676bbd8de417826aeee3d Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 16 Jul 2021 11:04:01 +0200 Subject: [PATCH 01/31] Bump 1.4.0 version --- changelog.txt | 16 ++++++++++++++++ package.json | 2 +- readme.txt | 18 +++++++++++++++++- woocommerce-paypal-payments.php | 4 ++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index 68e380959..cc915ab57 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,21 @@ *** Changelog *** += 1.4.0 - TBD = +* Add - Venmo update #169 +* Add - Pay Later Button –Global Expansion #182 +* Add - Add Canada to advanced credit and debit card #180 +* Add - Add button height setting for mini cart #181 +* Add - Add BN Code to Pay Later Messaging #183 +* Add - Add 30 seconds timeout by default to all API requests #184 +* Fix - ACDC checkout error: "Card Details not valid"; but payment completes #193 +* Fix - Incorrect API credentials cause fatal error #187 +* Fix - PayPal payment fails if a new user account is created during the checkout process #177 +* Fix - Disabled PayPal button appears when another button is loaded on the same page #192 +* Fix - [UNPROCESSABLE_ENTITY] error during checkout #172 +* Fix - Do not send customer email when order status is on hold #173 +* Fix - Remove merchant-id query parameter in JSSDK #179 +* Fix - Error on Plugin activation with Zettle POS Integration for WooCommerce #195 + = 1.3.2 - 2021-06-08 = * Fix - Improve Subscription plugin support. #161 * Fix - Disable vault setting if vaulting feature is not available. #150 diff --git a/package.json b/package.json index 4f6d099ba..e4380f8f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "woocommerce-paypal-payments", - "version": "1.3.2", + "version": "1.4.0", "description": "WooCommerce PayPal Payments", "repository": "https://github.com/woocommerce/woocommerce-paypal-payments", "license": "GPL-2.0", diff --git a/readme.txt b/readme.txt index 724a86a8e..d287575f7 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell, Requires at least: 5.3 Tested up to: 5.7 Requires PHP: 7.1 -Stable tag: 1.3.2 +Stable tag: 1.4.0 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -58,6 +58,22 @@ Follow the steps below to connect the plugin to your PayPal account: == Changelog == += 1.4.0 = +* Add - Venmo update #169 +* Add - Pay Later Button –Global Expansion #182 +* Add - Add Canada to advanced credit and debit card #180 +* Add - Add button height setting for mini cart #181 +* Add - Add BN Code to Pay Later Messaging #183 +* Add - Add 30 seconds timeout by default to all API requests #184 +* Fix - ACDC checkout error: "Card Details not valid"; but payment completes #193 +* Fix - Incorrect API credentials cause fatal error #187 +* Fix - PayPal payment fails if a new user account is created during the checkout process #177 +* Fix - Disabled PayPal button appears when another button is loaded on the same page #192 +* Fix - [UNPROCESSABLE_ENTITY] error during checkout #172 +* Fix - Do not send customer email when order status is on hold #173 +* Fix - Remove merchant-id query parameter in JSSDK #179 +* Fix - Error on Plugin activation with Zettle POS Integration for WooCommerce #195 + = 1.3.2 = * Fix - Improve Subscription plugin support. #161 * Fix - Disable vault setting if vaulting feature is not available. #150 diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 0ce0ab2e4..1f90977f0 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -3,13 +3,13 @@ * Plugin Name: WooCommerce PayPal Payments * Plugin URI: https://woocommerce.com/products/woocommerce-paypal-payments/ * Description: PayPal's latest complete payments processing solution. Accept PayPal, Pay Later, credit/debit cards, alternative digital wallets local payment types and bank accounts. Turn on only PayPal options or process a full suite of payment methods. Enable global transaction with extensive currency and country coverage. - * Version: 1.3.2 + * Version: 1.4.0 * Author: WooCommerce * Author URI: https://woocommerce.com/ * License: GPL-2.0 * Requires PHP: 7.1 * WC requires at least: 3.9 - * WC tested up to: 4.9 + * WC tested up to: 5.5 * Text Domain: woocommerce-paypal-payments * * @package WooCommerce\PayPalCommerce From c2a036c952568a447baeb1a442805f911e9fc7e9 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 21 Jul 2021 11:44:44 +0200 Subject: [PATCH 02/31] Check if array key exist before using it --- modules/ppcp-button/src/Endpoint/class-createorderendpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php b/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php index cadc0e0fd..0e90fc41c 100644 --- a/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php +++ b/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php @@ -174,7 +174,7 @@ class CreateOrderEndpoint implements EndpointInterface { $this->set_bn_code( $data ); if ( 'checkout' === $data['context'] ) { - if ( '1' === $data['createaccount'] ) { + if ( isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) { $this->process_checkout_form_when_creating_account( $data['form'], $wc_order ); } From f47d69a6b0c170af667cb0c42aabde06f339c9c4 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 23 Jul 2021 11:31:11 +0200 Subject: [PATCH 03/31] Do not render save credit card checkbox is user is not logged in --- modules/ppcp-button/src/Assets/class-smartbutton.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 4fb0eee10..81cf51161 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -202,7 +202,7 @@ class SmartButton implements SmartButtonInterface { add_filter( 'woocommerce_credit_card_form_fields', function ( $default_fields, $id ) { - if ( $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) && CreditCardGateway::ID === $id ) { + if ( is_user_logged_in() && $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) && CreditCardGateway::ID === $id ) { $default_fields['card-vault'] = sprintf( '

', esc_html__( 'Save your Credit Card', 'woocommerce-paypal-payments' ) From fb32cec67b33778a2414e60727bef482cac0795e Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 09:58:54 +0300 Subject: [PATCH 04/31] Allow button renderer hook to be filtered --- modules/ppcp-button/src/Assets/class-smartbutton.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 4fb0eee10..ca86ac294 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -360,7 +360,7 @@ class SmartButton implements SmartButtonInterface { ); } - add_action( 'woocommerce_review_order_after_payment', array( $this, 'button_renderer' ), 10 ); + add_action( $this->checkout_button_renderer_hook(), array( $this, 'button_renderer' ), 10 ); add_action( 'woocommerce_pay_order_after_submit', array( $this, 'button_renderer' ), 10 ); return true; @@ -963,4 +963,14 @@ class SmartButton implements SmartButtonInterface { return $height; } + + /** + * Return action name PayPal buttons will be rendered at. + * + * @return string Action name. + */ + private function checkout_button_renderer_hook(): string + { + return (string) apply_filters('woocommerce_paypal_payments_checkout_button_renderer_hook', 'woocommerce_review_order_after_payment'); + } } From 2391e7038e5a2d3a1fa0c900b599fc7b8098a8b4 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 10:18:43 +0300 Subject: [PATCH 05/31] Allow cart button renderer hook to be filtered --- .../src/Assets/class-smartbutton.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index ca86ac294..e465dec67 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -318,7 +318,7 @@ class SmartButton implements SmartButtonInterface { && ! $not_enabled_on_cart ) { add_action( - 'woocommerce_proceed_to_checkout', + $this->proceed_to_checkout_button_renderer_hook(), array( $this, 'button_renderer', @@ -965,7 +965,7 @@ class SmartButton implements SmartButtonInterface { } /** - * Return action name PayPal buttons will be rendered at. + * Return action name PayPal buttons will be rendered at on checkout page. * * @return string Action name. */ @@ -973,4 +973,17 @@ class SmartButton implements SmartButtonInterface { { return (string) apply_filters('woocommerce_paypal_payments_checkout_button_renderer_hook', 'woocommerce_review_order_after_payment'); } + + /** + * Return action name PayPal will be rendered next to Proceed to checkout button (normally displayed in cart). + * + * @return string + */ + private function proceed_to_checkout_button_renderer_hook(): string + { + return (string) apply_filters( + 'woocommerce_paypal_payments_to_checkout_button_renderer_hook', + 'woocommerce_proceed_to_checkout' + ); + } } From f81aa63f8b512303ef288d54b04e80042f053d62 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 10:27:34 +0300 Subject: [PATCH 06/31] Allow dcc checkout button renderer hook filter --- modules/ppcp-button/src/Assets/class-smartbutton.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index e465dec67..9c362bb6c 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -182,7 +182,7 @@ class SmartButton implements SmartButtonInterface { && ! $this->session_handler->order() ) { add_action( - 'woocommerce_review_order_after_submit', + $this->checkout_dcc_button_renderer_hook(), array( $this, 'dcc_renderer', @@ -974,6 +974,16 @@ class SmartButton implements SmartButtonInterface { return (string) apply_filters('woocommerce_paypal_payments_checkout_button_renderer_hook', 'woocommerce_review_order_after_payment'); } + /** + * Return action name PayPal DCC button will be rendered at on checkout page. + * + * @return string + */ + private function checkout_dcc_button_renderer_hook(): string + { + return (string) apply_filters('woocommerce_paypal_payments_checkout_dcc_renderer_hook', 'woocommerce_review_order_after_submit'); + } + /** * Return action name PayPal will be rendered next to Proceed to checkout button (normally displayed in cart). * From 03b76d91771c8051846deb75a019b037d5d26ce5 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 10:31:11 +0300 Subject: [PATCH 07/31] Allow dcc pay-order button renderer hook filter --- modules/ppcp-button/src/Assets/class-smartbutton.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 9c362bb6c..61a1e7678 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -191,7 +191,7 @@ class SmartButton implements SmartButtonInterface { ); add_action( - 'woocommerce_pay_order_after_submit', + $this->pay_order_dcc_button_renderer_hook(), array( $this, 'dcc_renderer', @@ -984,6 +984,16 @@ class SmartButton implements SmartButtonInterface { return (string) apply_filters('woocommerce_paypal_payments_checkout_dcc_renderer_hook', 'woocommerce_review_order_after_submit'); } + /** + * Return action name PayPal DCC button will be rendered at on pay-order page. + * + * @return string + */ + private function pay_order_dcc_button_renderer_hook(): string + { + return (string) apply_filters('woocommerce_paypal_payments-pay-order_dcc_renderer_hook', 'woocommerce_pay_order_after_submit'); + } + /** * Return action name PayPal will be rendered next to Proceed to checkout button (normally displayed in cart). * From 6ca363e379e9567caa725d1267b70f2f933a5fae Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 10:50:52 +0300 Subject: [PATCH 08/31] Allow button renderer hook filter on mini cart --- .../src/Assets/class-smartbutton.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 61a1e7678..f66f3164a 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -349,7 +349,7 @@ class SmartButton implements SmartButtonInterface { ! $not_enabled_on_minicart ) { add_action( - 'woocommerce_widget_shopping_cart_after_buttons', + $this->mini_cart_button_renderer_hook(), static function () { echo '

Date: Mon, 26 Jul 2021 18:23:25 +0300 Subject: [PATCH 09/31] show submit button, dcc and message on same hook --- modules/ppcp-button/src/Assets/class-smartbutton.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index f66f3164a..530d37306 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -255,7 +255,7 @@ class SmartButton implements SmartButtonInterface { && ! $not_enabled_on_cart ) { add_action( - 'woocommerce_proceed_to_checkout', + $this->proceed_to_checkout_button_renderer_hook(), array( $this, 'message_renderer', @@ -284,7 +284,7 @@ class SmartButton implements SmartButtonInterface { ! $this->settings->get( 'message_enabled' ); if ( ! $not_enabled_on_checkout ) { add_action( - 'woocommerce_review_order_after_submit', + $this->checkout_dcc_button_renderer_hook(), array( $this, 'message_renderer', @@ -292,7 +292,7 @@ class SmartButton implements SmartButtonInterface { 11 ); add_action( - 'woocommerce_pay_order_after_submit', + $this->pay_order_dcc_button_renderer_hook(), array( $this, 'message_renderer', @@ -361,7 +361,7 @@ class SmartButton implements SmartButtonInterface { } add_action( $this->checkout_button_renderer_hook(), array( $this, 'button_renderer' ), 10 ); - add_action( 'woocommerce_pay_order_after_submit', array( $this, 'button_renderer' ), 10 ); + add_action( $this->pay_order_dcc_button_renderer_hook(), array( $this, 'button_renderer' ), 10 ); return true; } From 91fff09133cbc2d490b7b09045b4a84a81b34fa0 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 18:32:16 +0300 Subject: [PATCH 10/31] rename method --- modules/ppcp-button/src/Assets/class-smartbutton.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 530d37306..a55837aa1 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -191,7 +191,7 @@ class SmartButton implements SmartButtonInterface { ); add_action( - $this->pay_order_dcc_button_renderer_hook(), + $this->pay_order_renderer_hook(), array( $this, 'dcc_renderer', @@ -292,7 +292,7 @@ class SmartButton implements SmartButtonInterface { 11 ); add_action( - $this->pay_order_dcc_button_renderer_hook(), + $this->pay_order_renderer_hook(), array( $this, 'message_renderer', @@ -361,7 +361,7 @@ class SmartButton implements SmartButtonInterface { } add_action( $this->checkout_button_renderer_hook(), array( $this, 'button_renderer' ), 10 ); - add_action( $this->pay_order_dcc_button_renderer_hook(), array( $this, 'button_renderer' ), 10 ); + add_action( $this->pay_order_renderer_hook(), array( $this, 'button_renderer' ), 10 ); return true; } @@ -985,11 +985,11 @@ class SmartButton implements SmartButtonInterface { } /** - * Return action name PayPal DCC button will be rendered at on pay-order page. + * Return action name PayPal button and Pay Later message will be rendered at on pay-order page. * * @return string */ - private function pay_order_dcc_button_renderer_hook(): string + private function pay_order_renderer_hook(): string { return (string) apply_filters('woocommerce_paypal_payments-pay-order_dcc_renderer_hook', 'woocommerce_pay_order_after_submit'); } From 1fbf5bae102e6d63cc2974bb777b5730a1a4b69c Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 18:36:29 +0300 Subject: [PATCH 11/31] add filter for the product page renderer hook --- .../ppcp-button/src/Assets/class-smartbutton.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index a55837aa1..24e921e8d 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -271,7 +271,7 @@ class SmartButton implements SmartButtonInterface { && ! $not_enabled_on_product_page ) { add_action( - 'woocommerce_single_product_summary', + $this->single_product_renderer_hook(), array( $this, 'message_renderer', @@ -334,7 +334,7 @@ class SmartButton implements SmartButtonInterface { && ! $not_enabled_on_product_page ) { add_action( - 'woocommerce_single_product_summary', + $this->single_product_renderer_hook(), array( $this, 'button_renderer', @@ -1019,4 +1019,14 @@ class SmartButton implements SmartButtonInterface { 'woocommerce_widget_shopping_cart_after_buttons' ); } + + /** + * Return action name PayPal button and Pay Later message will be rendered at on the single product page. + * + * @return string + */ + private function single_product_renderer_hook(): string + { + return (string) apply_filters('woocommerce_paypal_payments_single_product_renderer_hook', 'woocommerce_single_product_summary'); + } } From 4f8e917c3752ed36f303031c7fd55ab2c04df69d Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 19:02:52 +0300 Subject: [PATCH 12/31] fix filter name --- modules/ppcp-button/src/Assets/class-smartbutton.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 24e921e8d..3d1258d17 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -991,7 +991,7 @@ class SmartButton implements SmartButtonInterface { */ private function pay_order_renderer_hook(): string { - return (string) apply_filters('woocommerce_paypal_payments-pay-order_dcc_renderer_hook', 'woocommerce_pay_order_after_submit'); + return (string) apply_filters('woocommerce_paypal_payments_pay_order_dcc_renderer_hook', 'woocommerce_pay_order_after_submit'); } /** From defae9cca0b7248d864fd92ef2d715f4dc976978 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 19:06:23 +0300 Subject: [PATCH 13/31] fix filter name --- modules/ppcp-button/src/Assets/class-smartbutton.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 3d1258d17..260d03faf 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -1002,7 +1002,7 @@ class SmartButton implements SmartButtonInterface { private function proceed_to_checkout_button_renderer_hook(): string { return (string) apply_filters( - 'woocommerce_paypal_payments_to_checkout_button_renderer_hook', + 'woocommerce_paypal_payments_proceed_to_checkout_button_renderer_hook', 'woocommerce_proceed_to_checkout' ); } From 280fc86d5f0fe9480c2653ae3d2d593894533351 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 20:00:46 +0300 Subject: [PATCH 14/31] add filter for module files --- woocommerce-paypal-payments.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 0ce0ab2e4..42501c3c1 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -73,7 +73,11 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true ); static $initialized; if ( ! $initialized ) { $modules = array( new PluginModule() ); - foreach ( glob( plugin_dir_path( __FILE__ ) . 'modules/*/module.php' ) as $module_file ) { + $module_files = glob( plugin_dir_path( __FILE__ ) . 'modules/*/module.php' ); + + //Use this filter to add custom module or remove some of added ones. + $module_files = apply_filters('woocommerce_paypal_payments_module_files_list', $module_files); + foreach ( $module_files as $module_file ) { $modules[] = ( require $module_file )(); } $providers = array(); From 72e5a49175e2175bec0468d05bcdba502c4598d8 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 20:03:25 +0300 Subject: [PATCH 15/31] Revert "add filter for module files" This reverts commit 280fc86d5f0fe9480c2653ae3d2d593894533351. --- woocommerce-paypal-payments.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 42501c3c1..0ce0ab2e4 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -73,11 +73,7 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true ); static $initialized; if ( ! $initialized ) { $modules = array( new PluginModule() ); - $module_files = glob( plugin_dir_path( __FILE__ ) . 'modules/*/module.php' ); - - //Use this filter to add custom module or remove some of added ones. - $module_files = apply_filters('woocommerce_paypal_payments_module_files_list', $module_files); - foreach ( $module_files as $module_file ) { + foreach ( glob( plugin_dir_path( __FILE__ ) . 'modules/*/module.php' ) as $module_file ) { $modules[] = ( require $module_file )(); } $providers = array(); From 7d2468de0002c0119e697dbdf8d1f1a5c803a6f3 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 20:06:27 +0300 Subject: [PATCH 16/31] add modules filter --- woocommerce-paypal-payments.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 0ce0ab2e4..44874d781 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -77,6 +77,11 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true ); $modules[] = ( require $module_file )(); } $providers = array(); + + //Use this filter to add custom module or remove some of existing ones. + //Modules able to access container, add services and modify existing ones. + $modules = apply_filters('woocommerce_paypal_payments_modules', $modules); + foreach ( $modules as $module ) { /* @var $module ModuleInterface module */ $providers[] = $module->setup(); From 8a748b6e94021eb2d1685c60bd1db012fa9596ae Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Mon, 26 Jul 2021 20:13:05 +0300 Subject: [PATCH 17/31] auto fix phpcs errors --- .../src/Assets/class-smartbutton.php | 38 ++++++++----------- woocommerce-paypal-payments.php | 10 ++--- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 260d03faf..415cbceaf 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -963,70 +963,64 @@ class SmartButton implements SmartButtonInterface { return $height; } - + /** * Return action name PayPal buttons will be rendered at on checkout page. * * @return string Action name. */ - private function checkout_button_renderer_hook(): string - { - return (string) apply_filters('woocommerce_paypal_payments_checkout_button_renderer_hook', 'woocommerce_review_order_after_payment'); + private function checkout_button_renderer_hook(): string { + return (string) apply_filters( 'woocommerce_paypal_payments_checkout_button_renderer_hook', 'woocommerce_review_order_after_payment' ); } - + /** * Return action name PayPal DCC button will be rendered at on checkout page. * * @return string */ - private function checkout_dcc_button_renderer_hook(): string - { - return (string) apply_filters('woocommerce_paypal_payments_checkout_dcc_renderer_hook', 'woocommerce_review_order_after_submit'); + private function checkout_dcc_button_renderer_hook(): string { + return (string) apply_filters( 'woocommerce_paypal_payments_checkout_dcc_renderer_hook', 'woocommerce_review_order_after_submit' ); } - + /** * Return action name PayPal button and Pay Later message will be rendered at on pay-order page. * * @return string */ - private function pay_order_renderer_hook(): string - { - return (string) apply_filters('woocommerce_paypal_payments_pay_order_dcc_renderer_hook', 'woocommerce_pay_order_after_submit'); + private function pay_order_renderer_hook(): string { + return (string) apply_filters( 'woocommerce_paypal_payments_pay_order_dcc_renderer_hook', 'woocommerce_pay_order_after_submit' ); } - + /** * Return action name PayPal button will be rendered next to Proceed to checkout button (normally displayed in cart). * * @return string */ - private function proceed_to_checkout_button_renderer_hook(): string - { + private function proceed_to_checkout_button_renderer_hook(): string { return (string) apply_filters( 'woocommerce_paypal_payments_proceed_to_checkout_button_renderer_hook', 'woocommerce_proceed_to_checkout' ); } - + /** * Return action name PayPal button will be rendered in the WC mini cart. * * @return string */ - private function mini_cart_button_renderer_hook(): string - { + private function mini_cart_button_renderer_hook(): string { return (string) apply_filters( 'woocommerce_paypal_payments_mini_cart_button_renderer_hook', 'woocommerce_widget_shopping_cart_after_buttons' ); } - + /** * Return action name PayPal button and Pay Later message will be rendered at on the single product page. * * @return string */ - private function single_product_renderer_hook(): string - { - return (string) apply_filters('woocommerce_paypal_payments_single_product_renderer_hook', 'woocommerce_single_product_summary'); + private function single_product_renderer_hook(): string { + return (string) apply_filters( 'woocommerce_paypal_payments_single_product_renderer_hook', 'woocommerce_single_product_summary' ); } } diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 44874d781..953ee0c6f 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -77,11 +77,11 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true ); $modules[] = ( require $module_file )(); } $providers = array(); - - //Use this filter to add custom module or remove some of existing ones. - //Modules able to access container, add services and modify existing ones. - $modules = apply_filters('woocommerce_paypal_payments_modules', $modules); - + + // Use this filter to add custom module or remove some of existing ones. + // Modules able to access container, add services and modify existing ones. + $modules = apply_filters( 'woocommerce_paypal_payments_modules', $modules ); + foreach ( $modules as $module ) { /* @var $module ModuleInterface module */ $providers[] = $module->setup(); From dca37828c600199d12dca374ad9bec7e3846b228 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Tue, 27 Jul 2021 11:09:35 -0500 Subject: [PATCH 18/31] Update changelog date for release (1.4.0) --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index cc915ab57..a2ba808dd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,6 @@ *** Changelog *** -= 1.4.0 - TBD = += 1.4.0 - 2021-07-27 = * Add - Venmo update #169 * Add - Pay Later Button –Global Expansion #182 * Add - Add Canada to advanced credit and debit card #180 From b91ede355cfed90dc2bff2cce5fedf97689548c0 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Tue, 27 Jul 2021 19:20:51 +0300 Subject: [PATCH 19/31] store onboarded flag in the class properties --- .../src/Gateway/class-paypalgateway.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php index 667cd2766..aed294bb7 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php @@ -95,7 +95,14 @@ class PayPalGateway extends \WC_Payment_Gateway { * @var RefundProcessor */ private $refund_processor; - + + /** + * Whether the plugin is in onboarded state. + * + * @var bool + */ + private $onboarded; + /** * PayPalGateway constructor. * @@ -132,8 +139,9 @@ class PayPalGateway extends \WC_Payment_Gateway { $this->session_handler = $session_handler; $this->refund_processor = $refund_processor; $this->transaction_url_provider = $transaction_url_provider; + $this->onboarded = $state->current_state() === State::STATE_ONBOARDED; - if ( $state->current_state() === State::STATE_ONBOARDED ) { + if ( $this->onboarded ) { $this->supports = array( 'refunds' ); } if ( From 257842b7f7e5f585f044e31dc8230c43d5f1f42d Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Tue, 27 Jul 2021 19:53:54 +0300 Subject: [PATCH 20/31] don't redirect to gateway settings if onboarded --- modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php index aed294bb7..a18f36764 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php @@ -193,7 +193,7 @@ class PayPalGateway extends \WC_Payment_Gateway { */ public function needs_setup(): bool { - return true; + return ! $this->onboarded; } /** From 4bd4613255d64ac9b98f0d6a0b656eb7f337ebba Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Tue, 27 Jul 2021 19:56:59 +0300 Subject: [PATCH 21/31] auto fix phpcs errors --- modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php index a18f36764..0748445b9 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php @@ -95,14 +95,14 @@ class PayPalGateway extends \WC_Payment_Gateway { * @var RefundProcessor */ private $refund_processor; - + /** * Whether the plugin is in onboarded state. * * @var bool */ private $onboarded; - + /** * PayPalGateway constructor. * From 78fa4a5437356c3ceb92b6d9f2dbcefecb2a6e75 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Tue, 27 Jul 2021 15:23:57 -0500 Subject: [PATCH 22/31] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5f37f8f1c..794e0b310 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ branches: only: - master - trunk + - compat/ppxo script: | CHANGED_FILES=`git diff --name-only --diff-filter=ACMR $TRAVIS_COMMIT_RANGE | grep \\\\.php | awk '{print}' ORS=' '` From 282ff63330c44cc88d60f37da39fd8e6f256b731 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Wed, 28 Jul 2021 10:03:43 +0300 Subject: [PATCH 23/31] Add tests --- .../WcGateway/Gateway/WcGatewayTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php index 716a86ac2..f46ac5865 100644 --- a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway\Gateway; +use Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Session\SessionHandler; use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper; @@ -365,6 +366,45 @@ class WcGatewayTest extends TestCase $this->assertFalse($testee->capture_authorized_payment($wcOrder)); } + + /** + * @dataProvider dataForTestNeedsSetup + */ + public function testNeedsSetup($currentState, $needSetup) + { + expect('is_admin')->andReturn(true); + $settingsRenderer = Mockery::mock(SettingsRenderer::class); + $orderProcessor = Mockery::mock(OrderProcessor::class); + $authorizedOrdersProcessor = Mockery::mock(AuthorizedPaymentsProcessor::class); + $authorizeOrderActionNotice = Mockery::mock(AuthorizeOrderActionNotice::class); + $config = Mockery::mock(ContainerInterface::class); + $config + ->shouldReceive('has') + ->andReturn(false); + $sessionHandler = Mockery::mock(SessionHandler::class); + $refundProcessor = Mockery::mock(RefundProcessor::class); + $onboardingState = Mockery::mock(State::class); + $onboardingState + ->expects('current_state') + ->andReturn($currentState); + $transactionUrlProvider = Mockery::mock(TransactionUrlProvider::class); + $subscriptionHelper = Mockery::mock(SubscriptionHelper::class); + + $testee = new PayPalGateway( + $settingsRenderer, + $orderProcessor, + $authorizedOrdersProcessor, + $authorizeOrderActionNotice, + $config, + $sessionHandler, + $refundProcessor, + $onboardingState, + $transactionUrlProvider, + $subscriptionHelper + ); + + $this->assertSame($needSetup, $testee->needs_setup()); + } public function dataForTestCaptureAuthorizedPaymentNoActionableFailures() : array { @@ -383,4 +423,13 @@ class WcGatewayTest extends TestCase ], ]; } + + public function dataForTestNeedsSetup(): array + { + return [ + [State::STATE_START, true], + [State::STATE_PROGRESSIVE, true], + [State::STATE_ONBOARDED, false] + ]; + } } From a123a63afe69feaea3315ca75eaac154539f402c Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 29 Jul 2021 15:33:16 +0200 Subject: [PATCH 24/31] Use `get_icon` to display credit card gateway icons --- .../src/Gateway/class-creditcardgateway.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php b/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php index 6bb790518..1bc7938f8 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php @@ -236,21 +236,16 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { } /** - * Returns the title of the gateway. + * Returns the icons of the gateway. * * @return string */ - public function get_title() { + public function get_icon() { + $icon = parent::get_icon(); - //phpcs:disable WordPress.Security.NonceVerification.Recommended - if ( ! is_checkout() || ( is_ajax() && isset( $_GET['wc-ajax'] ) && 'update_order_review' !== $_GET['wc-ajax'] ) ) { - return parent::get_title(); - } - //phpcs:enable WordPress.Security.NonceVerification.Recommended - $title = parent::get_title(); $icons = $this->config->has( 'card_icons' ) ? (array) $this->config->get( 'card_icons' ) : array(); if ( empty( $icons ) ) { - return $title; + return $icon; } $title_options = $this->card_labels(); @@ -264,7 +259,8 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { }, $icons ); - return $title . implode( '', $images ); + + return implode( '', $images ); } /** From 008fcbc5f9e221b68f8db0beb4f2ba367ed8307d Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 2 Aug 2021 16:24:41 +0200 Subject: [PATCH 25/31] Implement `update_option` method in PayPal gateway to synchronize gateway enabled option --- .../src/Gateway/class-paypalgateway.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php index 0748445b9..e1aadeb83 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php @@ -381,4 +381,20 @@ class PayPalGateway extends \WC_Payment_Gateway { return parent::get_transaction_url( $order ); } + + /** + * Updates WooCommerce gateway option. + * + * @param string $key The option key. + * @param string $value The option value. + * @return bool|void + */ + public function update_option( $key, $value = '' ) { + parent::update_option( $key, $value ); + + if ( 'enabled' === $key ) { + $this->config->set( 'enabled', 'yes' === $value ); + $this->config->persist(); + } + } } From 9df2b1804a42f3b53faae1fd8ba065c6cfe9e1e9 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Mon, 2 Aug 2021 09:41:31 -0500 Subject: [PATCH 26/31] Bump "Tested up to" to 5.8 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index d287575f7..667a86402 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: woocommerce, automattic Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell, shop, shopping, cart, checkout Requires at least: 5.3 -Tested up to: 5.7 +Tested up to: 5.8 Requires PHP: 7.1 Stable tag: 1.4.0 License: GPLv2 From 00cc01376717e55204a8c60226bfab290053d571 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 3 Aug 2021 13:00:28 +0200 Subject: [PATCH 27/31] Remove double slash in icons src --- modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php b/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php index 1bc7938f8..86604af4b 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php @@ -253,7 +253,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { function ( string $type ) use ( $title_options ): string { return ' '; }, From 643bb1702d4438537ec6740d5d2b08f6d725b6b0 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 4 Aug 2021 16:38:42 +0200 Subject: [PATCH 28/31] Hide mini cart height field when mini cart is disabled --- modules/ppcp-onboarding/assets/js/settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ppcp-onboarding/assets/js/settings.js b/modules/ppcp-onboarding/assets/js/settings.js index 605dbdff6..e30b45856 100644 --- a/modules/ppcp-onboarding/assets/js/settings.js +++ b/modules/ppcp-onboarding/assets/js/settings.js @@ -253,6 +253,7 @@ document.addEventListener( '#field-button_mini-cart_label', '#field-button_mini-cart_color', '#field-button_mini-cart_shape', + '#field-button_mini-cart_height', ] ); From e305849b6e91f9782b351dad451da5ac22e41dc7 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 4 Aug 2021 16:52:29 +0200 Subject: [PATCH 29/31] Cast gateway description to string to prevent fatal error when is received as null --- modules/ppcp-subscription/src/class-subscriptionmodule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-subscription/src/class-subscriptionmodule.php b/modules/ppcp-subscription/src/class-subscriptionmodule.php index edb7f9408..91ab2ed8c 100644 --- a/modules/ppcp-subscription/src/class-subscriptionmodule.php +++ b/modules/ppcp-subscription/src/class-subscriptionmodule.php @@ -80,7 +80,7 @@ class SubscriptionModule implements ModuleInterface { $settings = $container->get( 'wcgateway.settings' ); $subscription_helper = $container->get( 'subscription.helper' ); - return $this->display_saved_paypal_payments( $settings, $id, $payment_token_repository, $description, $subscription_helper ); + return $this->display_saved_paypal_payments( $settings, $id, $payment_token_repository, (string) $description, $subscription_helper ); }, 10, 2 From a943fc4feaa3ceedb4fa2819d28915e86e9551e4 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 5 Aug 2021 09:52:24 +0200 Subject: [PATCH 30/31] Cast gateway id to string --- modules/ppcp-subscription/src/class-subscriptionmodule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-subscription/src/class-subscriptionmodule.php b/modules/ppcp-subscription/src/class-subscriptionmodule.php index 91ab2ed8c..5984ab988 100644 --- a/modules/ppcp-subscription/src/class-subscriptionmodule.php +++ b/modules/ppcp-subscription/src/class-subscriptionmodule.php @@ -80,7 +80,7 @@ class SubscriptionModule implements ModuleInterface { $settings = $container->get( 'wcgateway.settings' ); $subscription_helper = $container->get( 'subscription.helper' ); - return $this->display_saved_paypal_payments( $settings, $id, $payment_token_repository, (string) $description, $subscription_helper ); + return $this->display_saved_paypal_payments( $settings, (string) $id, $payment_token_repository, (string) $description, $subscription_helper ); }, 10, 2 From 8cb26a2aa082cb9511c735ecbdb29e94ea1871eb Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 9 Aug 2021 12:25:50 +0200 Subject: [PATCH 31/31] Add filters for button label default value --- modules/ppcp-wc-gateway/services.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index d114c560e..f072e347c 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -761,7 +761,7 @@ return array( 'type' => 'select', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'paypal', + 'default' => apply_filters( 'woocommerce_paypal_payments_button_label_default', 'paypal' ), 'desc_tip' => true, 'description' => __( 'This controls the label on the primary button.', @@ -1063,7 +1063,7 @@ return array( 'type' => 'select', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'paypal', + 'default' => apply_filters( 'woocommerce_paypal_payments_button_product_label_default', 'paypal' ), 'desc_tip' => true, 'description' => __( 'This controls the label on the primary button.', @@ -1366,7 +1366,7 @@ return array( 'type' => 'select', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'paypal', + 'default' => apply_filters( 'woocommerce_paypal_payments_button_cart_label_default', 'paypal' ), 'desc_tip' => true, 'description' => __( 'This controls the label on the primary button.', @@ -1669,7 +1669,7 @@ return array( 'type' => 'select', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'paypal', + 'default' => apply_filters( 'woocommerce_paypal_payments_button_mini_cart_label_default', 'paypal' ), 'desc_tip' => true, 'description' => __( 'This controls the label on the primary button.',