diff --git a/.ddev/config.yaml b/.ddev/config.yaml
index 7b1deb4b4..041455441 100644
--- a/.ddev/config.yaml
+++ b/.ddev/config.yaml
@@ -19,7 +19,7 @@ hooks:
pre-start:
- exec-host: "mkdir -p .ddev/wordpress/wp-content/plugins/${DDEV_PROJECT}"
web_environment:
- - WP_VERSION=6.3.3
+ - WP_VERSION=6.7.1
- WP_LOCALE=en_US
- WP_TITLE=WooCommerce PayPal Payments
- WP_MULTISITE=true
diff --git a/.psalm/stubs.php b/.psalm/stubs.php
index 59be5215c..56ba72451 100644
--- a/.psalm/stubs.php
+++ b/.psalm/stubs.php
@@ -1,71 +1,116 @@
function( ContainerInterface $container ) : string {
@@ -179,6 +179,22 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' )
);
},
+ 'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals {
+
+ return new PartnerReferrals(
+ CONNECT_WOO_SANDBOX_URL,
+ new ConnectBearer(),
+ $container->get( 'woocommerce.logger.woocommerce' )
+ );
+ },
+ 'api.endpoint.partner-referrals-production' => static function ( ContainerInterface $container ) : PartnerReferrals {
+
+ return new PartnerReferrals(
+ CONNECT_WOO_URL,
+ new ConnectBearer(),
+ $container->get( 'woocommerce.logger.woocommerce' )
+ );
+ },
'api.endpoint.identity-token' => static function ( ContainerInterface $container ) : IdentityToken {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$settings = $container->get( 'wcgateway.settings' );
@@ -572,6 +588,7 @@ return array(
'CZK',
'DKK',
'EUR',
+ 'HKD',
'HUF',
'ILS',
'JPY',
@@ -584,6 +601,7 @@ return array(
'PLN',
'GBP',
'RUB',
+ 'SGD',
'SEK',
'CHF',
'THB',
@@ -595,27 +613,32 @@ return array(
* The matrix which countries and currency combinations can be used for DCC.
*/
'api.dcc-supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
- $default_currencies = array(
- 'AUD',
- 'BRL',
- 'CAD',
- 'CHF',
- 'CZK',
- 'DKK',
- 'EUR',
- 'GBP',
- 'HUF',
- 'ILS',
- 'JPY',
- 'MXN',
- 'NOK',
- 'NZD',
- 'PHP',
- 'PLN',
- 'SEK',
- 'THB',
- 'TWD',
- 'USD',
+ $default_currencies = apply_filters(
+ 'woocommerce_paypal_payments_supported_currencies',
+ array(
+ 'AUD',
+ 'BRL',
+ 'CAD',
+ 'CHF',
+ 'CZK',
+ 'DKK',
+ 'EUR',
+ 'HKD',
+ 'GBP',
+ 'HUF',
+ 'ILS',
+ 'JPY',
+ 'MXN',
+ 'NOK',
+ 'NZD',
+ 'PHP',
+ 'PLN',
+ 'SGD',
+ 'SEK',
+ 'THB',
+ 'TWD',
+ 'USD',
+ )
);
/**
@@ -659,14 +682,7 @@ return array(
'ES' => $default_currencies,
'SE' => $default_currencies,
'GB' => $default_currencies,
- 'US' => array(
- 'AUD',
- 'CAD',
- 'EUR',
- 'GBP',
- 'JPY',
- 'USD',
- ),
+ 'US' => $default_currencies,
'NO' => $default_currencies,
)
);
@@ -845,4 +861,22 @@ return array(
$container->get( 'api.client-credentials-cache' )
);
},
+ 'api.paypal-host-production' => static function( ContainerInterface $container ) : string {
+ return PAYPAL_API_URL;
+ },
+ 'api.paypal-host-sandbox' => static function( ContainerInterface $container ) : string {
+ return PAYPAL_SANDBOX_API_URL;
+ },
+ 'api.paypal-website-url-production' => static function( ContainerInterface $container ) : string {
+ return PAYPAL_URL;
+ },
+ 'api.paypal-website-url-sandbox' => static function( ContainerInterface $container ) : string {
+ return PAYPAL_SANDBOX_URL;
+ },
+ 'api.partner_merchant_id-production' => static function( ContainerInterface $container ) : string {
+ return CONNECT_WOO_MERCHANT_ID;
+ },
+ 'api.partner_merchant_id-sandbox' => static function( ContainerInterface $container ) : string {
+ return CONNECT_WOO_SANDBOX_MERCHANT_ID;
+ },
);
diff --git a/modules/ppcp-api-client/src/Authentication/PayPalBearer.php b/modules/ppcp-api-client/src/Authentication/PayPalBearer.php
index f5cab579b..7f176c218 100644
--- a/modules/ppcp-api-client/src/Authentication/PayPalBearer.php
+++ b/modules/ppcp-api-client/src/Authentication/PayPalBearer.php
@@ -5,7 +5,7 @@
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
*/
-declare(strict_types=1);
+declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
@@ -28,7 +28,7 @@ class PayPalBearer implements Bearer {
/**
* The settings.
*
- * @var ContainerInterface
+ * @var ?ContainerInterface
*/
protected $settings;
@@ -70,12 +70,12 @@ class PayPalBearer implements Bearer {
/**
* PayPalBearer constructor.
*
- * @param Cache $cache The cache.
- * @param string $host The host.
- * @param string $key The key.
- * @param string $secret The secret.
- * @param LoggerInterface $logger The logger.
- * @param ContainerInterface $settings The settings.
+ * @param Cache $cache The cache.
+ * @param string $host The host.
+ * @param string $key The key.
+ * @param string $secret The secret.
+ * @param LoggerInterface $logger The logger.
+ * @param ?ContainerInterface $settings The settings.
*/
public function __construct(
Cache $cache,
@@ -83,7 +83,7 @@ class PayPalBearer implements Bearer {
string $key,
string $secret,
LoggerInterface $logger,
- ContainerInterface $settings
+ ?ContainerInterface $settings
) {
$this->cache = $cache;
@@ -97,27 +97,62 @@ class PayPalBearer implements Bearer {
/**
* Returns a bearer token.
*
- * @return Token
* @throws RuntimeException When request fails.
+ * @return Token
*/
- public function bearer(): Token {
+ public function bearer() : Token {
try {
$bearer = Token::from_json( (string) $this->cache->get( self::CACHE_KEY ) );
+
return ( $bearer->is_valid() ) ? $bearer : $this->newBearer();
} catch ( RuntimeException $error ) {
return $this->newBearer();
}
}
+ /**
+ * Retrieves the client key for authentication.
+ *
+ * @return string The client ID from settings, or the key defined via constructor.
+ */
+ private function get_key() : string {
+ if (
+ $this->settings
+ && $this->settings->has( 'client_id' )
+ && $this->settings->get( 'client_id' )
+ ) {
+ return $this->settings->get( 'client_id' );
+ }
+
+ return $this->key;
+ }
+
+ /**
+ * Retrieves the client secret for authentication.
+ *
+ * @return string The client secret from settings, or the value defined via constructor.
+ */
+ private function get_secret() : string {
+ if (
+ $this->settings
+ && $this->settings->has( 'client_secret' )
+ && $this->settings->get( 'client_secret' )
+ ) {
+ return $this->settings->get( 'client_secret' );
+ }
+
+ return $this->secret;
+ }
+
/**
* Creates a new bearer token.
*
- * @return Token
* @throws RuntimeException When request fails.
+ * @return Token
*/
- private function newBearer(): Token {
- $key = $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' ) ? $this->settings->get( 'client_id' ) : $this->key;
- $secret = $this->settings->has( 'client_secret' ) && $this->settings->get( 'client_secret' ) ? $this->settings->get( 'client_secret' ) : $this->secret;
+ private function newBearer() : Token {
+ $key = $this->get_key();
+ $secret = $this->get_secret();
$url = trailingslashit( $this->host ) . 'v1/oauth2/token?grant_type=client_credentials';
$args = array(
@@ -127,10 +162,7 @@ class PayPalBearer implements Bearer {
'Authorization' => 'Basic ' . base64_encode( $key . ':' . $secret ),
),
);
- $response = $this->request(
- $url,
- $args
- );
+ $response = $this->request( $url, $args );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
$error = new RuntimeException(
@@ -148,6 +180,7 @@ class PayPalBearer implements Bearer {
$token = Token::from_json( $response['body'] );
$this->cache->set( self::CACHE_KEY, $token->as_json() );
+
return $token;
}
}
diff --git a/modules/ppcp-api-client/src/Endpoint/PartnerReferrals.php b/modules/ppcp-api-client/src/Endpoint/PartnerReferrals.php
index 0f188f025..c7f5ec131 100644
--- a/modules/ppcp-api-client/src/Endpoint/PartnerReferrals.php
+++ b/modules/ppcp-api-client/src/Endpoint/PartnerReferrals.php
@@ -85,8 +85,7 @@ class PartnerReferrals {
$error = new RuntimeException(
__( 'Could not create referral.', 'woocommerce-paypal-payments' )
);
- $this->logger->log(
- 'warning',
+ $this->logger->warning(
$error->getMessage(),
array(
'args' => $args,
@@ -95,6 +94,7 @@ class PartnerReferrals {
);
throw $error;
}
+
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( 201 !== $status_code ) {
@@ -102,8 +102,7 @@ class PartnerReferrals {
$json,
$status_code
);
- $this->logger->log(
- 'warning',
+ $this->logger->warning(
$error->getMessage(),
array(
'args' => $args,
@@ -122,8 +121,7 @@ class PartnerReferrals {
$error = new RuntimeException(
__( 'Action URL not found.', 'woocommerce-paypal-payments' )
);
- $this->logger->log(
- 'warning',
+ $this->logger->warning(
$error->getMessage(),
array(
'args' => $args,
diff --git a/modules/ppcp-api-client/src/Endpoint/PaymentMethodTokensEndpoint.php b/modules/ppcp-api-client/src/Endpoint/PaymentMethodTokensEndpoint.php
index 538ca224d..e2c2a91e8 100644
--- a/modules/ppcp-api-client/src/Endpoint/PaymentMethodTokensEndpoint.php
+++ b/modules/ppcp-api-client/src/Endpoint/PaymentMethodTokensEndpoint.php
@@ -61,19 +61,24 @@ class PaymentMethodTokensEndpoint {
* Creates a setup token.
*
* @param PaymentSource $payment_source The payment source.
+ * @param string $customer_id PayPal customer ID.
*
* @return stdClass
*
* @throws RuntimeException When something when wrong with the request.
* @throws PayPalApiException When something when wrong setting up the token.
*/
- public function setup_tokens( PaymentSource $payment_source ): stdClass {
+ public function setup_tokens( PaymentSource $payment_source, string $customer_id = '' ): stdClass {
$data = array(
'payment_source' => array(
$payment_source->name() => $payment_source->properties(),
),
);
+ if ( $customer_id ) {
+ $data['customer']['id'] = $customer_id;
+ }
+
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v3/vault/setup-tokens';
@@ -109,19 +114,24 @@ class PaymentMethodTokensEndpoint {
* Creates a payment token for the given payment source.
*
* @param PaymentSource $payment_source The payment source.
+ * @param string $customer_id PayPal customer ID.
*
* @return stdClass
*
* @throws RuntimeException When something when wrong with the request.
* @throws PayPalApiException When something when wrong setting up the token.
*/
- public function create_payment_token( PaymentSource $payment_source ): stdClass {
+ public function create_payment_token( PaymentSource $payment_source, string $customer_id = '' ): stdClass {
$data = array(
'payment_source' => array(
$payment_source->name() => $payment_source->properties(),
),
);
+ if ( $customer_id ) {
+ $data['customer']['id'] = $customer_id;
+ }
+
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v3/vault/payment-tokens';
diff --git a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php
index 7642401b1..84231f8d8 100644
--- a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php
+++ b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php
@@ -127,7 +127,7 @@ class PurchaseUnitFactory {
$description = '';
$custom_id = (string) $order->get_id();
$invoice_id = $this->prefix . $order->get_order_number();
- $soft_descriptor = $this->soft_descriptor;
+ $soft_descriptor = $this->sanitize_soft_descriptor( $this->soft_descriptor );
$purchase_unit = new PurchaseUnit(
$amount,
@@ -197,7 +197,7 @@ class PurchaseUnitFactory {
}
}
$invoice_id = '';
- $soft_descriptor = $this->soft_descriptor;
+ $soft_descriptor = $this->sanitize_soft_descriptor( $this->soft_descriptor );
$purchase_unit = new PurchaseUnit(
$amount,
$items,
@@ -233,7 +233,7 @@ class PurchaseUnitFactory {
$description = ( isset( $data->description ) ) ? $data->description : '';
$custom_id = ( isset( $data->custom_id ) ) ? $data->custom_id : '';
$invoice_id = ( isset( $data->invoice_id ) ) ? $data->invoice_id : '';
- $soft_descriptor = ( isset( $data->soft_descriptor ) ) ? $data->soft_descriptor : $this->soft_descriptor;
+ $soft_descriptor = $this->sanitize_soft_descriptor( $data->soft_descriptor ?? $this->soft_descriptor );
$items = array();
if ( isset( $data->items ) && is_array( $data->items ) ) {
$items = array_map(
@@ -316,4 +316,22 @@ class PurchaseUnitFactory {
$purchase_unit->set_sanitizer( $this->sanitizer );
}
}
+
+ /**
+ * Sanitizes a soft descriptor, ensuring it is limited to 22 chars.
+ *
+ * The soft descriptor in the DB is escaped using `wp_kses_post()` which
+ * escapes certain characters via `wp_kses_normalize_entities()`. This
+ * helper method reverts those normalized entities back to UTF characters.
+ *
+ * @param string $soft_descriptor Soft descriptor to sanitize.
+ *
+ * @return string The sanitized soft descriptor.
+ */
+ private function sanitize_soft_descriptor( string $soft_descriptor ) : string {
+ $decoded = html_entity_decode( $soft_descriptor, ENT_QUOTES, 'UTF-8' );
+ $sanitized = preg_replace( '/[^a-zA-Z0-9 *\-.]/', '', $decoded ) ?: '';
+
+ return substr( $sanitized, 0, 22 ) ?: '';
+ }
}
diff --git a/modules/ppcp-axo-block/resources/js/plugins/PayPalInsightsLoader.js b/modules/ppcp-axo-block/resources/js/plugins/PayPalInsightsLoader.js
index b831bd45b..ccd7da7ad 100644
--- a/modules/ppcp-axo-block/resources/js/plugins/PayPalInsightsLoader.js
+++ b/modules/ppcp-axo-block/resources/js/plugins/PayPalInsightsLoader.js
@@ -1,7 +1,6 @@
import { registerPlugin } from '@wordpress/plugins';
import { useEffect, useCallback, useState, useRef } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
-import { PAYMENT_STORE_KEY } from '@woocommerce/block-data';
import PayPalInsights from '../../../../ppcp-axo/resources/js/Insights/PayPalInsights';
import { STORE_NAME } from '../stores/axoStore';
import usePayPalCommerceGateway from '../hooks/usePayPalCommerceGateway';
@@ -149,6 +148,7 @@ const usePaymentMethodTracking = ( axoConfig, eventTracking ) => {
const isInitialMount = useRef( true );
const activePaymentMethod = useSelect( ( select ) => {
+ const { PAYMENT_STORE_KEY } = window.wc.wcBlocksData;
return select( PAYMENT_STORE_KEY )?.getActivePaymentMethod();
}, [] );
diff --git a/modules/ppcp-axo-block/services.php b/modules/ppcp-axo-block/services.php
index f91cd738a..6945215ba 100644
--- a/modules/ppcp-axo-block/services.php
+++ b/modules/ppcp-axo-block/services.php
@@ -39,8 +39,7 @@ return array(
$container->get( 'onboarding.environment' ),
$container->get( 'wcgateway.url' ),
$container->get( 'axo.payment_method_selected_map' ),
- $container->get( 'axo.supported-country-card-type-matrix' ),
- $container->get( 'axo.shipping-wc-enabled-locations' )
+ $container->get( 'axo.supported-country-card-type-matrix' )
);
},
);
diff --git a/modules/ppcp-axo-block/src/AxoBlockModule.php b/modules/ppcp-axo-block/src/AxoBlockModule.php
index 1ebb068ed..c8216bf62 100644
--- a/modules/ppcp-axo-block/src/AxoBlockModule.php
+++ b/modules/ppcp-axo-block/src/AxoBlockModule.php
@@ -22,6 +22,7 @@ use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
/**
* Class AxoBlockModule
@@ -134,7 +135,6 @@ class AxoBlockModule implements ServiceModule, ExtendingModule, ExecutableModule
}
);
- // Enqueue the PayPal Insights script.
add_action(
'wp_enqueue_scripts',
function () use ( $c ) {
@@ -187,6 +187,11 @@ class AxoBlockModule implements ServiceModule, ExtendingModule, ExecutableModule
return;
}
+ $dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
+ if ( ! $dcc_configuration->use_fastlane() ) {
+ return;
+ }
+
$module_url = $c->get( 'axoblock.url' );
$asset_version = $c->get( 'ppcp.asset-version' );
diff --git a/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php b/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php
index fa546d5ac..78bafdae3 100644
--- a/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php
+++ b/modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php
@@ -93,13 +93,6 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
*/
private $supported_country_card_type_matrix;
- /**
- * The list of WooCommerce enabled shipping locations.
- *
- * @var array
- */
- private array $enabled_shipping_locations;
-
/**
* AdvancedCardPaymentMethod constructor.
*
@@ -113,7 +106,6 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
* @param string $wcgateway_module_url The WcGateway module URL.
* @param array $payment_method_selected_map Mapping of payment methods to the PayPal Insights 'payment_method_selected' types.
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
- * @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
*/
public function __construct(
string $module_url,
@@ -125,8 +117,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
Environment $environment,
string $wcgateway_module_url,
array $payment_method_selected_map,
- array $supported_country_card_type_matrix,
- array $enabled_shipping_locations
+ array $supported_country_card_type_matrix
) {
$this->name = AxoGateway::ID;
$this->module_url = $module_url;
@@ -139,7 +130,6 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
$this->wcgateway_module_url = $wcgateway_module_url;
$this->payment_method_selected_map = $payment_method_selected_map;
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
- $this->enabled_shipping_locations = $enabled_shipping_locations;
}
/**
* {@inheritDoc}
@@ -237,7 +227,7 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
),
'allowed_cards' => $this->supported_country_card_type_matrix,
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
- 'enabled_shipping_locations' => $this->enabled_shipping_locations,
+ 'enabled_shipping_locations' => apply_filters( 'woocommerce_paypal_payments_axo_shipping_wc_enabled_locations', array() ),
'style_options' => array(
'root' => array(
'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '',
diff --git a/modules/ppcp-axo/services.php b/modules/ppcp-axo/services.php
index e6767a29a..121b17805 100644
--- a/modules/ppcp-axo/services.php
+++ b/modules/ppcp-axo/services.php
@@ -70,8 +70,7 @@ return array(
$container->get( 'api.shop.currency.getter' ),
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.url' ),
- $container->get( 'axo.supported-country-card-type-matrix' ),
- $container->get( 'axo.shipping-wc-enabled-locations' )
+ $container->get( 'axo.supported-country-card-type-matrix' )
);
},
@@ -329,33 +328,23 @@ return array(
);
},
- 'axo.shipping-wc-enabled-locations' => static function ( ContainerInterface $container ): array {
+ 'axo.shipping-wc-enabled-locations' => static function ( ContainerInterface $container ) {
$default_zone = new \WC_Shipping_Zone( 0 );
- $is_method_enabled = fn( \WC_Shipping_Method $method): bool => $method->enabled === 'yes';
-
- $is_default_zone_enabled = ! empty(
- array_filter(
- $default_zone->get_shipping_methods(),
- $is_method_enabled
- )
- );
-
- if ( $is_default_zone_enabled ) {
+ if ( ! empty( $default_zone->get_shipping_methods( true ) ) ) {
return array();
}
$shipping_zones = \WC_Shipping_Zones::get_zones();
-
$get_zone_locations = fn( \WC_Shipping_Zone $zone): array =>
- ! empty( array_filter( $zone->get_shipping_methods(), $is_method_enabled ) )
+ ! empty( $zone->get_shipping_methods( true ) )
? array_map(
fn( object $location): string => $location->code,
$zone->get_zone_locations()
)
: array();
- $enabled_locations = array_unique(
+ return array_unique(
array_merge(
...array_map(
$get_zone_locations,
@@ -367,7 +356,5 @@ return array(
)
)
);
-
- return $enabled_locations;
},
);
diff --git a/modules/ppcp-axo/src/Assets/AxoManager.php b/modules/ppcp-axo/src/Assets/AxoManager.php
index 6fafcb681..d02e27355 100644
--- a/modules/ppcp-axo/src/Assets/AxoManager.php
+++ b/modules/ppcp-axo/src/Assets/AxoManager.php
@@ -99,12 +99,6 @@ class AxoManager {
* @var array
*/
private array $supported_country_card_type_matrix;
- /**
- * The list of WooCommerce enabled shipping locations.
- *
- * @var array
- */
- private array $enabled_shipping_locations;
/**
* AxoManager constructor.
@@ -120,7 +114,6 @@ class AxoManager {
* @param LoggerInterface $logger The logger.
* @param string $wcgateway_module_url The WcGateway module URL.
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
- * @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
*/
public function __construct(
string $module_url,
@@ -133,8 +126,7 @@ class AxoManager {
CurrencyGetter $currency,
LoggerInterface $logger,
string $wcgateway_module_url,
- array $supported_country_card_type_matrix,
- array $enabled_shipping_locations
+ array $supported_country_card_type_matrix
) {
$this->module_url = $module_url;
@@ -147,7 +139,6 @@ class AxoManager {
$this->currency = $currency;
$this->logger = $logger;
$this->wcgateway_module_url = $wcgateway_module_url;
- $this->enabled_shipping_locations = $enabled_shipping_locations;
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
}
@@ -203,7 +194,7 @@ class AxoManager {
return $data; } )( $this->insights_data ),
'allowed_cards' => $this->supported_country_card_type_matrix,
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
- 'enabled_shipping_locations' => $this->enabled_shipping_locations,
+ 'enabled_shipping_locations' => apply_filters( 'woocommerce_paypal_payments_axo_shipping_wc_enabled_locations', array() ),
'style_options' => array(
'root' => array(
'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '',
diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php
index b055697ba..3ac0ff157 100644
--- a/modules/ppcp-axo/src/AxoModule.php
+++ b/modules/ppcp-axo/src/AxoModule.php
@@ -229,6 +229,16 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
}
);
+ /**
+ * Late loading locations because of trouble with some shipping plugins
+ */
+ add_filter(
+ 'woocommerce_paypal_payments_axo_shipping_wc_enabled_locations',
+ function ( array $locations ) use ( $c ): array {
+ return array_merge( $locations, $c->get( 'axo.shipping-wc-enabled-locations' ) );
+ }
+ );
+
/**
* Param types removed to avoid third-party issues.
*
diff --git a/modules/ppcp-blocks/src/BlocksModule.php b/modules/ppcp-blocks/src/BlocksModule.php
index c5a2b29c5..28dbf5a04 100644
--- a/modules/ppcp-blocks/src/BlocksModule.php
+++ b/modules/ppcp-blocks/src/BlocksModule.php
@@ -143,10 +143,15 @@ class BlocksModule implements ServiceModule, ExtendingModule, ExecutableModule {
add_filter(
'woocommerce_paypal_payments_sdk_components_hook',
- function( array $components ) {
- $components[] = 'buttons';
+ function( array $components, string $context ) {
+ if ( str_ends_with( $context, '-block' ) ) {
+ $components[] = 'buttons';
+ }
+
return $components;
- }
+ },
+ 10,
+ 2
);
return true;
}
diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js
index 505fa60af..a4e094830 100644
--- a/modules/ppcp-button/resources/js/button.js
+++ b/modules/ppcp-button/resources/js/button.js
@@ -324,6 +324,10 @@ const bootstrap = () => {
messagesBootstrap.init();
apmButtonsInit( PayPalCommerceGateway );
+
+ if ( ! renderer.useSmartButtons ) {
+ buttonsSpinner.unblock();
+ }
};
document.addEventListener( 'DOMContentLoaded', () => {
diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js
index a85ad68ee..d314553bc 100644
--- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js
+++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js
@@ -211,6 +211,7 @@ class CheckoutBootstap {
const isFreeTrial = PayPalCommerceGateway.is_free_trial_cart;
const hasVaultedPaypal =
PayPalCommerceGateway.vaulted_paypal_email !== '';
+ const useSmartButtons = this.renderer.useSmartButtons ?? true;
const paypalButtonWrappers = {
...Object.entries( PayPalCommerceGateway.separate_buttons ).reduce(
@@ -225,7 +226,8 @@ class CheckoutBootstap {
this.standardOrderButtonSelector,
( isPaypal && isFreeTrial && hasVaultedPaypal ) ||
isNotOurGateway ||
- isSavedCard,
+ isSavedCard ||
+ ( isPaypal && ! useSmartButtons ),
'ppcp-hidden'
);
setVisible( '.ppcp-vaulted-paypal-details', isPaypal );
diff --git a/modules/ppcp-button/resources/js/modules/Helper/ConfigProcessor.js b/modules/ppcp-button/resources/js/modules/Helper/ConfigProcessor.js
index b70403a50..b8736d0e1 100644
--- a/modules/ppcp-button/resources/js/modules/Helper/ConfigProcessor.js
+++ b/modules/ppcp-button/resources/js/modules/Helper/ConfigProcessor.js
@@ -6,16 +6,16 @@ const processAxoConfig = ( config ) => {
const scriptOptions = {};
const sdkClientToken = config?.axo?.sdk_client_token;
const uuid = uuidv4().replace( /-/g, '' );
- if ( sdkClientToken ) {
+ if ( sdkClientToken && config?.user?.is_logged !== true ) {
scriptOptions[ 'data-sdk-client-token' ] = sdkClientToken;
scriptOptions[ 'data-client-metadata-id' ] = uuid;
}
return scriptOptions;
};
-const processUserIdToken = ( config, sdkClientToken ) => {
+const processUserIdToken = ( config ) => {
const userIdToken = config?.save_payment_methods?.id_token;
- return userIdToken && ! sdkClientToken
+ return userIdToken && config?.user?.is_logged === true
? { 'data-user-id-token': userIdToken }
: {};
};
@@ -26,9 +26,6 @@ export const processConfig = ( config ) => {
scriptOptions = merge( scriptOptions, config.script_attributes );
}
const axoOptions = processAxoConfig( config );
- const userIdTokenOptions = processUserIdToken(
- config,
- axoOptions[ 'data-sdk-client-token' ]
- );
+ const userIdTokenOptions = processUserIdToken( config );
return merge.all( [ scriptOptions, axoOptions, userIdTokenOptions ] );
};
diff --git a/modules/ppcp-button/resources/js/modules/Helper/PayPalScriptLoading.js b/modules/ppcp-button/resources/js/modules/Helper/PayPalScriptLoading.js
index 2fd5feaa3..48134d2bc 100644
--- a/modules/ppcp-button/resources/js/modules/Helper/PayPalScriptLoading.js
+++ b/modules/ppcp-button/resources/js/modules/Helper/PayPalScriptLoading.js
@@ -9,7 +9,7 @@ const scriptPromises = new Map();
const handleDataClientIdAttribute = async ( scriptOptions, config ) => {
if (
config.data_client_id?.set_attribute &&
- config.vault_v3_enabled !== '1'
+ config.vault_v3_enabled !== true
) {
return new Promise( ( resolve, reject ) => {
dataClientIdAttributeHandler(
diff --git a/modules/ppcp-button/resources/js/modules/Helper/ScriptLoading.js b/modules/ppcp-button/resources/js/modules/Helper/ScriptLoading.js
index 38f605cc7..00ae98a9c 100644
--- a/modules/ppcp-button/resources/js/modules/Helper/ScriptLoading.js
+++ b/modules/ppcp-button/resources/js/modules/Helper/ScriptLoading.js
@@ -75,7 +75,7 @@ export const loadPaypalScript = ( config, onLoaded, onError = null ) => {
// Axo SDK options
const sdkClientToken = config?.axo?.sdk_client_token;
const uuid = uuidv4().replace( /-/g, '' );
- if ( sdkClientToken ) {
+ if ( sdkClientToken && config?.user?.is_logged !== true ) {
scriptOptions[ 'data-sdk-client-token' ] = sdkClientToken;
scriptOptions[ 'data-client-metadata-id' ] = uuid;
}
@@ -96,7 +96,7 @@ export const loadPaypalScript = ( config, onLoaded, onError = null ) => {
// Adds data-user-id-token to script options.
const userIdToken = config?.save_payment_methods?.id_token;
- if ( userIdToken && ! sdkClientToken ) {
+ if ( userIdToken && config?.user?.is_logged === true ) {
scriptOptions[ 'data-user-id-token' ] = userIdToken;
}
diff --git a/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js b/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js
index 9fa4708bc..005ee6248 100644
--- a/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js
+++ b/modules/ppcp-button/resources/js/modules/Renderer/Renderer.js
@@ -7,6 +7,7 @@ import {
handleShippingOptionsChange,
handleShippingAddressChange,
} from '../Helper/ShippingHandler.js';
+import { PaymentContext } from '../Helper/CheckoutMethodState';
class Renderer {
constructor(
@@ -28,6 +29,22 @@ class Renderer {
this.reloadEventName = 'ppcp-reload-buttons';
}
+ /**
+ * Determine is PayPal smart buttons are used by inspecting the existing plugin configuration:
+ * If the url-param "components" contains a "buttons" element, smart buttons are enabled.
+ *
+ * @return {boolean} True, if smart buttons are present on the page.
+ */
+ get useSmartButtons() {
+ if ( PaymentContext.Preview === this.defaultSettings?.context ) {
+ return true;
+ }
+
+ const components = this.defaultSettings?.url_params?.components || '';
+
+ return components.split( ',' ).includes( 'buttons' );
+ }
+
render(
contextConfig,
settingsOverride = {},
@@ -44,12 +61,14 @@ class Renderer {
Object.keys( enabledSeparateGateways ).length !== 0;
if ( ! hasEnabledSeparateGateways ) {
- this.renderButtons(
- settings.button.wrapper,
- settings.button.style,
- contextConfig,
- hasEnabledSeparateGateways
- );
+ if ( this.useSmartButtons ) {
+ this.renderButtons(
+ settings.button.wrapper,
+ settings.button.style,
+ contextConfig,
+ hasEnabledSeparateGateways
+ );
+ }
} else {
// render each button separately
for ( const fundingSource of paypal
@@ -141,7 +160,7 @@ class Renderer {
// Check the condition and add the handler if needed
if ( this.shouldEnableShippingCallback() ) {
options.onShippingOptionsChange = ( data, actions ) => {
- let shippingOptionsChange =
+ const shippingOptionsChange =
! this.isVenmoButtonClickedWhenVaultingIsEnabled(
venmoButtonClicked
)
@@ -152,10 +171,10 @@ class Renderer {
)
: null;
- return shippingOptionsChange
+ return shippingOptionsChange;
};
options.onShippingAddressChange = ( data, actions ) => {
- let shippingAddressChange =
+ const shippingAddressChange =
! this.isVenmoButtonClickedWhenVaultingIsEnabled(
venmoButtonClicked
)
@@ -166,7 +185,7 @@ class Renderer {
)
: null;
- return shippingAddressChange
+ return shippingAddressChange;
};
}
@@ -228,8 +247,13 @@ class Renderer {
};
shouldEnableShippingCallback = () => {
- let needShipping = this.defaultSettings.needShipping || this.defaultSettings.context === 'product'
- return this.defaultSettings.should_handle_shipping_in_paypal && needShipping
+ const needShipping =
+ this.defaultSettings.needShipping ||
+ this.defaultSettings.context === 'product';
+ return (
+ this.defaultSettings.should_handle_shipping_in_paypal &&
+ needShipping
+ );
};
isAlreadyRendered( wrapper, fundingSource ) {
diff --git a/modules/ppcp-button/services.php b/modules/ppcp-button/services.php
index 5cd0c85e1..6844a08d0 100644
--- a/modules/ppcp-button/services.php
+++ b/modules/ppcp-button/services.php
@@ -38,6 +38,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
+use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
return array(
'button.client_id' => static function ( ContainerInterface $container ): string {
@@ -108,9 +109,18 @@ return array(
assert( $settings_status instanceof SettingsStatus );
if ( in_array( $context, array( 'checkout', 'pay-now' ), true ) ) {
- if ( $container->get( 'wcgateway.use-place-order-button' )
- || ! $settings_status->is_smart_button_enabled_for_location( $context )
- ) {
+ $redirect_to_pay = $container->get( 'wcgateway.use-place-order-button' );
+ if ( $redirect_to_pay ) {
+ // No smart buttons, redirect the current page to PayPal for payment.
+ return new DisabledSmartButton();
+ }
+
+ $no_smart_buttons = ! $settings_status->is_smart_button_enabled_for_location( $context );
+ $dcc_configuration = $container->get( 'wcgateway.configuration.dcc' );
+ assert( $dcc_configuration instanceof DCCGatewayConfiguration );
+
+ if ( $no_smart_buttons && ! $dcc_configuration->is_enabled() ) {
+ // Smart buttons disabled, and also not using advanced card payments.
return new DisabledSmartButton();
}
}
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index c116796b9..a08c20b27 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -1594,9 +1594,16 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
*
* @internal Matches filter name in APM extension.
*
- * @param array $components The array of components already registered.
+ * @param array $components The array of components already registered.
+ * @param string $context The SmartButton context.
*/
- return apply_filters( 'woocommerce_paypal_payments_sdk_components_hook', $components );
+ return array_unique(
+ (array) apply_filters(
+ 'woocommerce_paypal_payments_sdk_components_hook',
+ $components,
+ $this->context()
+ )
+ );
}
/**
diff --git a/modules/ppcp-card-fields/src/CardFieldsModule.php b/modules/ppcp-card-fields/src/CardFieldsModule.php
index bb8e055a8..f87655f72 100644
--- a/modules/ppcp-card-fields/src/CardFieldsModule.php
+++ b/modules/ppcp-card-fields/src/CardFieldsModule.php
@@ -46,12 +46,6 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
return true;
}
- $dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
- assert( $dcc_configuration instanceof DCCGatewayConfiguration );
- if ( ! $dcc_configuration->is_enabled() ) {
- return true;
- }
-
/**
* Param types removed to avoid third-party issues.
*
@@ -59,7 +53,10 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
*/
add_filter(
'woocommerce_paypal_payments_sdk_components_hook',
- function( $components ) {
+ function( $components ) use ( $c ) {
+ if ( ! $c->get( 'wcgateway.configuration.dcc' )->is_enabled() ) {
+ return $components;
+ }
if ( in_array( 'hosted-fields', $components, true ) ) {
$key = array_search( 'hosted-fields', $components, true );
if ( $key !== false ) {
@@ -80,7 +77,10 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
* @psalm-suppress MissingClosureReturnType
* @psalm-suppress MissingClosureParamType
*/
- function( $default_fields, $id ) {
+ function( $default_fields, $id ) use ( $c ) {
+ if ( ! $c->get( 'wcgateway.configuration.dcc' )->is_enabled() ) {
+ return $default_fields;
+ }
if ( CreditCardGateway::ID === $id && apply_filters( 'woocommerce_paypal_payments_enable_cardholder_name_field', false ) ) {
$default_fields['card-name-field'] = '
@@ -113,6 +113,9 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
add_filter(
'ppcp_create_order_request_body_data',
function( array $data, string $payment_method ) use ( $c ): array {
+ if ( ! $c->get( 'wcgateway.configuration.dcc' )->is_enabled() ) {
+ return $data;
+ }
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( $payment_method !== CreditCardGateway::ID ) {
return $data;
diff --git a/modules/ppcp-compat/services.php b/modules/ppcp-compat/services.php
index b6abcea56..07a6da27f 100644
--- a/modules/ppcp-compat/services.php
+++ b/modules/ppcp-compat/services.php
@@ -115,4 +115,43 @@ return array(
$container->get( 'api.bearer' )
);
},
+
+ /**
+ * Configuration for the new/old settings map.
+ *
+ * @returns SettingsMap[]
+ */
+ 'compat.setting.new-to-old-map' => function( ContainerInterface $container ) : array {
+ $are_new_settings_enabled = $container->get( 'wcgateway.settings.admin-settings-enabled' );
+ if ( ! $are_new_settings_enabled ) {
+ return array();
+ }
+
+ return array(
+ new SettingsMap(
+ $container->get( 'settings.data.common' ),
+ array(
+ 'client_id' => 'client_id',
+ 'client_secret' => 'client_secret',
+ )
+ ),
+ new SettingsMap(
+ $container->get( 'settings.data.general' ),
+ array(
+ 'is_sandbox' => 'sandbox_on',
+ 'live_client_id' => 'client_id_production',
+ 'live_client_secret' => 'client_secret_production',
+ 'live_merchant_id' => 'merchant_id_production',
+ 'live_merchant_email' => 'merchant_email_production',
+ 'sandbox_client_id' => 'client_id_sandbox',
+ 'sandbox_client_secret' => 'client_secret_sandbox',
+ 'sandbox_merchant_id' => 'merchant_id_sandbox',
+ 'sandbox_merchant_email' => 'merchant_email_sandbox',
+ )
+ ),
+ );
+ },
+ 'compat.settings.settings_map_helper' => static function( ContainerInterface $container ) : SettingsMapHelper {
+ return new SettingsMapHelper( $container->get( 'compat.setting.new-to-old-map' ) );
+ },
);
diff --git a/modules/ppcp-compat/src/CompatModule.php b/modules/ppcp-compat/src/CompatModule.php
index 94a4d0d61..d52e13454 100644
--- a/modules/ppcp-compat/src/CompatModule.php
+++ b/modules/ppcp-compat/src/CompatModule.php
@@ -51,14 +51,24 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
*/
public function run( ContainerInterface $c ): bool {
- $this->initialize_ppec_compat_layer( $c );
- $this->initialize_tracking_compat_layer( $c );
+ add_action(
+ 'woocommerce_init',
+ function() use ( $c ) {
+ $this->initialize_ppec_compat_layer( $c );
+ $this->initialize_tracking_compat_layer( $c );
+ }
+ );
- $asset_loader = $c->get( 'compat.assets' );
- assert( $asset_loader instanceof CompatAssets );
+ add_action(
+ 'init',
+ function() use ( $c ) {
+ $asset_loader = $c->get( 'compat.assets' );
+ assert( $asset_loader instanceof CompatAssets );
- add_action( 'init', array( $asset_loader, 'register' ) );
- add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
+ $asset_loader->register();
+ add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
+ }
+ );
$this->migrate_pay_later_settings( $c );
$this->migrate_smart_button_settings( $c );
@@ -72,11 +82,9 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
$this->initialize_nyp_compat_layer();
}
- $logger = $c->get( 'woocommerce.logger.woocommerce' );
-
$is_wc_bookings_active = $c->get( 'compat.wc_bookings.is_supported_plugin_version_active' );
if ( $is_wc_bookings_active ) {
- $this->initialize_wc_bookings_compat_layer( $logger );
+ $this->initialize_wc_bookings_compat_layer( $c );
}
return true;
@@ -427,13 +435,13 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
/**
* Sets up the compatibility layer for WooCommerce Bookings plugin.
*
- * @param LoggerInterface $logger The logger.
+ * @param ContainerInterface $container The logger.
* @return void
*/
- protected function initialize_wc_bookings_compat_layer( LoggerInterface $logger ): void {
+ protected function initialize_wc_bookings_compat_layer( ContainerInterface $container ): void {
add_action(
'woocommerce_paypal_payments_shipping_callback_woocommerce_order_created',
- static function ( WC_Order $wc_order, WC_Cart $wc_cart ) use ( $logger ): void {
+ static function ( WC_Order $wc_order, WC_Cart $wc_cart ) use ( $container ): void {
try {
$cart_contents = $wc_cart->get_cart();
foreach ( $cart_contents as $cart_item ) {
@@ -474,7 +482,7 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule {
}
}
} catch ( Exception $exception ) {
- $logger->warning( 'Failed to create booking for WooCommerce Bookings plugin: ' . $exception->getMessage() );
+ $container->get( 'woocommerce.logger.woocommerce' )->warning( 'Failed to create booking for WooCommerce Bookings plugin: ' . $exception->getMessage() );
}
},
10,
diff --git a/modules/ppcp-compat/src/SettingsMap.php b/modules/ppcp-compat/src/SettingsMap.php
new file mode 100644
index 000000000..7c97646a0
--- /dev/null
+++ b/modules/ppcp-compat/src/SettingsMap.php
@@ -0,0 +1,63 @@
+
+ */
+ private array $map;
+
+ /**
+ * The constructor.
+ *
+ * @param AbstractDataModel $model The new settings model.
+ * @param array $map The map of the new setting key to the old setting keys.
+ */
+ public function __construct( AbstractDataModel $model, array $map ) {
+ $this->model = $model;
+ $this->map = $map;
+ }
+
+ /**
+ * The model.
+ *
+ * @return AbstractDataModel
+ */
+ public function get_model(): AbstractDataModel {
+ return $this->model;
+ }
+
+ /**
+ * The map of the new setting key to the old setting keys.
+ *
+ * @return array
+ */
+ public function get_map(): array {
+ return $this->map;
+ }
+}
diff --git a/modules/ppcp-compat/src/SettingsMapHelper.php b/modules/ppcp-compat/src/SettingsMapHelper.php
new file mode 100644
index 000000000..474c6f533
--- /dev/null
+++ b/modules/ppcp-compat/src/SettingsMapHelper.php
@@ -0,0 +1,70 @@
+settings_map = $settings_map;
+ }
+
+ /**
+ * Retrieves the mapped value from the new settings.
+ *
+ * @param string $key The key.
+ * @return ?mixed the mapped value or Null if it doesn't exist.
+ */
+ public function mapped_value( string $key ) {
+ if ( ! $this->has_mapped_key( $key ) ) {
+ return null;
+ }
+
+ foreach ( $this->settings_map as $settings_map ) {
+ $mapped_key = array_search( $key, $settings_map->get_map(), true );
+ $new_settings = $settings_map->get_model()->to_array();
+ if ( ! empty( $new_settings[ $mapped_key ] ) ) {
+ return $new_settings[ $mapped_key ];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Checks if the given key exists in the new settings.
+ *
+ * @param string $key The key.
+ * @return bool true if the given key exists in the new settings, otherwise false.
+ */
+ public function has_mapped_key( string $key ) : bool {
+ foreach ( $this->settings_map as $settings_map ) {
+ if ( in_array( $key, $settings_map->get_map(), true ) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
index b66ad378f..1fac77a6e 100644
--- a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
+++ b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
@@ -44,12 +44,6 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): bool {
- $settings = $c->get( 'wcgateway.settings' );
- assert( $settings instanceof Settings );
-
- if ( ! self::should_add_local_apm_gateways( $settings ) ) {
- return true;
- }
add_filter(
'woocommerce_payment_gateways',
@@ -59,6 +53,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType
*/
function ( $methods ) use ( $c ) {
+ if ( ! self::should_add_local_apm_gateways( $c ) ) {
+ return $methods;
+ }
$onboarding_state = $c->get( 'onboarding.state' );
if ( $onboarding_state->current_state() === State::STATE_START ) {
return $methods;
@@ -85,6 +82,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType
*/
function ( $methods ) use ( $c ) {
+ if ( ! self::should_add_local_apm_gateways( $c ) ) {
+ return $methods;
+ }
if ( ! is_array( $methods ) ) {
return $methods;
}
@@ -115,6 +115,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
+ if ( ! self::should_add_local_apm_gateways( $c ) ) {
+ return;
+ }
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
foreach ( $payment_methods as $key => $value ) {
$payment_method_registry->register( $c->get( 'ppcp-local-apms.' . $key . '.payment-method' ) );
@@ -125,6 +128,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
add_filter(
'woocommerce_paypal_payments_localized_script_data',
function ( array $data ) use ( $c ) {
+ if ( ! self::should_add_local_apm_gateways( $c ) ) {
+ return $data;
+ }
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
$default_disable_funding = $data['url_params']['disable-funding'] ?? '';
@@ -143,6 +149,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType
*/
function( $order_id ) use ( $c ) {
+ if ( ! self::should_add_local_apm_gateways( $c ) ) {
+ return;
+ }
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return;
@@ -175,6 +184,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
add_action(
'woocommerce_paypal_payments_payment_capture_completed_webhook_handler',
function( WC_Order $wc_order, string $order_id ) use ( $c ) {
+ if ( ! self::should_add_local_apm_gateways( $c ) ) {
+ return;
+ }
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
if (
! $this->is_local_apm( $wc_order->get_payment_method(), $payment_methods )
@@ -214,10 +226,12 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
/**
* Check if the local APMs should be added to the available payment gateways.
*
- * @param Settings $settings PayPal gateway settings.
+ * @param ContainerInterface $container Container.
* @return bool
*/
- private function should_add_local_apm_gateways( Settings $settings ): bool {
+ private function should_add_local_apm_gateways( ContainerInterface $container ): bool {
+ $settings = $container->get( 'wcgateway.settings' );
+ assert( $settings instanceof Settings );
return $settings->has( 'enabled' )
&& $settings->get( 'enabled' ) === true
&& $settings->has( 'allow_local_apm_gateways' )
diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php
index 369e82824..56a49be8e 100644
--- a/modules/ppcp-onboarding/services.php
+++ b/modules/ppcp-onboarding/services.php
@@ -15,7 +15,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
-use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
@@ -25,7 +24,7 @@ use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use WooCommerce\PayPalCommerce\Onboarding\OnboardingRESTController;
return array(
- 'api.sandbox-host' => static function ( ContainerInterface $container ): string {
+ 'api.sandbox-host' => static function ( ContainerInterface $container ): string {
$state = $container->get( 'onboarding.state' );
@@ -39,7 +38,7 @@ return array(
}
return CONNECT_WOO_SANDBOX_URL;
},
- 'api.production-host' => static function ( ContainerInterface $container ): string {
+ 'api.production-host' => static function ( ContainerInterface $container ): string {
$state = $container->get( 'onboarding.state' );
@@ -54,7 +53,7 @@ return array(
}
return CONNECT_WOO_URL;
},
- 'api.host' => static function ( ContainerInterface $container ): string {
+ 'api.host' => static function ( ContainerInterface $container ): string {
$environment = $container->get( 'onboarding.environment' );
/**
@@ -66,25 +65,7 @@ return array(
? (string) $container->get( 'api.sandbox-host' ) : (string) $container->get( 'api.production-host' );
},
- 'api.paypal-host-production' => static function( ContainerInterface $container ) : string {
- return PAYPAL_API_URL;
- },
- 'api.paypal-host-sandbox' => static function( ContainerInterface $container ) : string {
- return PAYPAL_SANDBOX_API_URL;
- },
- 'api.paypal-website-url-production' => static function( ContainerInterface $container ) : string {
- return PAYPAL_URL;
- },
- 'api.paypal-website-url-sandbox' => static function( ContainerInterface $container ) : string {
- return PAYPAL_SANDBOX_URL;
- },
- 'api.partner_merchant_id-production' => static function( ContainerInterface $container ) : string {
- return CONNECT_WOO_MERCHANT_ID;
- },
- 'api.partner_merchant_id-sandbox' => static function( ContainerInterface $container ) : string {
- return CONNECT_WOO_SANDBOX_MERCHANT_ID;
- },
- 'api.paypal-host' => function( ContainerInterface $container ) : string {
+ 'api.paypal-host' => function( ContainerInterface $container ) : string {
$environment = $container->get( 'onboarding.environment' );
/**
* The current environment.
@@ -97,7 +78,7 @@ return array(
return $container->get( 'api.paypal-host-production' );
},
- 'api.paypal-website-url' => function( ContainerInterface $container ) : string {
+ 'api.paypal-website-url' => function( ContainerInterface $container ) : string {
$environment = $container->get( 'onboarding.environment' );
assert( $environment instanceof Environment );
if ( $environment->current_environment_is( Environment::SANDBOX ) ) {
@@ -107,7 +88,7 @@ return array(
},
- 'api.bearer' => static function ( ContainerInterface $container ): Bearer {
+ 'api.bearer' => static function ( ContainerInterface $container ): Bearer {
$state = $container->get( 'onboarding.state' );
@@ -134,16 +115,16 @@ return array(
$settings
);
},
- 'onboarding.state' => function( ContainerInterface $container ) : State {
+ 'onboarding.state' => function( ContainerInterface $container ) : State {
$settings = $container->get( 'wcgateway.settings' );
return new State( $settings );
},
- 'onboarding.environment' => function( ContainerInterface $container ) : Environment {
+ 'onboarding.environment' => function( ContainerInterface $container ) : Environment {
$settings = $container->get( 'wcgateway.settings' );
return new Environment( $settings );
},
- 'onboarding.assets' => function( ContainerInterface $container ) : OnboardingAssets {
+ 'onboarding.assets' => function( ContainerInterface $container ) : OnboardingAssets {
$state = $container->get( 'onboarding.state' );
$login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' );
return new OnboardingAssets(
@@ -156,14 +137,14 @@ return array(
);
},
- 'onboarding.url' => static function ( ContainerInterface $container ): string {
+ 'onboarding.url' => static function ( ContainerInterface $container ): string {
return plugins_url(
'/modules/ppcp-onboarding/',
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
- 'api.endpoint.login-seller-production' => static function ( ContainerInterface $container ) : LoginSeller {
+ 'api.endpoint.login-seller-production' => static function ( ContainerInterface $container ) : LoginSeller {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller(
@@ -173,7 +154,7 @@ return array(
);
},
- 'api.endpoint.login-seller-sandbox' => static function ( ContainerInterface $container ) : LoginSeller {
+ 'api.endpoint.login-seller-sandbox' => static function ( ContainerInterface $container ) : LoginSeller {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller(
@@ -183,7 +164,7 @@ return array(
);
},
- 'onboarding.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSellerEndpoint {
+ 'onboarding.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSellerEndpoint {
$request_data = $container->get( 'button.request-data' );
$login_seller_production = $container->get( 'api.endpoint.login-seller-production' );
@@ -203,7 +184,7 @@ return array(
new Cache( 'ppcp-client-credentials-cache' )
);
},
- 'onboarding.endpoint.pui' => static function( ContainerInterface $container ) : UpdateSignupLinksEndpoint {
+ 'onboarding.endpoint.pui' => static function( ContainerInterface $container ) : UpdateSignupLinksEndpoint {
return new UpdateSignupLinksEndpoint(
$container->get( 'wcgateway.settings' ),
$container->get( 'button.request-data' ),
@@ -213,26 +194,10 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' )
);
},
- 'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ) : PartnerReferrals {
-
- return new PartnerReferrals(
- CONNECT_WOO_SANDBOX_URL,
- new ConnectBearer(),
- $container->get( 'woocommerce.logger.woocommerce' )
- );
- },
- 'api.endpoint.partner-referrals-production' => static function ( ContainerInterface $container ) : PartnerReferrals {
-
- return new PartnerReferrals(
- CONNECT_WOO_URL,
- new ConnectBearer(),
- $container->get( 'woocommerce.logger.woocommerce' )
- );
- },
- 'onboarding.signup-link-cache' => static function( ContainerInterface $container ): Cache {
+ 'onboarding.signup-link-cache' => static function( ContainerInterface $container ): Cache {
return new Cache( 'ppcp-paypal-signup-link' );
},
- 'onboarding.signup-link-ids' => static function ( ContainerInterface $container ): array {
+ 'onboarding.signup-link-ids' => static function ( ContainerInterface $container ): array {
return array(
'production-ppcp',
'production-express_checkout',
@@ -240,12 +205,12 @@ return array(
'sandbox-express_checkout',
);
},
- 'onboarding.render-send-only-notice' => static function( ContainerInterface $container ) {
+ 'onboarding.render-send-only-notice' => static function( ContainerInterface $container ) {
return new OnboardingSendOnlyNoticeRenderer(
$container->get( 'wcgateway.send-only-message' )
);
},
- 'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
+ 'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
$partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' );
$partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' );
$partner_referrals_data = $container->get( 'api.repository.partner-referrals-data' );
@@ -261,14 +226,14 @@ return array(
$logger
);
},
- 'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
+ 'onboarding.render-options' => static function ( ContainerInterface $container ) : OnboardingOptionsRenderer {
return new OnboardingOptionsRenderer(
$container->get( 'onboarding.url' ),
$container->get( 'api.shop.country' ),
$container->get( 'wcgateway.settings' )
);
},
- 'onboarding.rest' => static function( $container ) : OnboardingRESTController {
+ 'onboarding.rest' => static function( $container ) : OnboardingRESTController {
return new OnboardingRESTController( $container );
},
);
diff --git a/modules/ppcp-onboarding/src/OnboardingModule.php b/modules/ppcp-onboarding/src/OnboardingModule.php
index 3ec48fabf..023319827 100644
--- a/modules/ppcp-onboarding/src/OnboardingModule.php
+++ b/modules/ppcp-onboarding/src/OnboardingModule.php
@@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\Onboarding\Endpoint\UpdateSignupLinksEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
+use WooCommerce\PayPalCommerce\Settings\SettingsModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
@@ -44,33 +45,32 @@ class OnboardingModule implements ServiceModule, ExtendingModule, ExecutableModu
*/
public function run( ContainerInterface $c ): bool {
- if ( ! apply_filters(
- // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
- 'woocommerce.feature-flags.woocommerce_paypal_payments.settings_enabled',
- getenv( 'PCP_SETTINGS_ENABLED' ) === '1'
- ) ) {
+ add_action(
+ 'admin_enqueue_scripts',
+ function() use ( $c ) {
+ if (
+ apply_filters(
+ // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
+ 'woocommerce.feature-flags.woocommerce_paypal_payments.settings_enabled',
+ getenv( 'PCP_SETTINGS_ENABLED' ) === '1'
+ ) && ! SettingsModule::should_use_the_old_ui()
+ ) {
+ return;
+ }
- $asset_loader = $c->get( 'onboarding.assets' );
- /**
- * The OnboardingAssets.
- *
- * @var OnboardingAssets $asset_loader
- */
- add_action(
- 'admin_enqueue_scripts',
- array(
- $asset_loader,
- 'register',
- )
- );
- add_action(
- 'woocommerce_settings_checkout',
- array(
- $asset_loader,
- 'enqueue',
- )
- );
- }
+ $asset_loader = $c->get( 'onboarding.assets' );
+ assert( $asset_loader instanceof OnboardingAssets );
+
+ $asset_loader->register();
+ add_action(
+ 'woocommerce_settings_checkout',
+ array(
+ $asset_loader,
+ 'enqueue',
+ )
+ );
+ }
+ );
add_filter(
'woocommerce_form_field',
diff --git a/modules/ppcp-order-tracking/src/OrderTrackingModule.php b/modules/ppcp-order-tracking/src/OrderTrackingModule.php
index cdc44fbdb..ec9324948 100644
--- a/modules/ppcp-order-tracking/src/OrderTrackingModule.php
+++ b/modules/ppcp-order-tracking/src/OrderTrackingModule.php
@@ -55,23 +55,21 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
* @throws NotFoundException
*/
public function run( ContainerInterface $c ): bool {
- $endpoint = $c->get( 'order-tracking.endpoint.controller' );
- assert( $endpoint instanceof OrderTrackingEndpoint );
- add_action( 'wc_ajax_' . OrderTrackingEndpoint::ENDPOINT, array( $endpoint, 'handle_request' ) );
+ add_action(
+ 'wc_ajax_' . OrderTrackingEndpoint::ENDPOINT,
+ function() use ( $c ) {
+ $c->get( 'order-tracking.endpoint.controller' )->handle_request();
+ }
+ );
$asset_loader = $c->get( 'order-tracking.assets' );
assert( $asset_loader instanceof OrderEditPageAssets );
- $logger = $c->get( 'woocommerce.logger.woocommerce' );
- assert( $logger instanceof LoggerInterface );
-
- $bearer = $c->get( 'api.bearer' );
-
add_action(
'init',
- function() use ( $asset_loader, $bearer ) {
- if ( ! $this->is_tracking_enabled( $bearer ) ) {
+ function() use ( $asset_loader, $c ) {
+ if ( ! $this->is_tracking_enabled( $c->get( 'api.bearer' ) ) ) {
return;
}
@@ -80,8 +78,8 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
);
add_action(
'init',
- function() use ( $asset_loader, $bearer ) {
- if ( ! $this->is_tracking_enabled( $bearer ) ) {
+ function() use ( $asset_loader, $c ) {
+ if ( ! $this->is_tracking_enabled( $c->get( 'api.bearer' ) ) ) {
return;
}
@@ -89,9 +87,6 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
}
);
- $meta_box_renderer = $c->get( 'order-tracking.meta-box.renderer' );
- assert( $meta_box_renderer instanceof MetaBoxRenderer );
-
add_action(
'add_meta_boxes',
/**
@@ -103,8 +98,8 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
*
* @psalm-suppress MissingClosureParamType
*/
- function( string $post_type, $post_or_order_object ) use ( $meta_box_renderer, $bearer ) {
- if ( ! $this->is_tracking_enabled( $bearer ) ) {
+ function( string $post_type, $post_or_order_object ) use ( $c ) {
+ if ( ! $this->is_tracking_enabled( $c->get( 'api.bearer' ) ) ) {
return;
}
@@ -135,6 +130,9 @@ class OrderTrackingModule implements ServiceModule, ExtendingModule, ExecutableM
? wc_get_page_screen_id( 'shop-order' )
: 'shop_order';
+ $meta_box_renderer = $c->get( 'order-tracking.meta-box.renderer' );
+ assert( $meta_box_renderer instanceof MetaBoxRenderer );
+
add_meta_box(
'ppcp_order-tracking',
__( 'PayPal Package Tracking', 'woocommerce-paypal-payments' ),
diff --git a/modules/ppcp-paylater-block/src/PayLaterBlockModule.php b/modules/ppcp-paylater-block/src/PayLaterBlockModule.php
index 896d98027..32d8dc762 100644
--- a/modules/ppcp-paylater-block/src/PayLaterBlockModule.php
+++ b/modules/ppcp-paylater-block/src/PayLaterBlockModule.php
@@ -71,12 +71,12 @@ class PayLaterBlockModule implements ServiceModule, ExtendingModule, ExecutableM
return true;
}
- $settings = $c->get( 'wcgateway.settings' );
- assert( $settings instanceof Settings );
-
add_action(
'init',
- function () use ( $c, $settings ): void {
+ function () use ( $c ): void {
+ $settings = $c->get( 'wcgateway.settings' );
+ assert( $settings instanceof Settings );
+
$script_handle = 'ppcp-paylater-block';
wp_register_script(
$script_handle,
diff --git a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php
index c7fef6ceb..2c13bed71 100644
--- a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php
+++ b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php
@@ -56,46 +56,46 @@ class PayLaterConfiguratorModule implements ServiceModule, ExtendingModule, Exec
* {@inheritDoc}
*/
public function run( ContainerInterface $c ) : bool {
- $is_available = $c->get( 'paylater-configurator.is-available' );
-
- if ( ! $is_available ) {
- return true;
- }
-
- $current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' );
- $is_wc_settings_page = $c->get( 'wcgateway.is-wc-settings-page' );
- $messaging_locations = $c->get( 'paylater-configurator.messaging-locations' );
-
- $this->add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id );
-
- $settings = $c->get( 'wcgateway.settings' );
- assert( $settings instanceof Settings );
-
- add_action(
- 'wc_ajax_' . SaveConfig::ENDPOINT,
- static function () use ( $c ) {
- $endpoint = $c->get( 'paylater-configurator.endpoint.save-config' );
- assert( $endpoint instanceof SaveConfig );
- $endpoint->handle_request();
- }
- );
-
- add_action(
- 'wc_ajax_' . GetConfig::ENDPOINT,
- static function () use ( $c ) {
- $endpoint = $c->get( 'paylater-configurator.endpoint.get-config' );
- assert( $endpoint instanceof GetConfig );
- $endpoint->handle_request();
- }
- );
-
- if ( $current_page_id !== Settings::PAY_LATER_TAB_ID ) {
- return true;
- }
add_action(
'init',
- static function () use ( $c, $settings ) {
+ static function () use ( $c ) {
+ $is_available = $c->get( 'paylater-configurator.is-available' );
+ if ( ! $is_available ) {
+ return;
+ }
+
+ $current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' );
+ $is_wc_settings_page = $c->get( 'wcgateway.is-wc-settings-page' );
+ $messaging_locations = $c->get( 'paylater-configurator.messaging-locations' );
+
+ self::add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id );
+
+ $settings = $c->get( 'wcgateway.settings' );
+ assert( $settings instanceof Settings );
+
+ add_action(
+ 'wc_ajax_' . SaveConfig::ENDPOINT,
+ static function () use ( $c ) {
+ $endpoint = $c->get( 'paylater-configurator.endpoint.save-config' );
+ assert( $endpoint instanceof SaveConfig );
+ $endpoint->handle_request();
+ }
+ );
+
+ add_action(
+ 'wc_ajax_' . GetConfig::ENDPOINT,
+ static function () use ( $c ) {
+ $endpoint = $c->get( 'paylater-configurator.endpoint.get-config' );
+ assert( $endpoint instanceof GetConfig );
+ $endpoint->handle_request();
+ }
+ );
+
+ if ( $current_page_id !== Settings::PAY_LATER_TAB_ID ) {
+ return;
+ }
+
wp_enqueue_script(
'ppcp-paylater-configurator-lib',
'https://www.paypalobjects.com/merchant-library/merchant-configurator.js',
@@ -165,7 +165,7 @@ class PayLaterConfiguratorModule implements ServiceModule, ExtendingModule, Exec
*
* @return void
*/
- private function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id ) : void {
+ private static function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id ) : void {
// The message must be registered on any WC-Settings page, except for the Pay Later page.
if ( ! $is_settings_page || Settings::PAY_LATER_TAB_ID === $current_page_id ) {
return;
diff --git a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksModule.php b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksModule.php
index fe547ea17..2a629b8f0 100644
--- a/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksModule.php
+++ b/modules/ppcp-paylater-wc-blocks/src/PayLaterWCBlocksModule.php
@@ -99,12 +99,11 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
return true;
}
- $settings = $c->get( 'wcgateway.settings' );
- assert( $settings instanceof Settings );
-
add_action(
'init',
- function () use ( $c, $settings ): void {
+ function () use ( $c ): void {
+ $settings = $c->get( 'wcgateway.settings' );
+ assert( $settings instanceof Settings );
$config_factory = $c->get( 'paylater-configurator.factory.config' );
assert( $config_factory instanceof ConfigFactory );
@@ -186,47 +185,52 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
2
);
- /**
- * Cannot return false for this path.
- *
- * @psalm-suppress PossiblyFalseArgument
- */
- if ( function_exists( 'register_block_type' ) ) {
- register_block_type(
- dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CartPayLaterMessagesBlock',
- array(
- 'render_callback' => function ( array $attributes ) use ( $c ) {
- return PayLaterWCBlocksUtils::render_paylater_block(
- $attributes['blockId'] ?? 'woocommerce-paypal-payments/cart-paylater-messages',
- $attributes['ppcpId'] ?? 'ppcp-cart-paylater-messages',
- 'cart',
- $c
- );
- },
- )
- );
- }
+ add_action(
+ 'init',
+ function () use ( $c ): void {
+ if ( ! function_exists( 'register_block_type' ) ) {
+ return;
+ }
- /**
- * Cannot return false for this path.
- *
- * @psalm-suppress PossiblyFalseArgument
- */
- if ( function_exists( 'register_block_type' ) ) {
- register_block_type(
- dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CheckoutPayLaterMessagesBlock',
- array(
- 'render_callback' => function ( array $attributes ) use ( $c ) {
- return PayLaterWCBlocksUtils::render_paylater_block(
- $attributes['blockId'] ?? 'woocommerce-paypal-payments/checkout-paylater-messages',
- $attributes['ppcpId'] ?? 'ppcp-checkout-paylater-messages',
- 'checkout',
- $c
- );
- },
- )
- );
- }
+ /**
+ * Cannot return false for this path.
+ *
+ * @psalm-suppress PossiblyFalseArgument
+ */
+ register_block_type(
+ dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CartPayLaterMessagesBlock',
+ array(
+ 'render_callback' => function ( array $attributes ) use ( $c ) {
+ return PayLaterWCBlocksUtils::render_paylater_block(
+ $attributes['blockId'] ?? 'woocommerce-paypal-payments/cart-paylater-messages',
+ $attributes['ppcpId'] ?? 'ppcp-cart-paylater-messages',
+ 'cart',
+ $c
+ );
+ },
+ )
+ );
+
+ /**
+ * Cannot return false for this path.
+ *
+ * @psalm-suppress PossiblyFalseArgument
+ */
+ register_block_type(
+ dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CheckoutPayLaterMessagesBlock',
+ array(
+ 'render_callback' => function ( array $attributes ) use ( $c ) {
+ return PayLaterWCBlocksUtils::render_paylater_block(
+ $attributes['blockId'] ?? 'woocommerce-paypal-payments/checkout-paylater-messages',
+ $attributes['ppcpId'] ?? 'ppcp-checkout-paylater-messages',
+ 'checkout',
+ $c
+ );
+ },
+ )
+ );
+ }
+ );
// This is a fallback for the default Cart block that haven't been saved with the inserted Pay Later messaging block.
add_filter(
@@ -271,7 +275,7 @@ class PayLaterWCBlocksModule implements ServiceModule, ExtendingModule, Executab
if ( self::is_under_cart_totals_placement_enabled() ) {
add_action(
'enqueue_block_editor_assets',
- function () use ( $c, $settings ): void {
+ function () use ( $c ): void {
$handle = 'ppcp-checkout-paylater-block-editor-inserter';
$path = $c->get( 'paylater-wc-blocks.url' ) . 'assets/js/cart-paylater-block-inserter.js';
diff --git a/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php b/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php
index 53d045454..48c3a71af 100644
--- a/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php
+++ b/modules/ppcp-paypal-subscriptions/src/PayPalSubscriptionsModule.php
@@ -599,11 +599,11 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
}
);
- $endpoint = $c->get( 'paypal-subscriptions.deactivate-plan-endpoint' );
- assert( $endpoint instanceof DeactivatePlanEndpoint );
add_action(
'wc_ajax_' . DeactivatePlanEndpoint::ENDPOINT,
- array( $endpoint, 'handle_request' )
+ function() use ( $c ) {
+ $c->get( 'paypal-subscriptions.deactivate-plan-endpoint' )->handle_request();
+ }
);
add_action(
diff --git a/modules/ppcp-save-payment-methods/src/Endpoint/CreatePaymentToken.php b/modules/ppcp-save-payment-methods/src/Endpoint/CreatePaymentToken.php
index ae3d7dfa0..434a08925 100644
--- a/modules/ppcp-save-payment-methods/src/Endpoint/CreatePaymentToken.php
+++ b/modules/ppcp-save-payment-methods/src/Endpoint/CreatePaymentToken.php
@@ -94,7 +94,9 @@ class CreatePaymentToken implements EndpointInterface {
)
);
- $result = $this->payment_method_tokens_endpoint->create_payment_token( $payment_source );
+ $customer_id = get_user_meta( get_current_user_id(), '_ppcp_target_customer_id', true );
+
+ $result = $this->payment_method_tokens_endpoint->create_payment_token( $payment_source, $customer_id );
if ( is_user_logged_in() && isset( $result->customer->id ) ) {
$current_user_id = get_current_user_id();
diff --git a/modules/ppcp-save-payment-methods/src/Endpoint/CreateSetupToken.php b/modules/ppcp-save-payment-methods/src/Endpoint/CreateSetupToken.php
index 7eb3a5ace..6952feb43 100644
--- a/modules/ppcp-save-payment-methods/src/Endpoint/CreateSetupToken.php
+++ b/modules/ppcp-save-payment-methods/src/Endpoint/CreateSetupToken.php
@@ -103,7 +103,9 @@ class CreateSetupToken implements EndpointInterface {
);
}
- $result = $this->payment_method_tokens_endpoint->setup_tokens( $payment_source );
+ $customer_id = get_user_meta( get_current_user_id(), '_ppcp_target_customer_id', true );
+
+ $result = $this->payment_method_tokens_endpoint->setup_tokens( $payment_source, $customer_id );
wp_send_json_success( $result );
return true;
diff --git a/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php b/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php
index 406192a5d..c76162193 100644
--- a/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php
+++ b/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php
@@ -63,33 +63,26 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
return true;
}
- $settings = $c->get( 'wcgateway.settings' );
- assert( $settings instanceof Settings );
-
- $billing_agreements_endpoint = $c->get( 'api.endpoint.billing-agreements' );
- assert( $billing_agreements_endpoint instanceof BillingAgreementsEndpoint );
-
add_action(
'woocommerce_paypal_payments_gateway_migrate_on_update',
- function() use ( $settings, $billing_agreements_endpoint ) {
+ function() use ( $c ) {
+ $billing_agreements_endpoint = $c->get( 'api.endpoint.billing-agreements' );
+ assert( $billing_agreements_endpoint instanceof BillingAgreementsEndpoint );
+
$reference_transaction_enabled = $billing_agreements_endpoint->reference_transaction_enabled();
if ( $reference_transaction_enabled !== true ) {
- $settings->set( 'vault_enabled', false );
- $settings->persist();
+ $c->get( 'wcgateway.settings' )->set( 'vault_enabled', false );
+ $c->get( 'wcgateway.settings' )->persist();
}
}
);
- if (
- ( ! $settings->has( 'vault_enabled' ) || ! $settings->get( 'vault_enabled' ) )
- && ( ! $settings->has( 'vault_enabled_dcc' ) || ! $settings->get( 'vault_enabled_dcc' ) )
- ) {
- return true;
- }
-
add_filter(
'woocommerce_paypal_payments_localized_script_data',
function( array $localized_script_data ) use ( $c ) {
+ if ( ! self::vault_enabled( $c ) ) {
+ return $localized_script_data;
+ }
$subscriptions_helper = $c->get( 'wc-subscriptions.helper' );
assert( $subscriptions_helper instanceof SubscriptionHelper );
if ( ! is_user_logged_in() && ! $subscriptions_helper->cart_contains_subscription() ) {
@@ -109,12 +102,11 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
// Adds attributes needed to save payment method.
add_filter(
'ppcp_create_order_request_body_data',
- function( array $data, string $payment_method, array $request_data ) use ( $settings ): array {
+ function( array $data, string $payment_method, array $request_data ) use ( $c ): array {
+ if ( ! self::vault_enabled( $c ) ) {
+ return $data;
+ }
if ( $payment_method === CreditCardGateway::ID ) {
- if ( ! $settings->has( 'vault_enabled_dcc' ) || ! $settings->get( 'vault_enabled_dcc' ) ) {
- return $data;
- }
-
$save_payment_method = $request_data['save_payment_method'] ?? false;
if ( $save_payment_method ) {
$data['payment_source'] = array(
@@ -141,10 +133,6 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
}
if ( $payment_method === PayPalGateway::ID ) {
- if ( ! $settings->has( 'vault_enabled' ) || ! $settings->get( 'vault_enabled' ) ) {
- return $data;
- }
-
$funding_source = $request_data['funding_source'] ?? null;
if ( $funding_source && $funding_source === 'venmo' ) {
@@ -197,6 +185,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'woocommerce_paypal_payments_after_order_processor',
function( WC_Order $wc_order, Order $order ) use ( $c ) {
+ if ( ! self::vault_enabled( $c ) ) {
+ return;
+ }
$payment_source = $order->payment_source();
assert( $payment_source instanceof PaymentSource );
@@ -259,13 +250,30 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
2
);
- add_filter( 'woocommerce_paypal_payments_disable_add_payment_method', '__return_false' );
- add_filter( 'woocommerce_paypal_payments_should_render_card_custom_fields', '__return_false' );
+ add_filter(
+ 'woocommerce_paypal_payments_disable_add_payment_method',
+ function ( bool $value ) use ( $c ): bool {
+ if ( ! self::vault_enabled( $c ) ) {
+ return $value;
+ }
+ return false;
+ }
+ );
+
+ add_filter(
+ 'woocommerce_paypal_payments_should_render_card_custom_fields',
+ function ( bool $value ) use ( $c ): bool {
+ if ( ! self::vault_enabled( $c ) ) {
+ return $value;
+ }
+ return false;
+ }
+ );
add_action(
'wp_enqueue_scripts',
function() use ( $c ) {
- if ( ! is_user_logged_in() || ! ( $this->is_add_payment_method_page() || $this->is_subscription_change_payment_method_page() ) ) {
+ if ( ! is_user_logged_in() || ! ( $this->is_add_payment_method_page() || $this->is_subscription_change_payment_method_page() ) || ! self::vault_enabled( $c ) ) {
return;
}
@@ -355,8 +363,8 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'woocommerce_add_payment_method_form_bottom',
- function () {
- if ( ! is_user_logged_in() || ! is_add_payment_method_page() ) {
+ function () use ( $c ) {
+ if ( ! is_user_logged_in() || ! is_add_payment_method_page() || ! self::vault_enabled( $c ) ) {
return;
}
@@ -367,6 +375,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'wc_ajax_' . CreateSetupToken::ENDPOINT,
static function () use ( $c ) {
+ if ( ! self::vault_enabled( $c ) ) {
+ return;
+ }
$endpoint = $c->get( 'save-payment-methods.endpoint.create-setup-token' );
assert( $endpoint instanceof CreateSetupToken );
@@ -377,6 +388,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'wc_ajax_' . CreatePaymentToken::ENDPOINT,
static function () use ( $c ) {
+ if ( ! self::vault_enabled( $c ) ) {
+ return;
+ }
$endpoint = $c->get( 'save-payment-methods.endpoint.create-payment-token' );
assert( $endpoint instanceof CreatePaymentToken );
@@ -387,6 +401,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'wc_ajax_' . CreatePaymentTokenForGuest::ENDPOINT,
static function () use ( $c ) {
+ if ( ! self::vault_enabled( $c ) ) {
+ return;
+ }
$endpoint = $c->get( 'save-payment-methods.endpoint.create-payment-token-for-guest' );
assert( $endpoint instanceof CreatePaymentTokenForGuest );
@@ -397,6 +414,9 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_action(
'woocommerce_paypal_payments_before_delete_payment_token',
function( string $token_id ) use ( $c ) {
+ if ( ! self::vault_enabled( $c ) ) {
+ return;
+ }
try {
$endpoint = $c->get( 'api.endpoint.payment-tokens' );
assert( $endpoint instanceof PaymentTokensEndpoint );
@@ -419,13 +439,11 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_filter(
'woocommerce_paypal_payments_credit_card_gateway_supports',
function( array $supports ) use ( $c ): array {
- $settings = $c->get( 'wcgateway.settings' );
- assert( $settings instanceof ContainerInterface );
-
- if ( $settings->has( 'vault_enabled_dcc' ) && $settings->get( 'vault_enabled_dcc' ) ) {
- $supports[] = 'tokenization';
- $supports[] = 'add_payment_method';
+ if ( ! self::vault_enabled( $c ) ) {
+ return $supports;
}
+ $supports[] = 'tokenization';
+ $supports[] = 'add_payment_method';
return $supports;
}
@@ -433,7 +451,10 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
add_filter(
'woocommerce_paypal_payments_save_payment_methods_eligible',
- function() {
+ function( bool $value ) use ( $c ): bool {
+ if ( ! self::vault_enabled( $c ) ) {
+ return $value;
+ }
return true;
}
);
@@ -481,4 +502,24 @@ class SavePaymentMethodsModule implements ServiceModule, ExtendingModule, Execut
return $localized_script_data;
}
+
+ /**
+ * Checks whether the vault functionality is enabled based on configuration settings.
+ *
+ * @param ContainerInterface $container The dependency injection container from which settings can be retrieved.
+ *
+ * @return bool Returns true if either 'vault_enabled' or 'vault_enabled_dcc' settings are enabled; otherwise, false.
+ */
+ private static function vault_enabled( ContainerInterface $container ): bool {
+ $settings = $container->get( 'wcgateway.settings' );
+ assert( $settings instanceof Settings );
+
+ if (
+ ( ! $settings->has( 'vault_enabled' ) || ! $settings->get( 'vault_enabled' ) )
+ && ( ! $settings->has( 'vault_enabled_dcc' ) || ! $settings->get( 'vault_enabled_dcc' ) )
+ ) {
+ return false;
+ }
+ return true;
+ }
}
diff --git a/modules/ppcp-settings/package.json b/modules/ppcp-settings/package.json
index 7a6aa9277..0a1391b88 100644
--- a/modules/ppcp-settings/package.json
+++ b/modules/ppcp-settings/package.json
@@ -13,6 +13,7 @@
"@wordpress/scripts": "^30.3.0"
},
"dependencies": {
+ "@paypal/react-paypal-js": "^8.7.0",
"@woocommerce/settings": "^1.0.0",
"react-select": "^5.8.3"
}
diff --git a/modules/ppcp-settings/resources/css/_global.scss b/modules/ppcp-settings/resources/css/_global.scss
index a5eed96d0..3b405d6c1 100644
--- a/modules/ppcp-settings/resources/css/_global.scss
+++ b/modules/ppcp-settings/resources/css/_global.scss
@@ -58,10 +58,6 @@ h1, h2, h3, h4 {
color: $color-black;
}
-a:not(.button) {
- color: $color-blueberry;
-}
-
.components-form-toggle.is-checked > .components-form-toggle__track {
background-color: $color-blueberry;
}
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_badge-box.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_badge-box.scss
index d65d1f184..427b4b1fb 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_badge-box.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_badge-box.scss
@@ -18,7 +18,7 @@
}
}
- &-image-badge {
+ .ppcp-r-badge-box__title-text:not(:empty) + .ppcp-r-badge-box__title-image-badge {
margin-left: 7px;
img {
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_button.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_button.scss
index 3528ad71f..4174e6a23 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_button.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_button.scss
@@ -5,16 +5,16 @@ button.components-button, a.components-button {
}
&:disabled {
- color: $color-white;
+ color: $color-gray-700;
}
- border-radius: 2px;
- padding: 14px 17px;
+ border-radius: 50px;
+ padding: 15px 32px;
height: auto;
}
&.is-primary {
- @include font(13, 20, 400);
+ @include font(14, 18, 900);
&:not(:disabled) {
background-color: $color-blueberry;
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss
index c58f8b021..1a9cf102c 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_fields.scss
@@ -21,23 +21,25 @@
}
}
- &__checkbox-value {
- @include hide-input-field;
+ &__checkbox {
+ position: relative;
- &:not(:checked) + .ppcp-r__checkbox-presentation img {
- display: none;
+ input {
+ margin: 0;
+ border-color: $color-gray-600;
+
+ &:checked {
+ background-color: $color-blueberry;
+ border-color:$color-blueberry;
+ }
}
- &:checked {
- + .ppcp-r__checkbox-presentation {
- width: 20px;
- height: 20px;
- border: none;
+ .components-checkbox-control__input-container {
+ margin: 0;
+ }
- img {
- border-radius: 2px;
- }
- }
+ .components-base-control__field {
+ margin: 0;
}
}
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_payment-method-modal.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_payment-method-modal.scss
index 4274a370a..df0cde379 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_payment-method-modal.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_payment-method-modal.scss
@@ -15,7 +15,7 @@
&__content {
margin-top: 60px;
- padding:0 24px 28px 24px;
+ padding: 0 24px 28px 24px;
}
}
@@ -96,6 +96,36 @@
margin-top: 2px;
}
}
+
+ .components-radio-control {
+ .components-flex {
+ gap: 18px;
+ }
+
+ label {
+ @include font(14, 20, 400);
+ color: $color-black;
+ }
+
+ &__option {
+ gap: 18px;
+ }
+
+ &__input {
+ border-color: $color-gray-700;
+ margin-right: 0;
+ &:checked {
+ border: 1px solid $color-gray-700;
+ background-color: $color-white;
+
+ &::before {
+ transform: translate(3px, 3px);
+ border-width: 6px;
+ border-color: $color-blueberry;
+ }
+ }
+ }
+ }
}
.ppcp-r-modal__field-row--save button.is-primary {
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_separator.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_separator.scss
index 84e3a1f19..6c3976ed7 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_separator.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_separator.scss
@@ -2,13 +2,22 @@
display: flex;
align-items: center;
+ &__space,
&__line {
- height: 1px;
- background-color: $color-gray-600;
+ margin: 0;
display: block;
width: 100%;
}
+ &__line {
+ background-color: $color-gray-400;
+ height: 1px;
+ }
+
+ &__space {
+ margin-bottom: 48px;
+ }
+
&__text {
color: $color-gray;
@include font(12, 24, 500, 0.8px);
diff --git a/modules/ppcp-settings/resources/css/components/reusable-components/_welcome-docs.scss b/modules/ppcp-settings/resources/css/components/reusable-components/_welcome-docs.scss
index e78c940ea..411d5a987 100644
--- a/modules/ppcp-settings/resources/css/components/reusable-components/_welcome-docs.scss
+++ b/modules/ppcp-settings/resources/css/components/reusable-components/_welcome-docs.scss
@@ -4,17 +4,7 @@
&__title {
text-align: center;
@include font(20, 28, 700);
- margin: 0 0 32px 0;
- }
-
- &__description {
- text-align: center;
- @include font(14, 22, 400);
- font-style: italic;
-
- a {
- color: $color-gray-700;
- }
+ margin: 32px 0 32px 0;
}
&__wrapper {
diff --git a/modules/ppcp-settings/resources/css/components/screens/_onboarding-global.scss b/modules/ppcp-settings/resources/css/components/screens/_onboarding-global.scss
index e98813d14..7878ef729 100644
--- a/modules/ppcp-settings/resources/css/components/screens/_onboarding-global.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/_onboarding-global.scss
@@ -1,7 +1,8 @@
body:has(.ppcp-r-container--onboarding) {
background-color: #fff !important;
- .notice, .nav-tab-wrapper.woo-nav-tab-wrapper, .woocommerce-layout, .wrap.woocommerce form > h2, #screen-meta-links {
+ .notice, .nav-tab-wrapper.woo-nav-tab-wrapper, .woocommerce-layout__header, .wrap.woocommerce form > h2, #screen-meta-links {
display: none !important;
+ visibility: hidden;
}
}
diff --git a/modules/ppcp-settings/resources/css/components/screens/_onboarding.scss b/modules/ppcp-settings/resources/css/components/screens/_onboarding.scss
index 5a00adc9d..cfef2e04f 100644
--- a/modules/ppcp-settings/resources/css/components/screens/_onboarding.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/_onboarding.scss
@@ -1,6 +1,7 @@
@import './onboarding/step-welcome';
@import './onboarding/step-business';
@import './onboarding/step-products';
+@import './onboarding/step-payment-methods';
.ppcp-r-tabs.onboarding,
.ppcp-r-container--onboarding {
diff --git a/modules/ppcp-settings/resources/css/components/screens/_settings.scss b/modules/ppcp-settings/resources/css/components/screens/_settings.scss
index cc8ec5a26..8cf4fe593 100644
--- a/modules/ppcp-settings/resources/css/components/screens/_settings.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/_settings.scss
@@ -49,6 +49,17 @@
}
}
+ .ppcp-r__checkbox {
+ .components-flex {
+ gap: 12px;
+ }
+
+ label {
+ @include font(13, 20, 400);
+ color: $color-blueberry;
+ }
+ }
+
&__description {
@include font(13, 20, 400);
color: $color-blueberry;
diff --git a/modules/ppcp-settings/resources/css/components/screens/onboarding/_step-payment-methods.scss b/modules/ppcp-settings/resources/css/components/screens/onboarding/_step-payment-methods.scss
new file mode 100644
index 000000000..4ab630733
--- /dev/null
+++ b/modules/ppcp-settings/resources/css/components/screens/onboarding/_step-payment-methods.scss
@@ -0,0 +1,38 @@
+.ppcp-r-page-optional-payment-methods {
+ .ppcp-r-select-box:first-child {
+ .ppcp-r-select-box__title {
+ margin-bottom: 20px;
+ }
+ }
+}
+
+.ppcp-r-optional-payment-methods {
+ &__wrapper {
+ .ppcp-r-badge-box {
+ margin: 0 0 24px 0;
+ &:last-child {
+ margin: 0;
+ }
+ }
+
+ .ppcp-r-badge-box__description {
+ margin: 12px 0 0 0;
+ @include font(14, 20, 400);
+ }
+ }
+
+ &__description {
+ margin: 32px 0 0 0;
+ text-align: center;
+ @include font(14, 22, 400);
+ font-style: italic;
+
+ a {
+ color: $color-gray-700;
+ }
+ }
+
+ &__separator {
+ margin: 0 0 24px 0;
+ }
+}
diff --git a/modules/ppcp-settings/resources/css/components/screens/onboarding/_step-welcome.scss b/modules/ppcp-settings/resources/css/components/screens/onboarding/_step-welcome.scss
index fec5f3483..3399a1bc9 100644
--- a/modules/ppcp-settings/resources/css/components/screens/onboarding/_step-welcome.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/onboarding/_step-welcome.scss
@@ -16,27 +16,22 @@
text-align: center;
}
- .ppcp-r-page-welcome-or-separator {
- margin: 0 0 16px 0;
- }
-
- .ppcp-r-page-welcome-mode-separator {
- margin: 0 0 48px 0;
-
- .ppcp-r-separator__line {
- background-color: $color-gray-300;
- }
- }
-
.components-base-control__field {
margin: 0 0 24px 0;
}
+
.ppcp-r-toggle-block__toggled-content > button{
@include small-button;
color: $color-white;
border: none;
}
+ .client-id-error {
+ color: #cc1818;
+ margin: -16px 0 24px;
+ @include font(11, 16, 450);
+ }
+
.onboarding-advanced-options {
max-width: 800px;
}
diff --git a/modules/ppcp-settings/resources/css/components/screens/overview/_tab-styling.scss b/modules/ppcp-settings/resources/css/components/screens/overview/_tab-styling.scss
new file mode 100644
index 000000000..c75d6a4c9
--- /dev/null
+++ b/modules/ppcp-settings/resources/css/components/screens/overview/_tab-styling.scss
@@ -0,0 +1,121 @@
+.ppcp-r-styling {
+ display: flex;
+ border: 1px solid $color-gray-200;
+ border-radius: 8px;
+ overflow: hidden;
+
+ &__section:not(:last-child) {
+ border-bottom: 1px solid black;
+ padding-bottom: 24px;
+ margin-bottom: 28px;
+ border-bottom: 1px solid $color-gray-600;
+ }
+
+ &__main-title {
+ @include font(14, 20, 600);
+ color: $color-gray-800;
+ margin: 0 0 8px 0;
+ display: block;
+ }
+
+ &__description {
+ @include font(13, 20, 400);
+ color: $color-gray-800;
+ margin: 0 0 18px 0;
+ }
+
+ &__settings {
+ width: 422px;
+ background-color: $color-white;
+ padding: 48px;
+ }
+
+ &__preview {
+ width: calc(100% - 422px);
+ background-color: #FAF8F5;
+ display: flex;
+ align-items: center;
+
+ &-inner {
+ width: 100%;
+ padding: 24px;
+ }
+ }
+
+ &__section--rc {
+ .ppcp-r-styling__title {
+ @include font(13, 20, 600);
+ color: $color-black;
+ display: block;
+ margin: 0 0 18px 0;
+ }
+ }
+
+ &__section--empty.ppcp-r-styling__section {
+ padding-bottom: 0;
+ margin-bottom: 0;
+ border-bottom: none;
+ }
+
+ &__select {
+ label {
+ @include font(13, 16, 600);
+ color: $color-black;
+ margin: 0;
+ text-transform: none;
+ }
+
+ select {
+ @include font(13, 20, 400);
+ }
+ }
+
+ .ppcp-r__checkbox {
+ .components-checkbox-control {
+ &__label {
+ @include font(13, 20, 400);
+ color: $color-black;
+ }
+ }
+
+ .components-flex {
+ gap: 12px;
+ }
+ }
+
+ &__payment-method-checkboxes {
+ display: flex;
+ flex-direction: column;
+ gap: 24px;
+ }
+}
+
+.ppcp-r {
+ &__horizontal-control {
+ .components-flex {
+ flex-direction: row;
+ justify-content: flex-start;
+ gap: 32px;
+ }
+
+
+ .components-radio-control {
+ &__option {
+ gap: 12px;
+
+ input {
+ margin: 0;
+ }
+
+ label {
+ @include font(13, 20, 400);
+ color: $color-black;
+ }
+ }
+
+ input {
+ margin: 0;
+ }
+ }
+ }
+}
diff --git a/modules/ppcp-settings/resources/css/style.scss b/modules/ppcp-settings/resources/css/style.scss
index 8358238df..ba1bc6ba9 100644
--- a/modules/ppcp-settings/resources/css/style.scss
+++ b/modules/ppcp-settings/resources/css/style.scss
@@ -21,6 +21,7 @@
@import './components/reusable-components/welcome-docs';
@import './components/screens/onboarding';
@import './components/screens/settings';
+ @import './components/screens/overview/tab-styling';
}
@import './components/reusable-components/payment-method-modal';
diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/AccordionSection.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/AccordionSection.js
index 05cc758db..23f01a09c 100644
--- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/AccordionSection.js
+++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/AccordionSection.js
@@ -1,3 +1,4 @@
+import { useEffect } from '@wordpress/element';
import { Icon } from '@wordpress/components';
import { chevronDown, chevronUp } from '@wordpress/icons';
@@ -5,11 +6,33 @@ import { useState } from 'react';
const Accordion = ( {
title,
- initiallyOpen = false,
+ initiallyOpen = null,
className = '',
+ id = '',
children,
} ) => {
- const [ isOpen, setIsOpen ] = useState( initiallyOpen );
+ const determineInitialState = () => {
+ if ( id && initiallyOpen === null ) {
+ return window.location.hash === `#${ id }`;
+ }
+ return !! initiallyOpen;
+ };
+
+ const [ isOpen, setIsOpen ] = useState( determineInitialState );
+
+ useEffect( () => {
+ const handleHashChange = () => {
+ if ( id && window.location.hash === `#${ id }` ) {
+ setIsOpen( true );
+ }
+ };
+
+ window.addEventListener( 'hashchange', handleHashChange );
+
+ return () => {
+ window.removeEventListener( 'hashchange', handleHashChange );
+ };
+ }, [ id ] );
const toggleOpen = ( ev ) => {
setIsOpen( ! isOpen );
@@ -26,7 +49,7 @@ const Accordion = ( {
}
return (
-
+