From 6efcaa56309cc9d3c0fbfcaed7da3d86f191b23c Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Tue, 2 Jul 2024 16:10:10 +0200 Subject: [PATCH 01/12] =?UTF-8?q?=E2=9C=A8=20New=20option=20to=20configure?= =?UTF-8?q?=20BN-Code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Configurable via a wp-config constant, or a new wp-filter. --- .../src/Endpoint/RequestTrait.php | 2 +- .../ppcp-button/src/Assets/SmartButton.php | 35 +++++++++++++++---- .../src/PayLaterBlockRenderer.php | 9 ++++- .../resources/js/paylater-configurator.js | 2 +- .../src/PayLaterConfiguratorModule.php | 8 +++++ .../src/PayLaterWCBlocksRenderer.php | 11 ++++-- woocommerce-paypal-payments.php | 2 ++ 7 files changed, 57 insertions(+), 12 deletions(-) diff --git a/modules/ppcp-api-client/src/Endpoint/RequestTrait.php b/modules/ppcp-api-client/src/Endpoint/RequestTrait.php index 369dc9c1e..cb5f3c543 100644 --- a/modules/ppcp-api-client/src/Endpoint/RequestTrait.php +++ b/modules/ppcp-api-client/src/Endpoint/RequestTrait.php @@ -42,7 +42,7 @@ trait RequestTrait { */ $args = apply_filters( 'ppcp_request_args', $args, $url ); if ( ! isset( $args['headers']['PayPal-Partner-Attribution-Id'] ) ) { - $args['headers']['PayPal-Partner-Attribution-Id'] = 'Woo_PPCP'; + $args['headers']['PayPal-Partner-Attribution-Id'] = PPCP_PAYPAL_BN_CODE; } $response = wp_remote_get( $url, $args ); diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 202693929..30c248706 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -818,7 +818,14 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages */ do_action( "ppcp_before_{$location_hook}_message_wrapper" ); - $messages_placeholder = '
'; + /** + * The BN code. + * + * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE + */ + $bn_code = PPCP_PAYPAL_BN_CODE; + + $messages_placeholder = '
'; if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) { $this->render_after_block( @@ -1538,7 +1545,15 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages private function bn_code_for_context( string $context ): string { $codes = $this->bn_codes(); - return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : 'Woo_PPCP'; + + /** + * The BN code. + * + * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE + */ + $bn_code = PPCP_PAYPAL_BN_CODE; + + return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : $bn_code; } /** @@ -1546,13 +1561,19 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages * * @return array */ - private function bn_codes(): array { + private function bn_codes() : array { + /** + * The BN code. + * + * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE + */ + $bn_code = PPCP_PAYPAL_BN_CODE; return array( - 'checkout' => 'Woo_PPCP', - 'cart' => 'Woo_PPCP', - 'mini-cart' => 'Woo_PPCP', - 'product' => 'Woo_PPCP', + 'checkout' => $bn_code, + 'cart' => $bn_code, + 'mini-cart' => $bn_code, + 'product' => $bn_code, ); } diff --git a/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php b/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php index 75fa9cf25..cd4ef7182 100644 --- a/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php +++ b/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php @@ -28,7 +28,14 @@ class PayLaterBlockRenderer { public function render( array $attributes, ContainerInterface $c ): string { if ( PayLaterBlockModule::is_block_enabled( $c->get( 'wcgateway.settings.status' ) ) ) { - $html = '
'; + /** + * The BN code. + * + * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE + */ + $bn_code = PPCP_PAYPAL_BN_CODE; + + $html = '
'; $processor = new \WP_HTML_Tag_Processor( $html ); diff --git a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js index 5aa4df772..5b60ca99e 100644 --- a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js +++ b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js @@ -54,7 +54,7 @@ document.addEventListener('DOMContentLoaded', () => { merchantClientId: PcpPayLaterConfigurator.merchantClientId, partnerClientId: PcpPayLaterConfigurator.partnerClientId, partnerName: 'WooCommerce', - bnCode: 'Woo_PPCP', + bnCode: PcpPayLaterConfigurator.bnCode, placements: ['cart', 'checkout', 'product', 'shop', 'home', 'custom_placement'], styleOverrides: { button: publishButtonClassName, diff --git a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php index 3588f393a..739402386 100644 --- a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php +++ b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php @@ -113,6 +113,13 @@ class PayLaterConfiguratorModule implements ModuleInterface { $config_factory = $c->get( 'paylater-configurator.factory.config' ); assert( $config_factory instanceof ConfigFactory ); + /** + * The BN code. + * + * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE + */ + $bn_code = PPCP_PAYPAL_BN_CODE; + wp_localize_script( 'ppcp-paylater-configurator', 'PcpPayLaterConfigurator', @@ -130,6 +137,7 @@ class PayLaterConfiguratorModule implements ModuleInterface { 'config' => $config_factory->from_settings( $settings ), 'merchantClientId' => $settings->get( 'client_id' ), 'partnerClientId' => $c->get( 'api.partner_merchant_id' ), + 'bnCode' => $bn_code, 'publishButtonClassName' => 'ppcp-paylater-configurator-publishButton', 'headerClassName' => 'ppcp-paylater-configurator-header', 'subheaderClassName' => 'ppcp-paylater-configurator-subheader', diff --git a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php index 6709b9a5b..e62210473 100644 --- a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php +++ b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php @@ -95,14 +95,21 @@ class PayLaterWCBlocksRenderer { ) { if ( PayLaterWCBlocksModule::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), $location ) ) { - $html = '
'; + /** + * The BN code. + * + * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE + */ + $bn_code = PPCP_PAYPAL_BN_CODE; + + $html = '
'; $processor = new \WP_HTML_Tag_Processor( $html ); if ( $processor->next_tag( 'div' ) ) { $processor->set_attribute( 'data-block-name', esc_attr( $attributes['blockId'] ?? '' ) ); $processor->set_attribute( 'class', 'ppcp-messages' ); - $processor->set_attribute( 'data-partner-attribution-id', 'Woo_PPCP' ); + $processor->set_attribute( 'data-partner-attribution-id', $bn_code ); if ( $this->layout === 'flex' ) { $processor->set_attribute( 'data-pp-style-layout', 'flex' ); diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 32ea572df..10b53aa47 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -35,6 +35,8 @@ define( 'PAYPAL_INTEGRATION_DATE', '2024-06-25' ); ! defined( 'CONNECT_WOO_URL' ) && define( 'CONNECT_WOO_URL', 'https://api.woocommerce.com/integrations/ppc' ); ! defined( 'CONNECT_WOO_SANDBOX_URL' ) && define( 'CONNECT_WOO_SANDBOX_URL', 'https://api.woocommerce.com/integrations/ppcsandbox' ); +! defined( 'PPCP_PAYPAL_BN_CODE' ) && define( 'PPCP_PAYPAL_BN_CODE', apply_filters( 'woocommerce_paypal_payments_bn_code', 'Woo_PPCP' ) ); + ( function () { $autoload_filepath = __DIR__ . '/vendor/autoload.php'; if ( file_exists( $autoload_filepath ) && ! class_exists( '\WooCommerce\PayPalCommerce\PluginModule' ) ) { From ece3e3a17bc9d7ccb96d6160f06911f196748583 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Tue, 2 Jul 2024 16:55:18 +0200 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=9A=A8=20Update=20unit=20tests=20to?= =?UTF-8?q?=20define=20a=20BN-Code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/PHPUnit/ModularTestCase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/PHPUnit/ModularTestCase.php b/tests/PHPUnit/ModularTestCase.php index a880acfbe..5f2b42476 100644 --- a/tests/PHPUnit/ModularTestCase.php +++ b/tests/PHPUnit/ModularTestCase.php @@ -54,6 +54,7 @@ class ModularTestCase extends TestCase !defined('CONNECT_WOO_SANDBOX_MERCHANT_ID') && define('CONNECT_WOO_SANDBOX_MERCHANT_ID', 'merchant-id2'); !defined('CONNECT_WOO_URL') && define('CONNECT_WOO_URL', 'https://connect.woocommerce.com/ppc'); !defined('CONNECT_WOO_SANDBOX_URL') && define('CONNECT_WOO_SANDBOX_URL', 'https://connect.woocommerce.com/ppcsandbox'); + !defined('PPCP_PAYPAL_BN_CODE') && define('PPCP_PAYPAL_BN_CODE', apply_filters( 'woocommerce_paypal_payments_bn_code', 'Woo_PPCP')); } /** From fa11c6863f06d2edc7be7dd3c9c2b41b7aeb4d43 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Tue, 2 Jul 2024 17:13:23 +0200 Subject: [PATCH 03/12] Add constant to psalm stubs --- .psalm/stubs.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.psalm/stubs.php b/.psalm/stubs.php index 8b9348b1b..59be5215c 100644 --- a/.psalm/stubs.php +++ b/.psalm/stubs.php @@ -25,6 +25,10 @@ if (!defined('ABSPATH')) { define('ABSPATH', ''); } +if (!defined('PPCP_PAYPAL_BN_CODE')) { + define('PPCP_PAYPAL_BN_CODE', 'Woo_PPCP'); +} + /** * Cancel the next occurrence of a scheduled action. * From 78bbc1fd67f68817a76bb63fa343b607c870da10 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Tue, 2 Jul 2024 17:38:25 +0200 Subject: [PATCH 04/12] Remove psalm comments --- modules/ppcp-button/src/Assets/SmartButton.php | 16 +--------------- .../src/PayLaterBlockRenderer.php | 5 ----- .../src/PayLaterConfiguratorModule.php | 5 ----- .../src/PayLaterWCBlocksRenderer.php | 5 ----- tests/PHPUnit/ModularTestCase.php | 2 +- 5 files changed, 2 insertions(+), 31 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 30c248706..31dc6ae1a 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -818,11 +818,6 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages */ do_action( "ppcp_before_{$location_hook}_message_wrapper" ); - /** - * The BN code. - * - * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE - */ $bn_code = PPCP_PAYPAL_BN_CODE; $messages_placeholder = '
'; @@ -1546,11 +1541,6 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages $codes = $this->bn_codes(); - /** - * The BN code. - * - * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE - */ $bn_code = PPCP_PAYPAL_BN_CODE; return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : $bn_code; @@ -1562,11 +1552,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages * @return array */ private function bn_codes() : array { - /** - * The BN code. - * - * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE - */ + $bn_code = PPCP_PAYPAL_BN_CODE; return array( diff --git a/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php b/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php index cd4ef7182..74e8586b3 100644 --- a/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php +++ b/modules/ppcp-paylater-block/src/PayLaterBlockRenderer.php @@ -28,11 +28,6 @@ class PayLaterBlockRenderer { public function render( array $attributes, ContainerInterface $c ): string { if ( PayLaterBlockModule::is_block_enabled( $c->get( 'wcgateway.settings.status' ) ) ) { - /** - * The BN code. - * - * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE - */ $bn_code = PPCP_PAYPAL_BN_CODE; $html = '
'; diff --git a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php index 739402386..1aa35462c 100644 --- a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php +++ b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php @@ -113,11 +113,6 @@ class PayLaterConfiguratorModule implements ModuleInterface { $config_factory = $c->get( 'paylater-configurator.factory.config' ); assert( $config_factory instanceof ConfigFactory ); - /** - * The BN code. - * - * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE - */ $bn_code = PPCP_PAYPAL_BN_CODE; wp_localize_script( diff --git a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php index e62210473..f0720300b 100644 --- a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php +++ b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksRenderer.php @@ -95,11 +95,6 @@ class PayLaterWCBlocksRenderer { ) { if ( PayLaterWCBlocksModule::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), $location ) ) { - /** - * The BN code. - * - * @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE - */ $bn_code = PPCP_PAYPAL_BN_CODE; $html = '
'; diff --git a/tests/PHPUnit/ModularTestCase.php b/tests/PHPUnit/ModularTestCase.php index 5f2b42476..14b7e61ef 100644 --- a/tests/PHPUnit/ModularTestCase.php +++ b/tests/PHPUnit/ModularTestCase.php @@ -54,7 +54,7 @@ class ModularTestCase extends TestCase !defined('CONNECT_WOO_SANDBOX_MERCHANT_ID') && define('CONNECT_WOO_SANDBOX_MERCHANT_ID', 'merchant-id2'); !defined('CONNECT_WOO_URL') && define('CONNECT_WOO_URL', 'https://connect.woocommerce.com/ppc'); !defined('CONNECT_WOO_SANDBOX_URL') && define('CONNECT_WOO_SANDBOX_URL', 'https://connect.woocommerce.com/ppcsandbox'); - !defined('PPCP_PAYPAL_BN_CODE') && define('PPCP_PAYPAL_BN_CODE', apply_filters( 'woocommerce_paypal_payments_bn_code', 'Woo_PPCP')); + !defined('PPCP_PAYPAL_BN_CODE') && define('PPCP_PAYPAL_BN_CODE', 'Woo_PPCP'); } /** From 9613e4741f799eaa9b73d894569b7deda4feb55d Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 8 Jul 2024 14:45:12 +0200 Subject: [PATCH 05/12] Extend advanced card country eligibility --- modules/ppcp-api-client/services.php | 84 +++++++++++++++++++ modules/ppcp-card-fields/services.php | 24 ++++++ .../ppcp-save-payment-methods/services.php | 24 ++++++ 3 files changed, 132 insertions(+) diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php index f91e24119..426c7f1e4 100644 --- a/modules/ppcp-api-client/services.php +++ b/modules/ppcp-api-client/services.php @@ -723,6 +723,30 @@ return array( 'TWD', 'USD', ), + 'CN' => array( + 'AUD', + 'BRL', + 'CAD', + 'CHF', + 'CZK', + 'DKK', + 'EUR', + 'GBP', + 'HKD', + 'HUF', + 'ILS', + 'JPY', + 'MXN', + 'NOK', + 'NZD', + 'PHP', + 'PLN', + 'SEK', + 'SGD', + 'THB', + 'TWD', + 'USD', + ), 'CY' => array( 'AUD', 'BRL', @@ -915,6 +939,30 @@ return array( 'TWD', 'USD', ), + 'HK' => array( + 'AUD', + 'BRL', + 'CAD', + 'CHF', + 'CZK', + 'DKK', + 'EUR', + 'GBP', + 'HKD', + 'HUF', + 'ILS', + 'JPY', + 'MXN', + 'NOK', + 'NZD', + 'PHP', + 'PLN', + 'SEK', + 'SGD', + 'THB', + 'TWD', + 'USD', + ), 'HU' => array( 'AUD', 'BRL', @@ -1230,6 +1278,30 @@ return array( 'TWD', 'USD', ), + 'SG' => array( + 'AUD', + 'BRL', + 'CAD', + 'CHF', + 'CZK', + 'DKK', + 'EUR', + 'GBP', + 'HKD', + 'HUF', + 'ILS', + 'JPY', + 'MXN', + 'NOK', + 'NZD', + 'PHP', + 'PLN', + 'SEK', + 'SGD', + 'THB', + 'TWD', + 'USD', + ), 'SK' => array( 'AUD', 'BRL', @@ -1416,6 +1488,10 @@ return array( 'visa' => array(), 'amex' => array(), ), + 'CN' => array( + 'mastercard' => array(), + 'visa' => array(), + ), 'CY' => array( 'mastercard' => array(), 'visa' => array(), @@ -1466,6 +1542,10 @@ return array( 'visa' => array(), 'amex' => array(), ), + 'HK' => array( + 'mastercard' => array(), + 'visa' => array(), + ), 'HU' => array( 'mastercard' => array(), 'visa' => array(), @@ -1553,6 +1633,10 @@ return array( 'visa' => array(), 'amex' => array(), ), + 'SG' => array( + 'mastercard' => array(), + 'visa' => array(), + ), 'SI' => array( 'mastercard' => array(), 'visa' => array(), diff --git a/modules/ppcp-card-fields/services.php b/modules/ppcp-card-fields/services.php index 5374a1c48..85f8004b6 100644 --- a/modules/ppcp-card-fields/services.php +++ b/modules/ppcp-card-fields/services.php @@ -150,6 +150,30 @@ return array( 'TWD', 'USD', ), + 'CN' => array( + 'AUD', + 'BRL', + 'CAD', + 'CHF', + 'CZK', + 'DKK', + 'EUR', + 'GBP', + 'HKD', + 'HUF', + 'ILS', + 'JPY', + 'MXN', + 'NOK', + 'NZD', + 'PHP', + 'PLN', + 'SEK', + 'SGD', + 'THB', + 'TWD', + 'USD', + ), 'CY' => array( 'AUD', 'BRL', diff --git a/modules/ppcp-save-payment-methods/services.php b/modules/ppcp-save-payment-methods/services.php index a0b43f021..37f725d3c 100644 --- a/modules/ppcp-save-payment-methods/services.php +++ b/modules/ppcp-save-payment-methods/services.php @@ -153,6 +153,30 @@ return array( 'TWD', 'USD', ), + 'CN' => array( + 'AUD', + 'BRL', + 'CAD', + 'CHF', + 'CZK', + 'DKK', + 'EUR', + 'GBP', + 'HKD', + 'HUF', + 'ILS', + 'JPY', + 'MXN', + 'NOK', + 'NZD', + 'PHP', + 'PLN', + 'SEK', + 'SGD', + 'THB', + 'TWD', + 'USD', + ), 'CY' => array( 'AUD', 'BRL', From acc0ac61d2b562a396f5efe839125dc65fba78f8 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Wed, 10 Jul 2024 12:47:58 +0200 Subject: [PATCH 06/12] Replace the init hook with wp_loaded to avoid getting 'called too early' errors --- modules/ppcp-axo/src/AxoModule.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index 629b56421..3505ff555 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -140,12 +140,17 @@ class AxoModule implements ModuleInterface { ); add_action( - 'init', + 'wp_loaded', function () use ( $c ) { $module = $this; + $subscription_helper = $c->get( 'wc-subscriptions.helper' ); + assert( $subscription_helper instanceof SubscriptionHelper ); + // Check if the module is applicable, correct country, currency, ... etc. - if ( ! $c->get( 'axo.eligible' ) || 'continuation' === $c->get( 'button.context' ) ) { + if ( ! $c->get( 'axo.eligible' ) + || 'continuation' === $c->get( 'button.context' ) + || $subscription_helper->cart_contains_subscription() ) { return; } @@ -334,15 +339,11 @@ class AxoModule implements ModuleInterface { $is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false; $is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false; - $subscription_helper = $c->get( 'wc-subscriptions.helper' ); - assert( $subscription_helper instanceof SubscriptionHelper ); - return ! is_user_logged_in() && CartCheckoutDetector::has_classic_checkout() && $is_axo_enabled && $is_dcc_enabled - && ! $this->is_excluded_endpoint() - && ! $subscription_helper->cart_contains_subscription(); + && ! $this->is_excluded_endpoint(); } /** From a71a3dec5a30842a4c4ad87f819fce276ffd4543 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Thu, 11 Jul 2024 15:02:23 +0200 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=92=AC=20Fix=20incorrect=20preview?= =?UTF-8?q?=20box=20title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the wrong literal introduced here: --- .../src/Settings/Fields/paypal-smart-button-fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php index 02a6bcb87..3a2513e98 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/paypal-smart-button-fields.php @@ -28,7 +28,7 @@ return function ( ContainerInterface $container, array $fields ): array { $has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' ); - $preview_message = __( 'Standard Card Button Styling Preview', 'woocommerce-paypal-payments' ); + $preview_message = __( 'Button Styling Preview', 'woocommerce-paypal-payments' ); $axo_smart_button_location_notice = $container->has( 'axo.smart-button-location-notice' ) ? $container->get( 'axo.smart-button-location-notice' ) : ''; From ff304b41851080870063e0c1b953b44244b5a5a1 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Fri, 12 Jul 2024 12:13:09 +0200 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Remove=20filter?= =?UTF-8?q?=20for=20BN=20code=20constant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- woocommerce-paypal-payments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 10b53aa47..13402784f 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -35,7 +35,7 @@ define( 'PAYPAL_INTEGRATION_DATE', '2024-06-25' ); ! defined( 'CONNECT_WOO_URL' ) && define( 'CONNECT_WOO_URL', 'https://api.woocommerce.com/integrations/ppc' ); ! defined( 'CONNECT_WOO_SANDBOX_URL' ) && define( 'CONNECT_WOO_SANDBOX_URL', 'https://api.woocommerce.com/integrations/ppcsandbox' ); -! defined( 'PPCP_PAYPAL_BN_CODE' ) && define( 'PPCP_PAYPAL_BN_CODE', apply_filters( 'woocommerce_paypal_payments_bn_code', 'Woo_PPCP' ) ); +! defined( 'PPCP_PAYPAL_BN_CODE' ) && define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' ); ( function () { $autoload_filepath = __DIR__ . '/vendor/autoload.php'; From 0e2cf0c2197a8165c55c71077ed87fb870117501 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Fri, 12 Jul 2024 14:43:14 +0200 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Removed=20option?= =?UTF-8?q?=20to=20customize=20BN=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- woocommerce-paypal-payments.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 13402784f..66bf62645 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -27,6 +27,7 @@ define( 'PAYPAL_URL', 'https://www.paypal.com' ); define( 'PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com' ); define( 'PAYPAL_SANDBOX_URL', 'https://www.sandbox.paypal.com' ); define( 'PAYPAL_INTEGRATION_DATE', '2024-06-25' ); +define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' ); ! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' ); ! defined( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define( 'CONNECT_WOO_SANDBOX_CLIENT_ID', 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' ); @@ -35,8 +36,6 @@ define( 'PAYPAL_INTEGRATION_DATE', '2024-06-25' ); ! defined( 'CONNECT_WOO_URL' ) && define( 'CONNECT_WOO_URL', 'https://api.woocommerce.com/integrations/ppc' ); ! defined( 'CONNECT_WOO_SANDBOX_URL' ) && define( 'CONNECT_WOO_SANDBOX_URL', 'https://api.woocommerce.com/integrations/ppcsandbox' ); -! defined( 'PPCP_PAYPAL_BN_CODE' ) && define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' ); - ( function () { $autoload_filepath = __DIR__ . '/vendor/autoload.php'; if ( file_exists( $autoload_filepath ) && ! class_exists( '\WooCommerce\PayPalCommerce\PluginModule' ) ) { From 636b905ef06259091614e378fb0b982e9532172e Mon Sep 17 00:00:00 2001 From: George Burduli Date: Fri, 12 Jul 2024 17:07:34 +0400 Subject: [PATCH 10/12] Fix add to cart limits of non-subscription products --- .../src/PayPalSubscriptionsModule.php | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php b/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php index 27d6b2a1e..d1e63c4d0 100644 --- a/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php +++ b/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php @@ -107,36 +107,32 @@ class PayPalSubscriptionsModule implements ModuleInterface { return $passed_validation; } - $product = wc_get_product( $product_id ); - + $product = wc_get_product( $product_id ); $settings = $c->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - $subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : ''; + $subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : ''; + $is_paypal_subscription = static function ( $product ) use ( $subscriptions_mode ): bool { + return $product && + in_array( $product->get_type(), array( 'subscription', 'variable-subscription' ), true ) && + 'subscriptions_api' === $subscriptions_mode && + $product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes'; + }; - if ( 'subscriptions_api' !== $subscriptions_mode ) { - if ( $product && $product->get_sold_individually() ) { - $product->set_sold_individually( false ); - $product->save(); - } - - return $passed_validation; - } - - if ( $product && $product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes' ) { + if ( $is_paypal_subscription( $product ) ) { if ( ! $product->get_sold_individually() ) { $product->set_sold_individually( true ); $product->save(); } - wc_add_notice( __( 'You cannot add a subscription product to a cart with other items.', 'woocommerce-paypal-payments' ), 'error' ); + wc_add_notice( __( 'You cannot add a PayPal Subscription product to a cart with other items.', 'woocommerce-paypal-payments' ), 'error' ); return false; } - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { + foreach ( WC()->cart->get_cart() as $cart_item ) { $cart_product = wc_get_product( $cart_item['product_id'] ); - if ( $cart_product && $cart_product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes' ) { - wc_add_notice( __( 'You can only have one subscription product in your cart.', 'woocommerce-paypal-payments' ), 'error' ); + if ( $is_paypal_subscription( $cart_product ) ) { + wc_add_notice( __( 'You can only have one PayPal Subscription product in your cart.', 'woocommerce-paypal-payments' ), 'error' ); return false; } } From bd6115855f7d4864a4495afd8fe8834558112411 Mon Sep 17 00:00:00 2001 From: George Burduli Date: Fri, 12 Jul 2024 17:15:56 +0400 Subject: [PATCH 11/12] Add check for invalid product --- .../src/PayPalSubscriptionsModule.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php b/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php index d1e63c4d0..77cb8ae49 100644 --- a/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php +++ b/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php @@ -107,7 +107,13 @@ class PayPalSubscriptionsModule implements ModuleInterface { return $passed_validation; } - $product = wc_get_product( $product_id ); + $product = wc_get_product( $product_id ); + + if ( ! ( is_a( $product, WC_Product::class ) ) ) { + wc_add_notice( __( 'Cannot add this product to cart (invalid product).', 'woocommerce-paypal-payments' ), 'error' ); + return false; + } + $settings = $c->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); From 70e9e95a860019bf8945c816ccc50bf5a6e7a27f Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Mon, 15 Jul 2024 11:43:00 +0200 Subject: [PATCH 12/12] Remove singapore and hong kong for now --- modules/ppcp-api-client/services.php | 56 ---------------------------- 1 file changed, 56 deletions(-) diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php index 426c7f1e4..dbdf2efe3 100644 --- a/modules/ppcp-api-client/services.php +++ b/modules/ppcp-api-client/services.php @@ -939,30 +939,6 @@ return array( 'TWD', 'USD', ), - 'HK' => array( - 'AUD', - 'BRL', - 'CAD', - 'CHF', - 'CZK', - 'DKK', - 'EUR', - 'GBP', - 'HKD', - 'HUF', - 'ILS', - 'JPY', - 'MXN', - 'NOK', - 'NZD', - 'PHP', - 'PLN', - 'SEK', - 'SGD', - 'THB', - 'TWD', - 'USD', - ), 'HU' => array( 'AUD', 'BRL', @@ -1278,30 +1254,6 @@ return array( 'TWD', 'USD', ), - 'SG' => array( - 'AUD', - 'BRL', - 'CAD', - 'CHF', - 'CZK', - 'DKK', - 'EUR', - 'GBP', - 'HKD', - 'HUF', - 'ILS', - 'JPY', - 'MXN', - 'NOK', - 'NZD', - 'PHP', - 'PLN', - 'SEK', - 'SGD', - 'THB', - 'TWD', - 'USD', - ), 'SK' => array( 'AUD', 'BRL', @@ -1542,10 +1494,6 @@ return array( 'visa' => array(), 'amex' => array(), ), - 'HK' => array( - 'mastercard' => array(), - 'visa' => array(), - ), 'HU' => array( 'mastercard' => array(), 'visa' => array(), @@ -1633,10 +1581,6 @@ return array( 'visa' => array(), 'amex' => array(), ), - 'SG' => array( - 'mastercard' => array(), - 'visa' => array(), - ), 'SI' => array( 'mastercard' => array(), 'visa' => array(),