|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * PayPal Settings Blueprint Exporter. |
| 4 | + * |
| 5 | + * @package WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint |
| 6 | + */ |
| 7 | + |
| 8 | +declare(strict_types=1); |
| 9 | + |
| 10 | +namespace WooCommerce\PayPalCommerce\Compat\WooCommerceBlueprint; |
| 11 | + |
| 12 | +use Automattic\WooCommerce\Blueprint\Exporters\StepExporter; |
| 13 | +use Automattic\WooCommerce\Blueprint\Exporters\HasAlias; |
| 14 | +use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions; |
| 15 | +use Automattic\WooCommerce\Blueprint\Steps\Step; |
| 16 | + |
| 17 | +/** |
| 18 | + * PayPal Settings Exporter for WooCommerce Blueprint. |
| 19 | + */ |
| 20 | +class PayPalSettingsExporter implements StepExporter, HasAlias { |
| 21 | + |
| 22 | + /** |
| 23 | + * Sentinel value to detect if option doesn't exist. |
| 24 | + */ |
| 25 | + private const OPTION_NOT_FOUND = '__PAYPAL_OPTION_NOT_FOUND__'; |
| 26 | + |
| 27 | + /** |
| 28 | + * PayPal-related options to export (excluding transients and plugin metadata). |
| 29 | + * |
| 30 | + * @var array<string> |
| 31 | + */ |
| 32 | + private const PAYPAL_OPTIONS = array( |
| 33 | + // Core PPCP data settings (new settings). |
| 34 | + 'woocommerce-ppcp-data-common', |
| 35 | + 'woocommerce-ppcp-data-onboarding', |
| 36 | + 'woocommerce-ppcp-data-payment', |
| 37 | + 'woocommerce-ppcp-data-settings', |
| 38 | + 'woocommerce-ppcp-data-styling', |
| 39 | + // Legacy settings (maintained for backward compatibility during migration). |
| 40 | + 'woocommerce-ppcp-settings', |
| 41 | + // Merchant state flags. |
| 42 | + 'woocommerce-ppcp-is-new-merchant', |
| 43 | + // UI and migration state flags (prevent re-migration and control UI display). |
| 44 | + 'woocommerce_ppcp-settings-should-use-old-ui', |
| 45 | + 'woocommerce_ppcp-is_pay_later_settings_migrated', |
| 46 | + 'woocommerce_ppcp-is_smart_button_settings_migrated', |
| 47 | + // Individual payment method settings (gateway titles/descriptions). |
| 48 | + 'woocommerce_venmo_settings', |
| 49 | + 'woocommerce_pay-later_settings', |
| 50 | + ); |
| 51 | + |
| 52 | + /** |
| 53 | + * Export PayPal settings. |
| 54 | + * |
| 55 | + * @return Step |
| 56 | + */ |
| 57 | + public function export(): Step { |
| 58 | + $paypal_options = array(); |
| 59 | + |
| 60 | + foreach ( self::PAYPAL_OPTIONS as $option_name ) { |
| 61 | + $value = get_option( $option_name, self::OPTION_NOT_FOUND ); |
| 62 | + if ( self::OPTION_NOT_FOUND !== $value ) { |
| 63 | + $paypal_options[ $option_name ] = $value; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + return new SetSiteOptions( $paypal_options ); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Get step name. |
| 72 | + * |
| 73 | + * @return string |
| 74 | + */ |
| 75 | + public function get_step_name(): string { |
| 76 | + return SetSiteOptions::get_step_name(); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Get alias for this exporter. |
| 81 | + * |
| 82 | + * @return string |
| 83 | + */ |
| 84 | + public function get_alias(): string { |
| 85 | + return 'paypalSettings'; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Return label used in the frontend. |
| 90 | + * |
| 91 | + * @return string |
| 92 | + */ |
| 93 | + public function get_label(): string { |
| 94 | + return __( 'PayPal Settings', 'woocommerce-paypal-payments' ); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Return the description used in the frontend. |
| 99 | + * |
| 100 | + * @return string |
| 101 | + */ |
| 102 | + public function get_description(): string { |
| 103 | + return __( 'Exports PayPal Payments settings and configuration options.', 'woocommerce-paypal-payments' ); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Check if user has capability to export PayPal settings. |
| 108 | + * |
| 109 | + * @return bool |
| 110 | + */ |
| 111 | + public function check_step_capabilities(): bool { |
| 112 | + return current_user_can( 'manage_woocommerce' ) && current_user_can( 'manage_options' ); |
| 113 | + } |
| 114 | +} |
0 commit comments