From 3281c6139420a68a75fa3dae739b71aa8094acb6 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 31 May 2021 12:01:14 +0200 Subject: [PATCH 01/50] Add query parameter `enable-funding=venmo` to all button loads except when Vault is turned on --- modules/ppcp-button/src/Assets/class-smartbutton.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 0af35654c..bdeed2394 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -754,6 +754,10 @@ class SmartButton implements SmartButtonInterface { $params['disable-funding'] = implode( ',', array_unique( $disable_funding ) ); } + if ( ! $this->settings->has( 'vault_enabled' ) || ! $this->settings->get( 'vault_enabled' ) ) { + $params['enable-funding'] = 'venmo'; + } + $smart_button_url = add_query_arg( $params, 'https://www.paypal.com/sdk/js' ); return $smart_button_url; } From 3e6efdea7653487772896a32e67e74c177ef46bd Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 9 Jun 2021 17:19:48 +0200 Subject: [PATCH 02/50] Ensure shipping info when patching order --- .../src/Endpoint/class-orderendpoint.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-api-client/src/Endpoint/class-orderendpoint.php b/modules/ppcp-api-client/src/Endpoint/class-orderendpoint.php index dd2003b36..adb41a59b 100644 --- a/modules/ppcp-api-client/src/Endpoint/class-orderendpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/class-orderendpoint.php @@ -502,6 +502,14 @@ class OrderEndpoint { return $order_to_update; } + $patches_array = $patches->to_array(); + if ( ! isset( $patches_array[0]['value']['shipping'] ) ) { + $shipping = isset( $order_to_update->purchase_units()[0] ) && null !== $order_to_update->purchase_units()[0]->shipping() ? $order_to_update->purchase_units()[0]->shipping() : null; + if ( $shipping ) { + $patches_array[0]['value']['shipping'] = $shipping->to_array(); + } + } + $bearer = $this->bearer->bearer(); $url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $order_to_update->id(); $args = array( @@ -514,7 +522,7 @@ class OrderEndpoint { $order_to_update ), ), - 'body' => wp_json_encode( $patches->to_array() ), + 'body' => wp_json_encode( $patches_array ), ); if ( $this->bn_code ) { $args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code; From 9e7b12f16b5ef3bf1979e663ac5a8affce5eac7c Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 10 Jun 2021 11:05:29 +0200 Subject: [PATCH 03/50] Do not send customer email when order status is on hold --- .../ppcp-wc-gateway/src/class-wcgatewaymodule.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php index 9e119a1cd..db0392879 100644 --- a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php +++ b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php @@ -135,6 +135,18 @@ class WcGatewayModule implements ModuleInterface { $endpoint->handle_request(); } ); + + add_filter( + 'woocommerce_email_recipient_customer_on_hold_order', + function( $recipient, $order ) { + if ( $order->get_payment_method() === PayPalGateway::ID || $order->get_payment_method() === CreditCardGateway::ID ) { + $recipient = ''; + } + return $recipient; + }, + 10, + 2 + ); } /** From 076a124ec725a4f0454ad9dd73c09fea3961d467 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 15 Jun 2021 12:48:01 +0200 Subject: [PATCH 04/50] Validate checkout form before creating PayPal order when creating account on checkout --- .../ActionHandler/CheckoutActionHandler.js | 5 +++- .../Endpoint/class-createorderendpoint.php | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js b/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js index 03451c144..6f5c9e48a 100644 --- a/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js +++ b/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js @@ -21,6 +21,8 @@ class CheckoutActionHandler { const formSelector = this.config.context === 'checkout' ? 'form.checkout' : 'form#order_review'; const formValues = jQuery(formSelector).serialize(); + const createaccount = jQuery('#createaccount').is(":checked") ? true : false; + return fetch(this.config.ajax.create_order.endpoint, { method: 'POST', body: JSON.stringify({ @@ -29,7 +31,8 @@ class CheckoutActionHandler { bn_code:bnCode, context:this.config.context, order_id:this.config.order_id, - form:formValues + form:formValues, + createaccount: createaccount }) }).then(function (res) { return res.json(); diff --git a/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php b/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php index 79e9a4185..932ca01a7 100644 --- a/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php +++ b/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php @@ -174,6 +174,36 @@ class CreateOrderEndpoint implements EndpointInterface { $this->set_bn_code( $data ); if ( 'checkout' === $data['context'] ) { + if ( '1' === $data['createaccount'] ) { + $form_values = explode( '&', $data['form'] ); + $parsed_values = array(); + foreach ( $form_values as $field ) { + $field = explode( '=', $field ); + + if ( count( $field ) !== 2 ) { + continue; + } + $parsed_values[ $field[0] ] = $field[1]; + } + $_POST = $parsed_values; + $_REQUEST = $parsed_values; + + add_action( + 'woocommerce_after_checkout_validation', + function( array $data, \WP_Error $errors ) use ( $wc_order ) { + if ( ! $errors->errors ) { + $order = $this->create_paypal_order( $wc_order ); + wp_send_json_success( $order->to_array() ); + return true; + } + }, + 10, + 2 + ); + + $checkout = \WC()->checkout(); + $checkout->process_checkout(); + } $this->process_checkout_form( $data['form'] ); } if ( 'pay-now' === $data['context'] && get_option( 'woocommerce_terms_page_id', '' ) !== '' ) { From f2f3633df4d2ca7644ec0a30ba7f90aa152fe411 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 15 Jun 2021 14:44:47 +0200 Subject: [PATCH 05/50] Refactoring --- .../Endpoint/class-createorderendpoint.php | 124 ++++++++++-------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php b/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php index 932ca01a7..cadc0e0fd 100644 --- a/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php +++ b/modules/ppcp-button/src/Endpoint/class-createorderendpoint.php @@ -175,36 +175,10 @@ class CreateOrderEndpoint implements EndpointInterface { if ( 'checkout' === $data['context'] ) { if ( '1' === $data['createaccount'] ) { - $form_values = explode( '&', $data['form'] ); - $parsed_values = array(); - foreach ( $form_values as $field ) { - $field = explode( '=', $field ); - - if ( count( $field ) !== 2 ) { - continue; - } - $parsed_values[ $field[0] ] = $field[1]; - } - $_POST = $parsed_values; - $_REQUEST = $parsed_values; - - add_action( - 'woocommerce_after_checkout_validation', - function( array $data, \WP_Error $errors ) use ( $wc_order ) { - if ( ! $errors->errors ) { - $order = $this->create_paypal_order( $wc_order ); - wp_send_json_success( $order->to_array() ); - return true; - } - }, - 10, - 2 - ); - - $checkout = \WC()->checkout(); - $checkout->process_checkout(); + $this->process_checkout_form_when_creating_account( $data['form'], $wc_order ); } - $this->process_checkout_form( $data['form'] ); + + $this->process_checkout_form( $data['form'] ); } if ( 'pay-now' === $data['context'] && get_option( 'woocommerce_terms_page_id', '' ) !== '' ) { $this->validate_paynow_form( $data['form'] ); @@ -231,6 +205,43 @@ class CreateOrderEndpoint implements EndpointInterface { return false; } + /** + * Once the checkout has been validated we execute this method. + * + * @param array $data The data. + * @param \WP_Error $errors The errors, which occurred. + * + * @return array + */ + public function after_checkout_validation( array $data, \WP_Error $errors ): array { + if ( ! $errors->errors ) { + + $order = $this->create_paypal_order(); + + /** + * In case we are onboarded and everything is fine with the \WC_Order + * we want this order to be created. We will intercept it and leave it + * in the "Pending payment" status though, which than later will change + * during the "onApprove"-JS callback or the webhook listener. + */ + if ( ! $this->early_order_handler->should_create_early_order() ) { + wp_send_json_success( $order->to_array() ); + } + $this->early_order_handler->register_for_order( $order ); + return $data; + } + + wp_send_json_error( + array( + 'name' => '', + 'message' => $errors->get_error_message(), + 'code' => (int) $errors->get_error_code(), + 'details' => array(), + ) + ); + return $data; + } + /** * Creates the order in the PayPal, uses data from WC order if provided. * @@ -371,39 +382,40 @@ class CreateOrderEndpoint implements EndpointInterface { } /** - * Once the checkout has been validated we execute this method. + * Processes checkout and creates the PayPal order after success form validation. * - * @param array $data The data. - * @param \WP_Error $errors The errors, which occurred. - * - * @return array + * @param string $form_values The values of the form. + * @param \WC_Order|null $wc_order WC order to get data from. + * @throws \Exception On Error. */ - public function after_checkout_validation( array $data, \WP_Error $errors ): array { - if ( ! $errors->errors ) { + private function process_checkout_form_when_creating_account( string $form_values, \WC_Order $wc_order = null ) { + $form_values = explode( '&', $form_values ); + $parsed_values = array(); + foreach ( $form_values as $field ) { + $field = explode( '=', $field ); - $order = $this->create_paypal_order(); - - /** - * In case we are onboarded and everything is fine with the \WC_Order - * we want this order to be created. We will intercept it and leave it - * in the "Pending payment" status though, which than later will change - * during the "onApprove"-JS callback or the webhook listener. - */ - if ( ! $this->early_order_handler->should_create_early_order() ) { - wp_send_json_success( $order->to_array() ); + if ( count( $field ) !== 2 ) { + continue; } - $this->early_order_handler->register_for_order( $order ); - return $data; + $parsed_values[ $field[0] ] = $field[1]; } + $_POST = $parsed_values; + $_REQUEST = $parsed_values; - wp_send_json_error( - array( - 'name' => '', - 'message' => $errors->get_error_message(), - 'code' => (int) $errors->get_error_code(), - 'details' => array(), - ) + add_action( + 'woocommerce_after_checkout_validation', + function ( array $data, \WP_Error $errors ) use ( $wc_order ) { + if ( ! $errors->errors ) { + $order = $this->create_paypal_order( $wc_order ); + wp_send_json_success( $order->to_array() ); + return true; + } + }, + 10, + 2 ); - return $data; + + $checkout = \WC()->checkout(); + $checkout->process_checkout(); } } From bdd9bb76369f7f2355910fcf8f9973d233c30480 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 15 Jun 2021 15:52:55 +0200 Subject: [PATCH 06/50] Remove vault conditional when adding venmo to enable funding --- modules/ppcp-button/src/Assets/class-smartbutton.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index bdeed2394..b765023e8 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -754,9 +754,7 @@ class SmartButton implements SmartButtonInterface { $params['disable-funding'] = implode( ',', array_unique( $disable_funding ) ); } - if ( ! $this->settings->has( 'vault_enabled' ) || ! $this->settings->get( 'vault_enabled' ) ) { - $params['enable-funding'] = 'venmo'; - } + $params['enable-funding'] = 'venmo'; $smart_button_url = add_query_arg( $params, 'https://www.paypal.com/sdk/js' ); return $smart_button_url; From 6a229b989a55bd0dc26a4ab72df9cde2758da6ad Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 16 Jun 2021 15:46:59 +0200 Subject: [PATCH 07/50] Add canada to advanced credit and debit card --- .../src/Helper/class-dccapplies.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/ppcp-api-client/src/Helper/class-dccapplies.php b/modules/ppcp-api-client/src/Helper/class-dccapplies.php index 2984be4a4..3224ab7b6 100644 --- a/modules/ppcp-api-client/src/Helper/class-dccapplies.php +++ b/modules/ppcp-api-client/src/Helper/class-dccapplies.php @@ -118,6 +118,24 @@ class DccApplies { 'JPY', 'USD', ), + 'CA' => array( + 'AUD', + 'CAD', + 'CHF', + 'CZK', + 'DKK', + 'EUR', + 'GBP', + 'HKD', + 'HUF', + 'JPY', + 'NOK', + 'NZD', + 'PLN', + 'SEK', + 'SGD', + 'USD', + ), ); /** @@ -157,6 +175,12 @@ class DccApplies { 'amex' => array( 'USD' ), 'discover' => array( 'USD' ), ), + 'CA' => array( + 'mastercard' => array(), + 'visa' => array(), + 'amex' => array( 'CAD' ), + 'jcb' => array( 'CAD' ), + ), ); /** From 8774879b798488d45aafe0c42423e0f2d0583e9e Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 16 Jun 2021 15:54:45 +0200 Subject: [PATCH 08/50] Remove `merchant-id` parameter on js sdk script --- modules/ppcp-button/src/Assets/class-smartbutton.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 67808ca49..4f65e5d72 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -740,10 +740,6 @@ class SmartButton implements SmartButtonInterface { ) { $params['buyer-country'] = WC()->customer->get_billing_country(); } - $payee = $this->payee_repository->payee(); - if ( $payee->merchant_id() ) { - $params['merchant-id'] = $payee->merchant_id(); - } $disable_funding = $this->settings->has( 'disable_funding' ) ? $this->settings->get( 'disable_funding' ) : array(); if ( ! is_checkout() ) { From b493ec5a5467a6b6389e0c6e21baab19613e6523 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 17 Jun 2021 11:51:43 +0200 Subject: [PATCH 09/50] Add `paylater` to enable funding when pay later messaging is enabled --- modules/ppcp-button/services.php | 4 +- .../src/Assets/class-smartbutton.php | 21 ++++++- modules/ppcp-wc-gateway/services.php | 9 ++- .../src/Helper/class-settingsstatus.php | 55 +++++++++++++++++++ .../src/Settings/class-settingsrenderer.php | 37 +++++-------- 5 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 modules/ppcp-wc-gateway/src/Helper/class-settingsstatus.php diff --git a/modules/ppcp-button/services.php b/modules/ppcp-button/services.php index 40d735d4e..5138a7770 100644 --- a/modules/ppcp-button/services.php +++ b/modules/ppcp-button/services.php @@ -69,6 +69,7 @@ return array( $messages_apply = $container->get( 'button.helper.messages-apply' ); $environment = $container->get( 'onboarding.environment' ); $payment_token_repository = $container->get( 'subscription.repository.payment-token' ); + $settings_status = $container->get( 'wcgateway.settings.status' ); return new SmartButton( $container->get( 'button.url' ), $container->get( 'session.handler' ), @@ -81,7 +82,8 @@ return array( $subscription_helper, $messages_apply, $environment, - $payment_token_repository + $payment_token_repository, + $settings_status ); }, 'button.url' => static function ( $container ): string { diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 67808ca49..e6a83f073 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -23,6 +23,7 @@ use WooCommerce\PayPalCommerce\Session\SessionHandler; use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper; use WooCommerce\PayPalCommerce\Subscription\Repository\PaymentTokenRepository; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; +use Woocommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; /** @@ -30,6 +31,13 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; */ class SmartButton implements SmartButtonInterface { + /** + * The Settings status helper. + * + * @var SettingsStatus + */ + protected $settings_status; + /** * The URL to the module. * @@ -129,6 +137,7 @@ class SmartButton implements SmartButtonInterface { * @param MessagesApply $messages_apply The Messages apply helper. * @param Environment $environment The environment object. * @param PaymentTokenRepository $payment_token_repository The payment token repository. + * @param SettingsStatus $settings_status The Settings status helper. */ public function __construct( string $module_url, @@ -142,7 +151,8 @@ class SmartButton implements SmartButtonInterface { SubscriptionHelper $subscription_helper, MessagesApply $messages_apply, Environment $environment, - PaymentTokenRepository $payment_token_repository + PaymentTokenRepository $payment_token_repository, + SettingsStatus $settings_status ) { $this->module_url = $module_url; @@ -157,6 +167,7 @@ class SmartButton implements SmartButtonInterface { $this->messages_apply = $messages_apply; $this->environment = $environment; $this->payment_token_repository = $payment_token_repository; + $this->settings_status = $settings_status; } /** @@ -754,6 +765,14 @@ class SmartButton implements SmartButtonInterface { $params['disable-funding'] = implode( ',', array_unique( $disable_funding ) ); } + $enable_funding = array(); + if ( $this->settings_status->pay_later_messaging_is_enabled() ) { + $enable_funding[] = 'paylater'; + } + if ( count( $enable_funding ) > 0 ) { + $params['enable-funding'] = implode( ',', array_unique( $enable_funding ) ); + } + $smart_button_url = add_query_arg( $params, 'https://www.paypal.com/sdk/js' ); return $smart_button_url; } diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 3377705ed..f7a5b0bd2 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -25,6 +25,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use Woocommerce\PayPalCommerce\WcGateway\Helper\DccProductStatus; +use Woocommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus; use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice; use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice; use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; @@ -114,6 +115,10 @@ return array( 'wcgateway.settings.sections-renderer' => static function ( $container ): SectionsRenderer { return new SectionsRenderer(); }, + 'wcgateway.settings.status' => static function ( $container ): SettingsStatus { + $settings = $container->get( 'wcgateway.settings' ); + return new SettingsStatus( $settings ); + }, 'wcgateway.settings.render' => static function ( $container ): SettingsRenderer { $settings = $container->get( 'wcgateway.settings' ); $state = $container->get( 'onboarding.state' ); @@ -121,13 +126,15 @@ return array( $dcc_applies = $container->get( 'api.helpers.dccapplies' ); $messages_apply = $container->get( 'button.helper.messages-apply' ); $dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' ); + $settings_status = $container->get( 'wcgateway.settings.status' ); return new SettingsRenderer( $settings, $state, $fields, $dcc_applies, $messages_apply, - $dcc_product_status + $dcc_product_status, + $settings_status ); }, 'wcgateway.settings.listener' => static function ( $container ): SettingsListener { diff --git a/modules/ppcp-wc-gateway/src/Helper/class-settingsstatus.php b/modules/ppcp-wc-gateway/src/Helper/class-settingsstatus.php new file mode 100644 index 000000000..f74355a1a --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Helper/class-settingsstatus.php @@ -0,0 +1,55 @@ +settings = $settings; + } + + /** + * Check whether Pay Later message is enabled either for checkout, cart or product page. + * + * @return bool + * @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting was not found. + */ + public function pay_later_messaging_is_enabled(): bool { + $pay_later_message_enabled_for_checkout = $this->settings->has( 'message_enabled' ) + && (bool) $this->settings->get( 'message_enabled' ); + + $pay_later_message_enabled_for_cart = $this->settings->has( 'message_cart_enabled' ) + && (bool) $this->settings->get( 'message_cart_enabled' ); + + $pay_later_message_enabled_for_product = $this->settings->has( 'message_product_enabled' ) + && (bool) $this->settings->get( 'message_product_enabled' ); + + return $pay_later_message_enabled_for_checkout || + $pay_later_message_enabled_for_cart || + $pay_later_message_enabled_for_product; + } +} diff --git a/modules/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php b/modules/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php index 2e425f550..21ed1abfb 100644 --- a/modules/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php +++ b/modules/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php @@ -16,12 +16,20 @@ use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use Psr\Container\ContainerInterface; use Woocommerce\PayPalCommerce\WcGateway\Helper\DccProductStatus; +use Woocommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus; /** * Class SettingsRenderer */ class SettingsRenderer { + /** + * The Settings status helper. + * + * @var SettingsStatus + */ + protected $settings_status; + /** * The settings. * @@ -73,6 +81,7 @@ class SettingsRenderer { * @param DccApplies $dcc_applies Whether DCC gateway can be shown. * @param MessagesApply $messages_apply Whether messages can be shown. * @param DccProductStatus $dcc_product_status The product status. + * @param SettingsStatus $settings_status The Settings status helper. */ public function __construct( ContainerInterface $settings, @@ -80,7 +89,8 @@ class SettingsRenderer { array $fields, DccApplies $dcc_applies, MessagesApply $messages_apply, - DccProductStatus $dcc_product_status + DccProductStatus $dcc_product_status, + SettingsStatus $settings_status ) { $this->settings = $settings; @@ -89,6 +99,7 @@ class SettingsRenderer { $this->dcc_applies = $dcc_applies; $this->messages_apply = $messages_apply; $this->dcc_product_status = $dcc_product_status; + $this->settings_status = $settings_status; } /** @@ -106,7 +117,7 @@ class SettingsRenderer { $pay_later_messages_title = __( 'Pay Later Messaging', 'woocommerce-paypal-payments' ); $enabled = $this->paypal_vaulting_is_enabled() ? $vaulting_title : $pay_later_messages_title; - $disabled = $this->pay_later_messaging_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. @@ -149,26 +160,6 @@ class SettingsRenderer { return $this->settings->has( 'vault_enabled' ) && (bool) $this->settings->get( 'vault_enabled' ); } - /** - * Check whether Pay Later message is enabled either for checkout, cart or product page. - * - * @return bool - */ - private function pay_later_messaging_is_enabled(): bool { - $pay_later_message_enabled_for_checkout = $this->settings->has( 'message_enabled' ) - && (bool) $this->settings->get( 'message_enabled' ); - - $pay_later_message_enabled_for_cart = $this->settings->has( 'message_cart_enabled' ) - && (bool) $this->settings->get( 'message_cart_enabled' ); - - $pay_later_message_enabled_for_product = $this->settings->has( 'message_product_enabled' ) - && (bool) $this->settings->get( 'message_product_enabled' ); - - return $pay_later_message_enabled_for_checkout || - $pay_later_message_enabled_for_cart || - $pay_later_message_enabled_for_product; - } - /** * Check if current screen is PayPal checkout settings screen. * @@ -557,6 +548,6 @@ class SettingsRenderer { } return $this->is_paypal_checkout_screen() && $this->paypal_vaulting_is_enabled() - || $this->is_paypal_checkout_screen() && $this->pay_later_messaging_is_enabled(); + || $this->is_paypal_checkout_screen() && $this->settings_status->pay_later_messaging_is_enabled(); } } From 64f856b83d9739e950a0eec7466bbf13661e5511 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 17 Jun 2021 14:42:41 +0200 Subject: [PATCH 10/50] Remove payee repository on smart button class --- modules/ppcp-button/services.php | 2 -- modules/ppcp-button/src/Assets/class-smartbutton.php | 11 ----------- 2 files changed, 13 deletions(-) diff --git a/modules/ppcp-button/services.php b/modules/ppcp-button/services.php index 40d735d4e..d48f7427a 100644 --- a/modules/ppcp-button/services.php +++ b/modules/ppcp-button/services.php @@ -59,7 +59,6 @@ return array( if ( $paypal_disabled ) { return new DisabledSmartButton(); } - $payee_repository = $container->get( 'api.repository.payee' ); $payer_factory = $container->get( 'api.factory.payer' ); $request_data = $container->get( 'button.request-data' ); @@ -73,7 +72,6 @@ return array( $container->get( 'button.url' ), $container->get( 'session.handler' ), $settings, - $payee_repository, $payer_factory, $client_id, $request_data, diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 4f65e5d72..0539b8b02 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\Button\Assets; use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; -use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository; use WooCommerce\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint; use WooCommerce\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint; use WooCommerce\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint; @@ -51,13 +50,6 @@ class SmartButton implements SmartButtonInterface { */ private $settings; - /** - * The Payee Repository. - * - * @var PayeeRepository - */ - private $payee_repository; - /** * The Payer Factory. * @@ -120,7 +112,6 @@ class SmartButton implements SmartButtonInterface { * @param string $module_url The URL to the module. * @param SessionHandler $session_handler The Session Handler. * @param Settings $settings The Settings. - * @param PayeeRepository $payee_repository The Payee Repository. * @param PayerFactory $payer_factory The Payer factory. * @param string $client_id The client ID. * @param RequestData $request_data The Request Data helper. @@ -134,7 +125,6 @@ class SmartButton implements SmartButtonInterface { string $module_url, SessionHandler $session_handler, Settings $settings, - PayeeRepository $payee_repository, PayerFactory $payer_factory, string $client_id, RequestData $request_data, @@ -148,7 +138,6 @@ class SmartButton implements SmartButtonInterface { $this->module_url = $module_url; $this->session_handler = $session_handler; $this->settings = $settings; - $this->payee_repository = $payee_repository; $this->payer_factory = $payer_factory; $this->client_id = $client_id; $this->request_data = $request_data; From 00b4d4a78e1c848fb8f82be72d8954e03a9a5658 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 17 Jun 2021 17:04:02 +0200 Subject: [PATCH 11/50] Add button height setting for mini cart --- .../src/Assets/class-smartbutton.php | 18 ++++++++++++++++++ modules/ppcp-wc-gateway/services.php | 13 +++++++++++++ .../src/Settings/class-settingslistener.php | 1 + 3 files changed, 32 insertions(+) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 67808ca49..dd2ab216d 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -650,6 +650,7 @@ class SmartButton implements SmartButtonInterface { 'shape' => $this->style_for_context( 'shape', 'mini-cart' ), 'label' => $this->style_for_context( 'label', 'mini-cart' ), 'tagline' => $this->style_for_context( 'tagline', 'mini-cart' ), + 'height' => $this->settings->has( 'button_mini-cart_height' ) && $this->settings->get( 'button_mini-cart_height' ) ? $this->normalize_height( (int) $this->settings->get( 'button_mini-cart_height' ) ) : 35, ), 'style' => array( 'layout' => $this->style_for_context( 'layout', $this->context() ), @@ -939,4 +940,21 @@ class SmartButton implements SmartButtonInterface { } return (string) $value; } + + /** + * Returns a value between 25 and 55. + * + * @param int $height The input value. + * @return int The normalized output value. + */ + private function normalize_height( int $height ): int { + if ( $height < 25 ) { + return 25; + } + if ( $height > 55 ) { + return 55; + } + + return $height; + } } diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 3377705ed..3c458ab48 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1727,6 +1727,19 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), + 'button_mini-cart_height' => array( + 'title' => __( 'Button Height', 'woocommerce-paypal-payments' ), + 'type' => 'number', + 'default' => '35', + 'desc_tip' => true, + 'description' => __( 'Add a value from 25 to 55.', 'woocommerce-paypal-payments' ), + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => 'paypal', + ), 'disable_cards' => array( 'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-payments' ), diff --git a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php index 9560917ff..7512c76d7 100644 --- a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php +++ b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php @@ -315,6 +315,7 @@ class SettingsListener { $settings[ $key ] = isset( $raw_data[ $key ] ); break; case 'text': + case 'number': case 'ppcp-text-input': case 'ppcp-password': $settings[ $key ] = isset( $raw_data[ $key ] ) ? sanitize_text_field( $raw_data[ $key ] ) : ''; From cbfa3f84c04af0c26ad7d7cf7cedb5a19732bd41 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 18 Jun 2021 12:38:54 +0200 Subject: [PATCH 12/50] Add pay later button disclaimer --- modules/ppcp-wc-gateway/services.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index f7a5b0bd2..fe9c990d3 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -835,7 +835,7 @@ return array( ), 'requirements' => array( 'messages' ), 'gateway' => 'paypal', - 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more.', 'woocommerce-paypal-payments' ) ), + 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. Pay Later button will show for eligible buyers and PayPal determines eligibility.', 'woocommerce-paypal-payments' ) ), 'class' => array( 'ppcp-subheading' ), ), 'message_enabled' => array( @@ -1138,7 +1138,7 @@ return array( ), 'requirements' => array( 'messages' ), 'gateway' => 'paypal', - 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more.', 'woocommerce-paypal-payments' ) ), + 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. Pay Later button will show for eligible buyers and PayPal determines eligibility.', 'woocommerce-paypal-payments' ) ), 'class' => array( 'ppcp-subheading' ), ), 'message_product_enabled' => array( @@ -1441,7 +1441,7 @@ return array( ), 'requirements' => array( 'messages' ), 'gateway' => 'paypal', - 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more.', 'woocommerce-paypal-payments' ) ), + 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. Pay Later button will show for eligible buyers and PayPal determines eligibility.', 'woocommerce-paypal-payments' ) ), 'class' => array( 'ppcp-subheading' ), ), 'message_cart_enabled' => array( From 6dc26ec06c598c0f3ab35cd1db703095adcd94f3 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 18 Jun 2021 15:29:19 +0200 Subject: [PATCH 13/50] Add `data-partner-attribution-id` parameter to jssdk when messaging is enabled --- modules/ppcp-button/src/Assets/class-smartbutton.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index e6a83f073..82c15303f 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -773,6 +773,10 @@ class SmartButton implements SmartButtonInterface { $params['enable-funding'] = implode( ',', array_unique( $enable_funding ) ); } + if ( $this->settings_status->pay_later_messaging_is_enabled() ) { + $params['data-partner-attribution-id'] = 'Woo_PPCP'; + } + $smart_button_url = add_query_arg( $params, 'https://www.paypal.com/sdk/js' ); return $smart_button_url; } From 74c8bc9b49583e77ee028282da8e1d7168e5103f Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 18 Jun 2021 16:53:43 +0200 Subject: [PATCH 14/50] Add `enable-funding=paylater` to all button loads unless the merchant has added paylater to disable funding settings --- 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 e6a83f073..ec1e063f5 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -766,7 +766,7 @@ class SmartButton implements SmartButtonInterface { } $enable_funding = array(); - if ( $this->settings_status->pay_later_messaging_is_enabled() ) { + if ( $this->settings_status->pay_later_messaging_is_enabled() || ! in_array( 'credit', $disable_funding, true ) ) { $enable_funding[] = 'paylater'; } if ( count( $enable_funding ) > 0 ) { From 1beb414f817a38226d3d383673d65023a04ea731 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 21 Jun 2021 16:45:19 +0200 Subject: [PATCH 15/50] Add 30 seconds timeout by default to all requests --- modules/ppcp-api-client/src/Endpoint/class-requesttrait.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/ppcp-api-client/src/Endpoint/class-requesttrait.php b/modules/ppcp-api-client/src/Endpoint/class-requesttrait.php index b54dc0bbd..7066f13b1 100644 --- a/modules/ppcp-api-client/src/Endpoint/class-requesttrait.php +++ b/modules/ppcp-api-client/src/Endpoint/class-requesttrait.php @@ -24,6 +24,8 @@ trait RequestTrait { */ private function request( string $url, array $args ) { + $args['timeout'] = 30; + /** * This filter can be used to alter the request args. * For example, during testing, the PayPal-Mock-Response header could be From 2fdd1746216c2d0f2c10ec75c221aa826c9624bb Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 22 Jun 2021 15:55:31 +0200 Subject: [PATCH 16/50] Remove `data-partner-attribution-id` query parameter --- modules/ppcp-button/src/Assets/class-smartbutton.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 82c15303f..e6a83f073 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -773,10 +773,6 @@ class SmartButton implements SmartButtonInterface { $params['enable-funding'] = implode( ',', array_unique( $enable_funding ) ); } - if ( $this->settings_status->pay_later_messaging_is_enabled() ) { - $params['data-partner-attribution-id'] = 'Woo_PPCP'; - } - $smart_button_url = add_query_arg( $params, 'https://www.paypal.com/sdk/js' ); return $smart_button_url; } From d4f46b305688ce92521b34d47b791060f9b02ad6 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 23 Jun 2021 11:59:52 +0200 Subject: [PATCH 17/50] Add `data-partner-attribution-id` data attribute to messages wrapper div --- 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 e6a83f073..d3e118eb6 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -449,7 +449,7 @@ class SmartButton implements SmartButtonInterface { */ public function message_renderer() { - echo '
'; + echo '
'; } /** From 6c20336bc82f46ad64c48f205c3473d6aa8bc504 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 1 Jul 2021 09:39:18 +0200 Subject: [PATCH 18/50] Add `venmo` to enable funding by default --- modules/ppcp-button/src/Assets/class-smartbutton.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index aff4bb742..3f2a1912a 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -765,11 +765,10 @@ class SmartButton implements SmartButtonInterface { $params['disable-funding'] = implode( ',', array_unique( $disable_funding ) ); } - $enable_funding = array(); + $enable_funding = array( 'venmo' ); if ( $this->settings_status->pay_later_messaging_is_enabled() || ! in_array( 'credit', $disable_funding, true ) ) { $enable_funding[] = 'paylater'; } - $params['enable-funding'] = 'venmo'; if ( count( $enable_funding ) > 0 ) { $params['enable-funding'] = implode( ',', array_unique( $enable_funding ) ); } From e7e80c309504652c5d4bd2768f1d84302b360b11 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 2 Jul 2021 12:31:20 +0200 Subject: [PATCH 19/50] Fix unhandled exceptions when token creation fails --- .../src/Authentication/class-paypalbearer.php | 6 ++++- .../src/Assets/class-settingspageassets.php | 21 +++++++++------- .../src/Settings/class-settingslistener.php | 24 +++++++++++++++---- .../src/class-wcgatewaymodule.php | 1 + 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/modules/ppcp-api-client/src/Authentication/class-paypalbearer.php b/modules/ppcp-api-client/src/Authentication/class-paypalbearer.php index 55e06a045..fb4cac9ac 100644 --- a/modules/ppcp-api-client/src/Authentication/class-paypalbearer.php +++ b/modules/ppcp-api-client/src/Authentication/class-paypalbearer.php @@ -120,7 +120,11 @@ class PayPalBearer implements Bearer { if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { $error = new RuntimeException( - __( 'Could not create token.', 'woocommerce-paypal-payments' ) + sprintf( + // translators: %s is the error description. + __( 'Could not create token. %s', 'woocommerce-paypal-payments' ), + isset( json_decode( $response['body'] )->error_description ) ? json_decode( $response['body'] )->error_description : '' + ) ); $this->logger->log( 'warning', diff --git a/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php b/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php index 197c07e03..d4d699398 100644 --- a/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php +++ b/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway\Assets; use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; +use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; /** * Class SettingsPageAssets @@ -111,13 +112,17 @@ class SettingsPageAssets { true ); - $token = $bearer->bearer(); - wp_localize_script( - 'ppcp-gateway-settings', - 'PayPalCommerceGatewaySettings', - array( - 'vaulting_features_available' => $token->vaulting_available(), - ) - ); + try { + $token = $bearer->bearer(); + wp_localize_script( + 'ppcp-gateway-settings', + 'PayPalCommerceGatewaySettings', + array( + 'vaulting_features_available' => $token->vaulting_available(), + ) + ); + } catch ( RuntimeException $exception ) { + // Already displaying an admin message in SettingsListener. + } } } diff --git a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php index 7512c76d7..1bb26eb78 100644 --- a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php +++ b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php @@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings; use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer; +use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; @@ -147,11 +148,24 @@ class SettingsListener { return; } - $token = $this->bearer->bearer(); - if ( ! $token->vaulting_available() ) { - $this->settings->set( 'vault_enabled', false ); - $this->settings->persist(); - return; + try { + $token = $this->bearer->bearer(); + if ( ! $token->vaulting_available() ) { + $this->settings->set( 'vault_enabled', false ); + $this->settings->persist(); + return; + } + } catch ( RuntimeException $exception ) { + add_action( + 'admin_notices', + function () use ( $exception ) { + printf( + // translators: %s is the error message. + '

%s

', + $exception->getMessage() + ); + } + ); } /** diff --git a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php index db0392879..50d8d1f4e 100644 --- a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php +++ b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php @@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway; use Dhii\Container\ServiceProvider; use Dhii\Modular\Module\ModuleInterface; +use http\Exception\RuntimeException; use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository; From db4e1422d86cca406dd5657d6091fb2e67f8bacd Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 2 Jul 2021 12:36:59 +0200 Subject: [PATCH 20/50] Remove unused class --- modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php index 50d8d1f4e..db0392879 100644 --- a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php +++ b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php @@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway; use Dhii\Container\ServiceProvider; use Dhii\Modular\Module\ModuleInterface; -use http\Exception\RuntimeException; use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository; From d8817134a95cbd5f5b209fb422e74952a4d055ff Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 13 Jan 2021 15:28:08 +0100 Subject: [PATCH 21/50] Update `dhii\module-interface` --- composer.json | 3 ++- modules/ppcp-admin-notices/src/class-adminnotices.php | 2 +- modules/ppcp-api-client/src/class-apimodule.php | 2 +- modules/ppcp-button/src/class-buttonmodule.php | 2 +- modules/ppcp-onboarding/src/class-onboardingmodule.php | 3 ++- modules/ppcp-session/src/class-sessionmodule.php | 2 +- modules/ppcp-subscription/src/class-subscriptionmodule.php | 2 +- modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php | 2 +- modules/ppcp-webhooks/src/class-webhookmodule.php | 2 +- .../woocommerce-logging/src/class-woocommerceloggingmodule.php | 2 +- 10 files changed, 12 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index cec1c7724..bceb96309 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,9 @@ "description": "PayPal Commerce Platform for WooCommerce", "license": "GPL-2.0", "require": { - "dhii/module-interface": "0.1", + "dhii/module-interface": "0.2.x-dev", "psr/container": "1.0.0", + "oomphinc/composer-installers-extender": "^1.1", "container-interop/service-provider": "^0.4.0", "dhii/containers": "v0.1.0-alpha1", "dhii/wp-containers": "v0.1.0-alpha1", diff --git a/modules/ppcp-admin-notices/src/class-adminnotices.php b/modules/ppcp-admin-notices/src/class-adminnotices.php index e8ae55b47..657a1bc0f 100644 --- a/modules/ppcp-admin-notices/src/class-adminnotices.php +++ b/modules/ppcp-admin-notices/src/class-adminnotices.php @@ -36,7 +36,7 @@ class AdminNotices implements ModuleInterface { * * @param ContainerInterface $container The container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { add_action( 'admin_notices', function() use ( $container ) { diff --git a/modules/ppcp-api-client/src/class-apimodule.php b/modules/ppcp-api-client/src/class-apimodule.php index 9b466f87b..a6f1ace8f 100644 --- a/modules/ppcp-api-client/src/class-apimodule.php +++ b/modules/ppcp-api-client/src/class-apimodule.php @@ -37,7 +37,7 @@ class ApiModule implements ModuleInterface { * * @param ContainerInterface $container The container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { } /** diff --git a/modules/ppcp-button/src/class-buttonmodule.php b/modules/ppcp-button/src/class-buttonmodule.php index 8d06a91fe..5981c14c9 100644 --- a/modules/ppcp-button/src/class-buttonmodule.php +++ b/modules/ppcp-button/src/class-buttonmodule.php @@ -43,7 +43,7 @@ class ButtonModule implements ModuleInterface { * * @param ContainerInterface|null $container The Container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { add_action( 'wp', diff --git a/modules/ppcp-onboarding/src/class-onboardingmodule.php b/modules/ppcp-onboarding/src/class-onboardingmodule.php index 3526f7c33..2bfabe0bd 100644 --- a/modules/ppcp-onboarding/src/class-onboardingmodule.php +++ b/modules/ppcp-onboarding/src/class-onboardingmodule.php @@ -40,7 +40,8 @@ class OnboardingModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { + $asset_loader = $container->get( 'onboarding.assets' ); /** * The OnboardingAssets. diff --git a/modules/ppcp-session/src/class-sessionmodule.php b/modules/ppcp-session/src/class-sessionmodule.php index 8e1d97055..7199b5078 100644 --- a/modules/ppcp-session/src/class-sessionmodule.php +++ b/modules/ppcp-session/src/class-sessionmodule.php @@ -37,7 +37,7 @@ class SessionModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { add_action( 'woocommerce_init', function () use ( $container ) { diff --git a/modules/ppcp-subscription/src/class-subscriptionmodule.php b/modules/ppcp-subscription/src/class-subscriptionmodule.php index 82b4117f4..20d964d82 100644 --- a/modules/ppcp-subscription/src/class-subscriptionmodule.php +++ b/modules/ppcp-subscription/src/class-subscriptionmodule.php @@ -44,7 +44,7 @@ class SubscriptionModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { add_action( 'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID, function ( $amount, $order ) use ( $container ) { diff --git a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php index db0392879..faf79817f 100644 --- a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php +++ b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php @@ -53,7 +53,7 @@ class WcGatewayModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { $this->register_payment_gateways( $container ); $this->register_order_functionality( $container ); $this->register_columns( $container ); diff --git a/modules/ppcp-webhooks/src/class-webhookmodule.php b/modules/ppcp-webhooks/src/class-webhookmodule.php index 5700430bd..5e2783798 100644 --- a/modules/ppcp-webhooks/src/class-webhookmodule.php +++ b/modules/ppcp-webhooks/src/class-webhookmodule.php @@ -36,7 +36,7 @@ class WebhookModule implements ModuleInterface { * * @param ContainerInterface|null $container The Container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { add_action( 'rest_api_init', static function () use ( $container ) { diff --git a/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php b/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php index aa629b5c8..11a0054f5 100644 --- a/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php +++ b/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php @@ -36,7 +36,7 @@ class WooCommerceLoggingModule implements ModuleInterface { * * @param ContainerInterface $container The container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { } From 4bca690161af87c970555c8cc6946df746513f78 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 13 Jan 2021 15:58:48 +0100 Subject: [PATCH 22/50] Update `dhii/module-interface` version constrain --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bceb96309..8a8f40407 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "PayPal Commerce Platform for WooCommerce", "license": "GPL-2.0", "require": { - "dhii/module-interface": "0.2.x-dev", + "dhii/module-interface": "^0.2", "psr/container": "1.0.0", "oomphinc/composer-installers-extender": "^1.1", "container-interop/service-provider": "^0.4.0", From 2a8ee97ad1ad842d0e0e3922517199bda04fe7ad Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Tue, 6 Jul 2021 09:44:04 -0500 Subject: [PATCH 23/50] Update PluginModule::run() to follow upstream's signature --- composer.json | 1 - src/class-pluginmodule.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8a8f40407..fd5d98be5 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,6 @@ "require": { "dhii/module-interface": "^0.2", "psr/container": "1.0.0", - "oomphinc/composer-installers-extender": "^1.1", "container-interop/service-provider": "^0.4.0", "dhii/containers": "v0.1.0-alpha1", "dhii/wp-containers": "v0.1.0-alpha1", diff --git a/src/class-pluginmodule.php b/src/class-pluginmodule.php index b961c4878..f891c6e84 100644 --- a/src/class-pluginmodule.php +++ b/src/class-pluginmodule.php @@ -31,7 +31,7 @@ class PluginModule implements ModuleInterface { * * @param ContainerInterface|null $container The Container. */ - public function run( ContainerInterface $container = null ) { + public function run( ContainerInterface $container ) { } /** From 362b782387797946bd34c98849bbf51900a49e06 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 11:22:19 +0200 Subject: [PATCH 24/50] Fix phpcs errors --- modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php | 2 +- modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php b/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php index d4d699398..db22c2c2f 100644 --- a/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php +++ b/modules/ppcp-wc-gateway/src/Assets/class-settingspageassets.php @@ -122,7 +122,7 @@ class SettingsPageAssets { ) ); } catch ( RuntimeException $exception ) { - // Already displaying an admin message in SettingsListener. + return; } } } diff --git a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php index 1bb26eb78..e76238b65 100644 --- a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php +++ b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php @@ -160,7 +160,6 @@ class SettingsListener { 'admin_notices', function () use ( $exception ) { printf( - // translators: %s is the error message. '

%s

', $exception->getMessage() ); From 3cf78834a34489e23596c3acdda62ffde2487ec6 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 11:30:08 +0200 Subject: [PATCH 25/50] Fix github actions workflow --- .github/workflows/php.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index e2d5f1752..78f1729ba 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,10 +11,19 @@ jobs: runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ['7.1'] + steps: - uses: actions/checkout@v2 - - name: Validate composer.json and composer.lock + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + + - name: Validate composer.json and composer.lock run: composer validate - name: Install dependencies From 7b1297a4536ccd5363e675457d7f53bcae34ce79 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 11:30:49 +0200 Subject: [PATCH 26/50] Fix github actions workflow --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 78f1729ba..955552a87 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -23,7 +23,7 @@ jobs: with: php-version: ${{ matrix.php-versions }} - - name: Validate composer.json and composer.lock + - name: Validate composer.json and composer.lock run: composer validate - name: Install dependencies From 060d3561a53227b778d21b6c28798fc97ed53ba5 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 11:37:46 +0200 Subject: [PATCH 27/50] Fix phpcs errors --- .github/workflows/php.yml | 3 --- .../ppcp-wc-gateway/src/Settings/class-settingslistener.php | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 955552a87..ddeaeaf11 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -29,9 +29,6 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest - # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" - # Docs: https://getcomposer.org/doc/articles/scripts.md - - name: Run test suite run: ./vendor/bin/phpunit - name: Run Woocommerce coding standards diff --git a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php index e76238b65..e7a559355 100644 --- a/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php +++ b/modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php @@ -161,7 +161,7 @@ class SettingsListener { function () use ( $exception ) { printf( '

%s

', - $exception->getMessage() + esc_attr( $exception->getMessage() ) ); } ); From ab6f8a3c996cffcbb3c8cb0ccb3354b6c83d2368 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 17:16:26 +0200 Subject: [PATCH 28/50] Check single product and mini card setting for displaying PayPal buttons --- modules/ppcp-button/resources/js/button.js | 14 +++++---- .../src/Assets/class-smartbutton.php | 30 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js index 067bc5347..7d3b1484d 100644 --- a/modules/ppcp-button/resources/js/button.js +++ b/modules/ppcp-button/resources/js/button.js @@ -18,15 +18,17 @@ const bootstrap = () => { const messageRenderer = new MessageRenderer(PayPalCommerceGateway.messages); const context = PayPalCommerceGateway.context; if (context === 'mini-cart' || context === 'product') { - const miniCartBootstrap = new MiniCartBootstap( - PayPalCommerceGateway, - renderer - ); + if (PayPalCommerceGateway.mini_card_buttons_enabled === '1') { + const miniCartBootstrap = new MiniCartBootstap( + PayPalCommerceGateway, + renderer + ); - miniCartBootstrap.init(); + miniCartBootstrap.init(); + } } - if (context === 'product') { + if (context === 'product' && PayPalCommerceGateway.single_product_buttons_enabled === '1') { const singleProductBootstrap = new SingleProductBootstap( PayPalCommerceGateway, renderer, diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index 016028d4d..ffcdf1bb6 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -612,16 +612,16 @@ class SmartButton implements SmartButtonInterface { $this->request_data->enqueue_nonce_fix(); $localize = array( - 'script_attributes' => $this->attributes(), - 'data_client_id' => array( + 'script_attributes' => $this->attributes(), + 'data_client_id' => array( 'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() ) || $this->can_save_vault_token(), 'endpoint' => home_url( \WC_AJAX::get_endpoint( DataClientIdEndpoint::ENDPOINT ) ), 'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ), 'user' => get_current_user_id(), ), - 'redirect' => wc_get_checkout_url(), - 'context' => $this->context(), - 'ajax' => array( + 'redirect' => wc_get_checkout_url(), + 'context' => $this->context(), + 'ajax' => array( 'change_cart' => array( 'endpoint' => home_url( \WC_AJAX::get_endpoint( ChangeCartEndpoint::ENDPOINT ) ), 'nonce' => wp_create_nonce( ChangeCartEndpoint::nonce() ), @@ -635,11 +635,11 @@ class SmartButton implements SmartButtonInterface { 'nonce' => wp_create_nonce( ApproveOrderEndpoint::nonce() ), ), ), - 'enforce_vault' => $this->has_subscriptions(), - 'save_card' => $this->can_save_vault_token(), - 'bn_codes' => $this->bn_codes(), - 'payer' => $this->payerData(), - 'button' => array( + 'enforce_vault' => $this->has_subscriptions(), + 'save_card' => $this->can_save_vault_token(), + 'bn_codes' => $this->bn_codes(), + 'payer' => $this->payerData(), + 'button' => array( 'wrapper' => '#ppc-button', 'mini_cart_wrapper' => '#ppc-button-minicart', 'cancel_wrapper' => '#ppcp-cancel', @@ -660,7 +660,7 @@ class SmartButton implements SmartButtonInterface { 'tagline' => $this->style_for_context( 'tagline', $this->context() ), ), ), - 'hosted_fields' => array( + 'hosted_fields' => array( 'wrapper' => '#ppcp-hosted-fields', 'mini_cart_wrapper' => '#ppcp-hosted-fields-mini-cart', 'labels' => array( @@ -678,8 +678,8 @@ class SmartButton implements SmartButtonInterface { ), 'valid_cards' => $this->dcc_applies->valid_cards(), ), - 'messages' => $this->message_values(), - 'labels' => array( + 'messages' => $this->message_values(), + 'labels' => array( 'error' => array( 'generic' => __( 'Something went wrong. Please try again or choose another payment source.', @@ -687,7 +687,9 @@ class SmartButton implements SmartButtonInterface { ), ), ), - 'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0, + 'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0, + 'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ), + 'mini_card_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ), ); if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) { From 2b34496ea74bc115673fb0594ceb0e7e634ab25d Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 17:21:38 +0200 Subject: [PATCH 29/50] Fix yaml indentation on GH actions workflow --- .github/workflows/php.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index ddeaeaf11..02a171b9e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -19,9 +19,9 @@ jobs: - uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} - name: Validate composer.json and composer.lock run: composer validate From 7a6508fc1b1b0ae9b2287561486b897010fd0d1c Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 17:23:11 +0200 Subject: [PATCH 30/50] Run ci on php 7.3 --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 02a171b9e..001d1bdcc 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - php-versions: ['7.1'] + php-versions: ['7.3'] steps: - uses: actions/checkout@v2 From 03d2eed36b293e5901fc5ea4127911d36e403571 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 12 Jul 2021 17:31:07 +0200 Subject: [PATCH 31/50] Fix phpunit tests --- tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php index cbfba53b6..17ebf857b 100644 --- a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php +++ b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php @@ -432,6 +432,9 @@ class OrderEndpointTest extends TestCase $orderToUpdate ->shouldReceive('id') ->andReturn($orderId); + $orderToUpdate + ->shouldReceive('purchase_units') + ->andReturn([]); $orderToCompare = Mockery::mock(Order::class); $rawResponse = ['body' => '{"is_correct":true}']; @@ -526,6 +529,9 @@ class OrderEndpointTest extends TestCase $orderToUpdate ->shouldReceive('id') ->andReturn($orderId); + $orderToUpdate + ->shouldReceive('purchase_units') + ->andReturn([]); $orderToCompare = Mockery::mock(Order::class); $rawResponse = ['body' => '{"has_error":true}']; @@ -614,6 +620,9 @@ class OrderEndpointTest extends TestCase $orderToUpdate ->shouldReceive('id') ->andReturn($orderId); + $orderToUpdate + ->shouldReceive('purchase_units') + ->andReturn([]); $orderToCompare = Mockery::mock(Order::class); $rawResponse = ['body' => '{"is_correct":true}']; From fad6c27ae4345ec59fef3d00a61738b4fc9358cb Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 13 Jul 2021 09:43:30 +0200 Subject: [PATCH 32/50] Fix typo in variable name --- modules/ppcp-button/resources/js/button.js | 2 +- modules/ppcp-button/src/Assets/class-smartbutton.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js index 7d3b1484d..424b691a7 100644 --- a/modules/ppcp-button/resources/js/button.js +++ b/modules/ppcp-button/resources/js/button.js @@ -18,7 +18,7 @@ const bootstrap = () => { const messageRenderer = new MessageRenderer(PayPalCommerceGateway.messages); const context = PayPalCommerceGateway.context; if (context === 'mini-cart' || context === 'product') { - if (PayPalCommerceGateway.mini_card_buttons_enabled === '1') { + if (PayPalCommerceGateway.mini_cart_buttons_enabled === '1') { const miniCartBootstrap = new MiniCartBootstap( PayPalCommerceGateway, renderer diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index ffcdf1bb6..e003aec9b 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -689,7 +689,7 @@ class SmartButton implements SmartButtonInterface { ), 'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0, 'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ), - 'mini_card_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ), + 'mini_cart_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ), ); if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) { From a9922f36b1a33ec70af702eafa2c35c2e3ad396c Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 13 Jul 2021 11:55:59 +0200 Subject: [PATCH 33/50] Do not rerender hosted fields on each checkout form field update --- .../resources/js/modules/ContextBootstrap/CheckoutBootstap.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js index e4558e34a..75c9408e0 100644 --- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js +++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js @@ -13,10 +13,6 @@ class CheckoutBootstap { this.render(); - jQuery(document.body).on('updated_checkout', () => { - this.render() - }); - jQuery(document.body). on('updated_checkout payment_method_selected', () => { this.switchBetweenPayPalandOrderButton() From 0daedb7461f4f834011e70d47363e673ea520019 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 13 Jul 2021 16:16:17 +0200 Subject: [PATCH 34/50] Make mini cart button layout vertical by default --- modules/ppcp-wc-gateway/services.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 3c458ab48..742fd125a 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1623,7 +1623,7 @@ return array( 'type' => 'select', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'horizontal', + '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.', From 090e829f754b32ded9d727b7aa4ad0a66736c720 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 13 Jul 2021 16:20:27 +0200 Subject: [PATCH 35/50] Make mini cart button layout vertical by default --- modules/ppcp-wc-gateway/services.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 1b6c109a1..d114c560e 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1630,7 +1630,7 @@ return array( 'type' => 'select', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => 'horizontal', + '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.', From 119543ae2d2d58ab81939e90b146a87e24a2307b Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 14 Jul 2021 14:58:23 +0200 Subject: [PATCH 36/50] Update `dhii/module-interface` to version 0.3 --- composer.json | 2 +- modules/ppcp-admin-notices/src/class-adminnotices.php | 2 +- modules/ppcp-api-client/src/class-apimodule.php | 2 +- modules/ppcp-button/src/class-buttonmodule.php | 2 +- modules/ppcp-onboarding/src/class-onboardingmodule.php | 2 +- modules/ppcp-session/src/class-sessionmodule.php | 2 +- modules/ppcp-subscription/src/class-subscriptionmodule.php | 2 +- modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php | 2 +- modules/ppcp-webhooks/src/class-webhookmodule.php | 2 +- .../woocommerce-logging/src/class-woocommerceloggingmodule.php | 2 +- phpcs.xml.dist | 2 +- src/class-pluginmodule.php | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index fd5d98be5..c562752b0 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "PayPal Commerce Platform for WooCommerce", "license": "GPL-2.0", "require": { - "dhii/module-interface": "^0.2", + "dhii/module-interface": "^0.2 || ^0.3", "psr/container": "1.0.0", "container-interop/service-provider": "^0.4.0", "dhii/containers": "v0.1.0-alpha1", diff --git a/modules/ppcp-admin-notices/src/class-adminnotices.php b/modules/ppcp-admin-notices/src/class-adminnotices.php index 657a1bc0f..686ae4db6 100644 --- a/modules/ppcp-admin-notices/src/class-adminnotices.php +++ b/modules/ppcp-admin-notices/src/class-adminnotices.php @@ -36,7 +36,7 @@ class AdminNotices implements ModuleInterface { * * @param ContainerInterface $container The container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { add_action( 'admin_notices', function() use ( $container ) { diff --git a/modules/ppcp-api-client/src/class-apimodule.php b/modules/ppcp-api-client/src/class-apimodule.php index a6f1ace8f..70265dad9 100644 --- a/modules/ppcp-api-client/src/class-apimodule.php +++ b/modules/ppcp-api-client/src/class-apimodule.php @@ -37,7 +37,7 @@ class ApiModule implements ModuleInterface { * * @param ContainerInterface $container The container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { } /** diff --git a/modules/ppcp-button/src/class-buttonmodule.php b/modules/ppcp-button/src/class-buttonmodule.php index 5981c14c9..659183db8 100644 --- a/modules/ppcp-button/src/class-buttonmodule.php +++ b/modules/ppcp-button/src/class-buttonmodule.php @@ -43,7 +43,7 @@ class ButtonModule implements ModuleInterface { * * @param ContainerInterface|null $container The Container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { add_action( 'wp', diff --git a/modules/ppcp-onboarding/src/class-onboardingmodule.php b/modules/ppcp-onboarding/src/class-onboardingmodule.php index 2bfabe0bd..7fdaf5d55 100644 --- a/modules/ppcp-onboarding/src/class-onboardingmodule.php +++ b/modules/ppcp-onboarding/src/class-onboardingmodule.php @@ -40,7 +40,7 @@ class OnboardingModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { $asset_loader = $container->get( 'onboarding.assets' ); /** diff --git a/modules/ppcp-session/src/class-sessionmodule.php b/modules/ppcp-session/src/class-sessionmodule.php index 7199b5078..b2c5a5aef 100644 --- a/modules/ppcp-session/src/class-sessionmodule.php +++ b/modules/ppcp-session/src/class-sessionmodule.php @@ -37,7 +37,7 @@ class SessionModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { add_action( 'woocommerce_init', function () use ( $container ) { diff --git a/modules/ppcp-subscription/src/class-subscriptionmodule.php b/modules/ppcp-subscription/src/class-subscriptionmodule.php index 20d964d82..edb7f9408 100644 --- a/modules/ppcp-subscription/src/class-subscriptionmodule.php +++ b/modules/ppcp-subscription/src/class-subscriptionmodule.php @@ -44,7 +44,7 @@ class SubscriptionModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { add_action( 'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID, function ( $amount, $order ) use ( $container ) { diff --git a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php index faf79817f..981491351 100644 --- a/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php +++ b/modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php @@ -53,7 +53,7 @@ class WcGatewayModule implements ModuleInterface { * * @param ContainerInterface|null $container The container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { $this->register_payment_gateways( $container ); $this->register_order_functionality( $container ); $this->register_columns( $container ); diff --git a/modules/ppcp-webhooks/src/class-webhookmodule.php b/modules/ppcp-webhooks/src/class-webhookmodule.php index 5e2783798..24a765a08 100644 --- a/modules/ppcp-webhooks/src/class-webhookmodule.php +++ b/modules/ppcp-webhooks/src/class-webhookmodule.php @@ -36,7 +36,7 @@ class WebhookModule implements ModuleInterface { * * @param ContainerInterface|null $container The Container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { add_action( 'rest_api_init', static function () use ( $container ) { diff --git a/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php b/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php index 11a0054f5..1d4da4899 100644 --- a/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php +++ b/modules/woocommerce-logging/src/class-woocommerceloggingmodule.php @@ -36,7 +36,7 @@ class WooCommerceLoggingModule implements ModuleInterface { * * @param ContainerInterface $container The container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e33a90b71..533eefc50 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -4,7 +4,7 @@ - + diff --git a/src/class-pluginmodule.php b/src/class-pluginmodule.php index f891c6e84..ef622a978 100644 --- a/src/class-pluginmodule.php +++ b/src/class-pluginmodule.php @@ -31,7 +31,7 @@ class PluginModule implements ModuleInterface { * * @param ContainerInterface|null $container The Container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { } /** From 473463597ac2d815061bbb136b6bee2812929953 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Thu, 15 Jul 2021 06:51:37 -0500 Subject: [PATCH 37/50] Add compatibility module --- modules/ppcp-compat/extensions.php | 12 +++++ modules/ppcp-compat/module.php | 16 ++++++ modules/ppcp-compat/services.php | 12 +++++ .../ppcp-compat/src/class-compatmodule.php | 49 +++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 modules/ppcp-compat/extensions.php create mode 100644 modules/ppcp-compat/module.php create mode 100644 modules/ppcp-compat/services.php create mode 100644 modules/ppcp-compat/src/class-compatmodule.php diff --git a/modules/ppcp-compat/extensions.php b/modules/ppcp-compat/extensions.php new file mode 100644 index 000000000..8155f88b8 --- /dev/null +++ b/modules/ppcp-compat/extensions.php @@ -0,0 +1,12 @@ + Date: Thu, 15 Jul 2021 17:27:19 +0200 Subject: [PATCH 38/50] Move hosted fields validation into `validityChange` event --- .../js/modules/ContextBootstrap/CartBootstap.js | 2 +- .../modules/ContextBootstrap/CheckoutBootstap.js | 4 ++++ .../js/modules/Renderer/CreditCardRenderer.js | 14 +++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CartBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CartBootstap.js index 83fe11f65..29e6a4819 100644 --- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CartBootstap.js +++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CartBootstap.js @@ -39,4 +39,4 @@ class CartBootstrap { } } -export default CartBootstrap; \ No newline at end of file +export default CartBootstrap; diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js index 75c9408e0..e4558e34a 100644 --- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js +++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js @@ -13,6 +13,10 @@ class CheckoutBootstap { this.render(); + jQuery(document.body).on('updated_checkout', () => { + this.render() + }); + jQuery(document.body). on('updated_checkout payment_method_selected', () => { this.switchBetweenPayPalandOrderButton() diff --git a/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js b/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js index ee7153c67..9745997ba 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js @@ -7,6 +7,7 @@ class CreditCardRenderer { this.errorHandler = errorHandler; this.spinner = spinner; this.cardValid = false; + this.formValid = false; } render(wrapper, contextConfig) { @@ -97,12 +98,8 @@ class CreditCardRenderer { event.preventDefault(); } this.errorHandler.clear(); - const state = hostedFields.getState(); - const formValid = Object.keys(state.fields).every(function (key) { - return state.fields[key].isValid; - }); - if (formValid && this.cardValid) { + if (this.formValid && this.cardValid) { const save_card = this.defaultConfig.save_card ? true : false; const vault = document.getElementById('ppcp-credit-card-vault') ? document.getElementById('ppcp-credit-card-vault').checked : save_card; @@ -134,6 +131,13 @@ class CreditCardRenderer { const validCards = this.defaultConfig.hosted_fields.valid_cards; this.cardValid = validCards.indexOf(event.cards[0].type) !== -1; }) + hostedFields.on('validityChange', (event) => { + const formValid = Object.keys(event.fields).every(function (key) { + return event.fields[key].isValid; + }); + this.formValid = formValid; + + }) document.querySelector(wrapper + ' button').addEventListener( 'click', submitEvent From e79c71224b8efde8bec10e3bb86b511a3eaa956a Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 16 Jul 2021 09:26:52 +0200 Subject: [PATCH 39/50] Implement `void` return on `run` method --- modules/ppcp-compat/src/class-compatmodule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-compat/src/class-compatmodule.php b/modules/ppcp-compat/src/class-compatmodule.php index 37ae4a62c..d377998b9 100644 --- a/modules/ppcp-compat/src/class-compatmodule.php +++ b/modules/ppcp-compat/src/class-compatmodule.php @@ -36,7 +36,7 @@ class CompatModule implements ModuleInterface { * * @param ContainerInterface|null $container The Container. */ - public function run( ContainerInterface $container ) { + public function run( ContainerInterface $container ): void { } /** From 16a48156a50e68c98e5676bbd8de417826aeee3d Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 16 Jul 2021 11:04:01 +0200 Subject: [PATCH 40/50] 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 41/50] 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 42/50] 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 dca37828c600199d12dca374ad9bec7e3846b228 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Tue, 27 Jul 2021 11:09:35 -0500 Subject: [PATCH 43/50] 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 44/50] 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 45/50] 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 46/50] 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 47/50] 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 48/50] 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 008fcbc5f9e221b68f8db0beb4f2ba367ed8307d Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 2 Aug 2021 16:24:41 +0200 Subject: [PATCH 49/50] 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 50/50] 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