| 1 |
<?php |
| 2 |
|
| 3 |
//phpcs:disable PSR12.Files.FileHeader.IncorrectOrder |
| 4 |
declare (strict_types=1); |
| 5 |
/** |
| 6 |
* Plugin Name: PayPal Point of Sale |
| 7 |
* Plugin URI: https://zettle.inpsyde.com/ |
| 8 |
* Description: PayPal Point of Sale Integration for WooCommerce |
| 9 |
* Version: 2.0.0 |
| 10 |
* SHA: 127eafc1e31f4ee75169713f214a0d1dd0c8fada |
| 11 |
* Requires at least: 6.8 |
| 12 |
* Requires PHP: 8.2 |
| 13 |
* Requires Plugins: woocommerce |
| 14 |
* WC requires at least: 10.2 |
| 15 |
* WC tested up to: 10.2 |
| 16 |
* Author: PayPal |
| 17 |
* Author URI: https://www.paypal.com/us/business/pos |
| 18 |
* License: GPL-2.0 |
| 19 |
* Text Domain: paypal-point-of-sale |
| 20 |
* Domain Path: /languages |
| 21 |
*/ |
| 22 |
/** |
| 23 |
* phpcs:disable PSR1.Files.SideEffects |
| 24 |
* phpcs:disable Squiz.PHP.CommentedOutCode.Found |
| 25 |
* phpcs:disable Squiz.PHP.InnerFunctions.NotAllowed |
| 26 |
* phpcs:disable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh |
| 27 |
*/ |
| 28 |
namespace Syde\Vendor\Zettle\Syde\PayPal\PointOfSale; |
| 29 |
|
| 30 |
use Syde\Vendor\Zettle\Inpsyde\Modularity\Package; |
| 31 |
use Syde\Vendor\Zettle\Syde\PayPal\PointOfSale\Validation\ValidationFailedException; |
| 32 |
(static function (): void { |
| 33 |
/** |
| 34 |
* Display an error message in the WP admin |
| 35 |
* |
| 36 |
* @param string $message The message content |
| 37 |
* |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
function errorNotice(string $message): void |
| 41 |
{ |
| 42 |
add_action('all_admin_notices', static function () use ($message) { |
| 43 |
$class = 'notice notice-error'; |
| 44 |
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), wp_kses_post($message)); |
| 45 |
}); |
| 46 |
} |
| 47 |
$requiresAtLeast = '8.2'; |
| 48 |
if (version_compare(\PHP_VERSION, $requiresAtLeast, '<')) { |
| 49 |
errorNotice(sprintf( |
| 50 |
/* translators: required PHP version */ |
| 51 |
esc_html__('PayPal Point of Sale requires at least PHP version %s.', 'paypal-point-of-sale'), |
| 52 |
$requiresAtLeast |
| 53 |
) . '<br>' . sprintf( |
| 54 |
/* translators: required PHP version */ |
| 55 |
esc_html__('Please ask your server administrator to update your environment to PHP version %s.', 'paypal-point-of-sale'), |
| 56 |
$requiresAtLeast |
| 57 |
)); |
| 58 |
return; |
| 59 |
} |
| 60 |
if (!class_exists(PluginModule::class) && file_exists(__DIR__ . '/vendor/autoload.php')) { |
| 61 |
include_once __DIR__ . '/vendor/autoload.php'; |
| 62 |
} |
| 63 |
function init(): ?Package |
| 64 |
{ |
| 65 |
static $initialized; |
| 66 |
static $package; |
| 67 |
if (!$initialized) { |
| 68 |
try { |
| 69 |
$package = (require __DIR__ . '/bootstrap.php')(__FILE__, \true); |
| 70 |
} catch (ValidationFailedException $exc) { |
| 71 |
$messages = array_map(static function (mixed $error): string { |
| 72 |
if ($error instanceof ValidationFailedException) { |
| 73 |
return $error->getMessage(); |
| 74 |
} |
| 75 |
return (string) $error; |
| 76 |
}, $exc->getValidationErrors()); |
| 77 |
foreach ($messages as $message) { |
| 78 |
errorNotice($message); |
| 79 |
} |
| 80 |
return null; |
| 81 |
} |
| 82 |
$initialized = \true; |
| 83 |
} |
| 84 |
return $package; |
| 85 |
} |
| 86 |
add_action('plugins_loaded', static function (): void { |
| 87 |
$package = init(); |
| 88 |
if (!$package) { |
| 89 |
return; |
| 90 |
} |
| 91 |
$container = $package->container(); |
| 92 |
// IZET-356, looks like there is no good built-in hook in WP for plugin upgrades |
| 93 |
$version = $container->get('paypal-pos.plugin.properties')->version(); |
| 94 |
$versionOptionName = $container->get('paypal-pos.version-option-key'); |
| 95 |
if (get_option($versionOptionName) !== $version) { |
| 96 |
do_action('paypal-point-of-sale.migrate'); |
| 97 |
update_option($versionOptionName, $version); |
| 98 |
} |
| 99 |
}); |
| 100 |
register_activation_hook(__FILE__, static function (): void { |
| 101 |
init(); |
| 102 |
do_action('paypal-point-of-sale.activate'); |
| 103 |
}); |
| 104 |
register_deactivation_hook(__FILE__, static function (): void { |
| 105 |
init(); |
| 106 |
do_action('paypal-point-of-sale.deactivate'); |
| 107 |
}); |
| 108 |
add_action('before_woocommerce_init', static function () { |
| 109 |
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) { |
| 110 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, \true); |
| 111 |
} |
| 112 |
}); |
| 113 |
})(); |
| 114 |
|