diff --git a/.distignore b/.distignore index 135763c5..2ef36687 100644 --- a/.distignore +++ b/.distignore @@ -18,4 +18,11 @@ Dockerfile readme.dev.txt phpcs.ruleset.xml phpunit-docker.xml -phpunit.xml \ No newline at end of file +phpunit.xml +composer-dependencies.json +composer-dependencies.lock +composer.json +composer.lock +/vendor +/tmp* +scoper.custom.php \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 73304e03..d5807c7d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,16 +2,25 @@ name: Deploy to WordPress.org on: push: tags: - - "*" + - "*" jobs: tag: name: New tag runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - name: WordPress Plugin Deploy - uses: 10up/action-wordpress-plugin-deploy@master - env: - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} - SLUG: klarna-checkout-for-woocommerce \ No newline at end of file + # Build the plugin with dev dependencies to scope the dependency packages. + - name: Composer Install (Dev) + run: composer install + + # Build the plugin for release. + - name: Composer Install (Prod) + run: composer install --no-dev + + # Deploy the plugin to WordPress.org. + - uses: actions/checkout@master + - name: WordPress Plugin Deploy + uses: 10up/action-wordpress-plugin-deploy@master + env: + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + SLUG: klarna-checkout-for-woocommerce diff --git a/.gitignore b/.gitignore index 0923bcb9..893b21c1 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,8 @@ nightwatch.conf.js .vscode/settings.json .idea/ +# wpify/scoper +/vendor/ +/dependencies/* +!dependencies/.gitkeep +tmp* diff --git a/composer-dependencies.json b/composer-dependencies.json new file mode 100644 index 00000000..2418a42f --- /dev/null +++ b/composer-dependencies.json @@ -0,0 +1,24 @@ +{ + "require": { + "krokedil/klarna-onsite-messaging": "^1.0.0" + }, + "repositories": [ + { + "type": "vcs", + "url": "git@github.com:krokedil/klarna-onsite-messaging.git" + } + ], + "config": { + "platform": { + "php": "7.4" + }, + "allow-plugins": { + "wpify/scoper": true + }, + "scripts": { + "wpify-scoper": "wpify-scoper" + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} \ No newline at end of file diff --git a/composer-dependencies.lock b/composer-dependencies.lock new file mode 100644 index 00000000..21f684a1 --- /dev/null +++ b/composer-dependencies.lock @@ -0,0 +1,93 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "d8005cfc348a7e59d79e0794919d4917", + "packages": [ + { + "name": "krokedil/klarna-onsite-messaging", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/krokedil/klarna-onsite-messaging.git", + "reference": "c864c0eb2a7fd8ccd57f7fa845219bcf72a88a2c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/krokedil/klarna-onsite-messaging/zipball/c864c0eb2a7fd8ccd57f7fa845219bcf72a88a2c", + "reference": "c864c0eb2a7fd8ccd57f7fa845219bcf72a88a2c", + "shasum": "" + }, + "require": { + "php": "~7.4 || ~8.0" + }, + "require-dev": { + "10up/wp_mock": "^1.0", + "php-stubs/woocommerce-stubs": "^8.3", + "wp-coding-standards/wpcs": "^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Krokedil\\KlarnaOnsiteMessaging\\": "src/" + } + }, + "archive": { + "exclude": [ + "tests/*", + "phpunit.xml", + "composer-lock.json", + ".github/*", + ".gitignore", + ".gitattributes" + ] + }, + "scripts": { + "phpcs": [ + "phpcs --standard=phpcs.xml --extensions=php --ignore=vendor/,tests/" + ], + "phpcbf": [ + "phpcbf --standard=phpcs.xml --extensions=php --ignore=vendor/,tests/" + ], + "test": [ + "@php ./vendor/bin/phpunit --configuration phpunit.xml" + ], + "test-coverage-html": [ + "@php ./vendor/bin/phpunit --configuration phpunit.xml --coverage-html coverage" + ], + "test-coverage-clover": [ + "@php ./vendor/bin/phpunit --configuration phpunit.xml --coverage-clover coverage.xml" + ] + }, + "license": [ + "GPL-v3" + ], + "authors": [ + { + "name": "Krokedil AB", + "email": "info@krokedil.se" + } + ], + "description": "Klarna On-Site Messaging for WooCommerce", + "support": { + "source": "https://github.com/krokedil/klarna-onsite-messaging/tree/1.2.0", + "issues": "https://github.com/krokedil/klarna-onsite-messaging/issues" + }, + "time": "2024-09-11T09:30:15+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "platform-overrides": { + "php": "7.4" + }, + "plugin-api-version": "2.6.0" +} diff --git a/composer.json b/composer.json index 686dc9ef..41d47dc2 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,25 @@ { "require-dev": { - "wp-coding-standards/wpcs": "^2.3" + "wp-coding-standards/wpcs": "^2.3", + "wpify/scoper": "3.1.3" + }, + "config": { + "allow-plugins": { + "wpify/scoper": true + }, + "platform": { + "php": "7.4" + } + }, + "extra": { + "wpify-scoper": { + "prefix": "KrokedilKCODeps", + "folder": "dependencies", + "autorun": true, + "globals": [ + "wordpress", + "woocommerce" + ] + } } -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 424bc08e..a8d75969 100644 --- a/composer.lock +++ b/composer.lock @@ -4,21 +4,21 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "93e09194408acf7c385f20b3ead4958d", + "content-hash": "c5d31c20c8e96b276c0082df69ba007c", "packages": [], "packages-dev": [ { "name": "squizlabs/php_codesniffer", - "version": "3.6.1", + "version": "3.10.2", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e" + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/f268ca40d54617c6e06757f83f699775c9b3ff2e", - "reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/86e5f5dd9a840c46810ebe5ff1885581c42a3017", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017", "shasum": "" }, "require": { @@ -28,11 +28,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -47,21 +47,45 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, - "time": "2021-10-11T04:00:11+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-07-21T23:26:44+00:00" }, { "name": "wp-coding-standards/wpcs", @@ -113,6 +137,106 @@ "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, "time": "2020-05-13T23:57:56+00:00" + }, + { + "name": "wpify/php-scoper", + "version": "0.16.2", + "source": { + "type": "git", + "url": "https://github.com/wpify/php-scoper.git", + "reference": "ea51e75cee3a2ff2ac1aedb1b3c0631147360149" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wpify/php-scoper/zipball/ea51e75cee3a2ff2ac1aedb1b3c0631147360149", + "reference": "ea51e75cee3a2ff2ac1aedb1b3c0631147360149", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "bin": [ + "bin/php-scoper.phar" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "authors": [ + { + "name": "mejta", + "email": "daniel@mejta.net" + } + ], + "support": { + "issues": "https://github.com/wpify/php-scoper/issues", + "source": "https://github.com/wpify/php-scoper/tree/0.16.2" + }, + "time": "2023-11-01T18:00:51+00:00" + }, + { + "name": "wpify/scoper", + "version": "3.1.3", + "source": { + "type": "git", + "url": "https://github.com/wpify/scoper.git", + "reference": "bac861226cbb4d674213c89a63f7b79570033b31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wpify/scoper/zipball/bac861226cbb4d674213c89a63f7b79570033b31", + "reference": "bac861226cbb4d674213c89a63f7b79570033b31", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.3", + "php": "^7.4 || ^8.0", + "wpify/php-scoper": "^0.16" + }, + "require-dev": { + "composer/composer": "^2.6", + "jetbrains/phpstorm-stubs": "^v2023.2", + "johnpbloch/wordpress": "^6.3", + "nikic/php-parser": "^v4.17", + "woocommerce/action-scheduler": "^3.6", + "wpackagist-plugin/woocommerce": "^8.2", + "yahnis-elsts/plugin-update-checker": "^v5.2" + }, + "type": "composer-plugin", + "extra": { + "class": "Wpify\\Scoper\\Plugin", + "wordpress-install-dir": "sources/wordpress", + "installer-paths": { + "sources/plugin-{$name}/": [ + "type:wordpress-plugin" + ], + "sources/theme-{$name}/": [ + "type:wordpress-theme" + ] + }, + "textdomain": { + "wpify-custom-fields": "some-new-textdomain" + } + }, + "autoload": { + "psr-4": { + "Wpify\\Scoper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Daniel Mejta", + "email": "daniel@mejta.net" + } + ], + "description": "Composer plugin that scopes WordPress and WooCommerce dependencies for usage in WordPress plugins and themes.", + "support": { + "issues": "https://github.com/wpify/scoper/issues", + "source": "https://github.com/wpify/scoper/tree/3.1.3" + }, + "time": "2023-11-02T15:10:42+00:00" } ], "aliases": [], @@ -122,5 +246,8 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.1.0" + "platform-overrides": { + "php": "7.4" + }, + "plugin-api-version": "2.6.0" } diff --git a/klarna-checkout-for-woocommerce.php b/klarna-checkout-for-woocommerce.php index 776d008d..1bb344ef 100644 --- a/klarna-checkout-for-woocommerce.php +++ b/klarna-checkout-for-woocommerce.php @@ -32,6 +32,8 @@ exit; } +use KrokedilKCODeps\Krokedil\KlarnaOnsiteMessaging\KlarnaOnsiteMessaging; + /** * Required minimums and constants */ @@ -146,9 +148,17 @@ protected function __construct() { * Init the plugin after plugins_loaded so environment variables are set. */ public function init() { + if ( ! $this->init_composer() ) { + return; + } + // Init the gateway itself. $this->init_gateways(); + $settings = get_option( 'woocommerce_kco_settings', array() ); + $kosm = new KlarnaOnsiteMessaging( $settings ); + add_filter( 'kco_wc_gateway_settings', array( $kosm->settings(), 'extend_settings' ) ); + // Declare HPOS compatibility. add_action( 'before_woocommerce_init', @@ -268,6 +278,53 @@ public function init_gateways() { add_action( 'before_woocommerce_init', array( $this, 'declare_wc_compatibility' ) ); } + /** + * Initialize composers autoloader. + * + * @return bool|mixed + */ + public function init_composer() { + $autoloader = KCO_WC_PLUGIN_PATH . '/dependencies/autoload.php'; + + if ( ! is_readable( $autoloader ) ) { + self::missing_autoloader(); + return false; + } + + $autoloader_result = require $autoloader; + if ( ! $autoloader_result ) { + self::missing_autoloader(); + return false; + } + + return $autoloader_result; + } + + /** + * Checks if the autoloader is missing and displays an admin notice. + * + * @return void + */ + protected static function missing_autoloader() { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( // phpcs:ignore + esc_html__( 'Your installation of Klarna Checkout is not complete. If you installed this plugin directly from Github please refer to the README.DEV.md file in the plugin.', 'klarna-checkout-for-woocommerce' ) + ); + } + add_action( + 'admin_notices', + function () { + ?> +
+ +
+