Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions modules/ppcp-compat/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use WooCommerce\PayPalCommerce\Compat\Settings\StylingSettingsMapHelper;
use WooCommerce\PayPalCommerce\Compat\Settings\SubscriptionSettingsMapHelper;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint\PayPalSettingsExporter;
use WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint\PayPalSettingsImporter;
use WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint\PayPalBlueprintBootstrap;

return array(

Expand Down Expand Up @@ -215,4 +218,19 @@
'compat.settings.payment_methods_map_helper' => static function (): PaymentMethodSettingsMapHelper {
return new PaymentMethodSettingsMapHelper();
},
'compat.blueprint.is_available' => function (): bool {
return interface_exists( 'Automattic\WooCommerce\Blueprint\Exporters\StepExporter' );
},
'compat.blueprint.paypal_settings_exporter' => static function ( ContainerInterface $container ): PayPalSettingsExporter {
return new PayPalSettingsExporter();
},
'compat.blueprint.paypal_settings_importer' => static function ( ContainerInterface $container ): PayPalSettingsImporter {
return new PayPalSettingsImporter();
},
'compat.blueprint.bootstrap' => static function ( ContainerInterface $container ): PayPalBlueprintBootstrap {
return new PayPalBlueprintBootstrap(
$container->get( 'compat.blueprint.paypal_settings_exporter' ),
$container->get( 'compat.blueprint.paypal_settings_importer' )
);
},
);
18 changes: 18 additions & 0 deletions modules/ppcp-compat/src/CompatModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ function () use ( $c ) {
$this->initialize_wc_bookings_compat_layer( $c );
}

$this->initialize_blueprint_compat_layer( $c );

add_action( 'woocommerce_paypal_payments_gateway_migrate', static fn() => delete_transient( 'ppcp_has_ppec_subscriptions' ) );

$this->legacy_ui_card_payment_mapping( $c );
Expand Down Expand Up @@ -551,6 +553,22 @@ static function ( WC_Order $wc_order, CartData $cart_data ) use ( $container ):
);
}

/**
* Sets up the WooCommerce Blueprint compatibility layer.
*
* @param ContainerInterface $container The Container.
* @return void
*/
private function initialize_blueprint_compat_layer( ContainerInterface $container ): void {
$is_blueprint_available = $container->get( 'compat.blueprint.is_available' );
if ( ! $is_blueprint_available ) {
return;
}

$blueprint_bootstrap = $container->get( 'compat.blueprint.bootstrap' );
$blueprint_bootstrap->init();
}

/**
* Responsible to keep the credit card payment configuration backwards
* compatible with the legacy UI.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* PayPal Blueprint Bootstrap - Registers exporters and importers.
*
* @package WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint
*/

declare(strict_types=1);

namespace WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint;

/**
* Bootstrap class for PayPal Blueprint functionality.
*/
class PayPalBlueprintBootstrap {

/**
* PayPal Settings Exporter instance.
*
* @var PayPalSettingsExporter
*/
private PayPalSettingsExporter $exporter;

/**
* PayPal Settings Importer instance.
*
* @var PayPalSettingsImporter
*/
private PayPalSettingsImporter $importer;

/**
* Constructor.
*
* @param PayPalSettingsExporter $exporter PayPal settings exporter.
* @param PayPalSettingsImporter $importer PayPal settings importer.
*/
public function __construct(
PayPalSettingsExporter $exporter,
PayPalSettingsImporter $importer
) {
$this->exporter = $exporter;
$this->importer = $importer;
}

/**
* Initialize the PayPal Blueprint functionality.
*
* @return void
*/
public function init(): void {
$this->register_hooks();
}

/**
* Register WordPress hooks.
*
* @return void
*/
private function register_hooks(): void {
add_filter( 'wooblueprint_exporters', array( $this, 'register_exporters' ) );
add_filter( 'wooblueprint_importers', array( $this, 'register_importers' ) );
}

/**
* Register PayPal exporters.
*
* @param array $exporters Existing exporters.
* @return array
*/
public function register_exporters( array $exporters ): array {
$exporters[] = $this->exporter;
return $exporters;
}

/**
* Register PayPal importers.
*
* @param array $importers Existing importers.
* @return array
*/
public function register_importers( array $importers ): array {
$importers[] = $this->importer;
return $importers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* PayPal Settings Blueprint Exporter.
*
* @package WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint
*/

declare(strict_types=1);

namespace WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint;

use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\Steps\Step;

/**
* PayPal Settings Exporter for WooCommerce Blueprint.
*/
class PayPalSettingsExporter implements StepExporter, HasAlias {

/**
* Sentinel value to detect if option doesn't exist.
*/
private const OPTION_NOT_FOUND = '__PAYPAL_OPTION_NOT_FOUND__';

/**
* PayPal-related options to export (excluding transients and plugin metadata).
*
* @var array<string>
*/
private const PAYPAL_OPTIONS = array(
// Core PPCP data settings (new settings).
'woocommerce-ppcp-data-common',
'woocommerce-ppcp-data-onboarding',
'woocommerce-ppcp-data-payment',
'woocommerce-ppcp-data-settings',
'woocommerce-ppcp-data-styling',
// Legacy settings (maintained for backward compatibility during migration).
'woocommerce-ppcp-settings',
// Merchant state flags.
'woocommerce-ppcp-is-new-merchant',
// UI and migration state flags (prevent re-migration and control UI display).
'woocommerce_ppcp-settings-should-use-old-ui',
'woocommerce_ppcp-is_pay_later_settings_migrated',
'woocommerce_ppcp-is_smart_button_settings_migrated',
// Individual payment method settings (gateway titles/descriptions).
'woocommerce_venmo_settings',
'woocommerce_pay-later_settings',
);

/**
* Export PayPal settings.
*
* @return Step
*/
public function export(): Step {
$paypal_options = array();

foreach ( self::PAYPAL_OPTIONS as $option_name ) {
$value = get_option( $option_name, self::OPTION_NOT_FOUND );
if ( self::OPTION_NOT_FOUND !== $value ) {
$paypal_options[ $option_name ] = $value;
}
}

return new SetSiteOptions( $paypal_options );
}

/**
* Get step name.
*
* @return string
*/
public function get_step_name(): string {
return SetSiteOptions::get_step_name();
}

/**
* Get alias for this exporter.
*
* @return string
*/
public function get_alias(): string {
return 'paypalSettings';
}

/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label(): string {
return __( 'PayPal Settings', 'woocommerce-paypal-payments' );
}

/**
* Return the description used in the frontend.
*
* @return string
*/
public function get_description(): string {
return __( 'Exports PayPal Payments settings and configuration options.', 'woocommerce-paypal-payments' );
}

/**
* Check if user has capability to export PayPal settings.
*
* @return bool
*/
public function check_step_capabilities(): bool {
return current_user_can( 'manage_woocommerce' ) && current_user_can( 'manage_options' );
}
}
Loading
Loading