diff --git a/.distignore b/.distignore new file mode 100644 index 0000000..c68c2cf --- /dev/null +++ b/.distignore @@ -0,0 +1,32 @@ +/.wordpress-org +/.git +/.github +/node_modules +/tests +/languages/*-backup-* +/.vscode +.editorconfig +.distignore +.gitignore +Dockerfile-cron +Dockerfile-wpdebug-php7 +Dockerfile-wpdebug-php8 +DOCKER_ENV +docker_tag +output.log +readme.md +README.md +gulpfile.js +package.json +package-lock.json +docker-compose.phpunit.yml +docker-compose.yml +Dockerfile +readme.dev.txt +README.md +phpcs.ruleset.xml +phpunit-docker.xml +phpunit.xml +phpcs.xml +renovate.json +wpcron.txt \ No newline at end of file diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..435f18f --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,29 @@ +name: Build and deploy to WordPress.org +on: + release: + types: [published] +jobs: + tag: + name: New tag + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@main + + # Install all composer dependencies for the plugin. + - name: Install Composer dependencies + uses: php-actions/composer@v6 + with: + dev: no + php_version: 7.4 + + # Deploy the plugin to WordPress.org + - name: WordPress Plugin Deploy + id: deploy + uses: 10up/action-wordpress-plugin-deploy@stable + with: + generate-zip: true + env: + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + SLUG: ledyer-order-management-for-woocommerce \ No newline at end of file diff --git a/classes/class-ledyer-om-main.php b/classes/class-ledyer-om-main.php index 3bcad13..7b7a5d6 100644 --- a/classes/class-ledyer-om-main.php +++ b/classes/class-ledyer-om-main.php @@ -8,7 +8,6 @@ namespace LedyerOm; - \defined( 'ABSPATH' ) || die(); class Ledyer_Order_Management_For_WooCommerce { @@ -18,16 +17,17 @@ class Ledyer_Order_Management_For_WooCommerce { public $parentSettings; public $api; - const VERSION = '1.5.0'; - const SLUG = 'ledyer-order-management-for-woocommerce'; + const VERSION = '1.5.1'; + const SLUG = 'ledyer-order-management-for-woocommerce'; const SETTINGS = 'ledyer_order_management_for_woocommerce_settings'; /** * Summary of actions - called from class-ledyer-om-singleton.php + * * @return void */ public function actions() { - add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ] ); + add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) ); // Add refunds support to Ledyer Payments and Ledyer Checkout gateways. add_action( 'wc_ledyer_payments_supports', array( $this, 'add_gateway_support' ) ); @@ -36,60 +36,66 @@ public function actions() { // Capture an order -> lom-capture.php add_action( 'woocommerce_order_status_completed', - function ($order_id, $action = false) { - lom_capture_ledyer_order($order_id, $action, $this->api); + function ( $order_id, $action = false ) { + lom_capture_ledyer_order( $order_id, $action, $this->api ); } ); // Listen to refund from Ledyer Checkout for Woocommerce, then call lom_refund_ledyer_order -> lom-refund.php add_filter( 'wc_ledyer_checkout_process_refund', - function ($result, $order_id, $amount, $reason) { - return lom_refund_ledyer_order($order_id, $amount, $this->api); + function ( $result, $order_id, $amount, $reason ) { + return lom_refund_ledyer_order( $order_id, $amount, $this->api ); }, - 10, 4); + 10, + 4 + ); // Listen to refund from Ledyer Payments for Woocommerce, then call lom_refund_ledyer_order -> lom-refund.php add_filter( 'wc_ledyer_payments_process_refund', - function ($result, $order_id, $amount, $reason) { - return lom_refund_ledyer_order($order_id, $amount, $this->api); + function ( $result, $order_id, $amount, $reason ) { + return lom_refund_ledyer_order( $order_id, $amount, $this->api ); }, - 10, 4); + 10, + 4 + ); // Cancel an order -> lom-cancel.php add_action( 'woocommerce_order_status_cancelled', - function ($order_id, $action = false) { - lom_cancel_ledyer_order($order_id, $action, $this->api); + function ( $order_id, $action = false ) { + lom_cancel_ledyer_order( $order_id, $action, $this->api ); } ); // Sync order items and totals add_action( 'woocommerce_saved_order_items', - function ($order_id, $action = false) { - lom_edit_ledyer_order($order_id, $action, $this->api, "order"); + function ( $order_id, $action = false ) { + lom_edit_ledyer_order( $order_id, $action, $this->api, 'order' ); } ); // Sync customer details such as shipping and billing add_action( 'woocommerce_process_shop_order_meta', - function ($order_id, $action = false) { + function ( $order_id, $action = false ) { - if (!is_admin()) { + if ( ! is_admin() ) { return; } - lom_edit_ledyer_order($order_id, $action, $this->api, "customer"); - }, 55, 1 // Priority higher than 50, since that is the priority we use to save the fields after validation is done. We don't want to sync with Ledyer if local Woo validation of the fields fail. + lom_edit_ledyer_order( $order_id, $action, $this->api, 'customer' ); + }, + 55, + 1 // Priority higher than 50, since that is the priority we use to save the fields after validation is done. We don't want to sync with Ledyer if local Woo validation of the fields fail. ); } /** * Adds plugin action link to Ledyer documentation for LOM. * - * @param array $links Plugin action link before filtering. + * @param array $links Plugin action link before filtering. * * @return array Filtered links. */ @@ -122,11 +128,11 @@ public function on_plugins_loaded() { $this->include_files(); $this->set_settings(); - $this->credentials = Credentials::instance(); - $this->parentSettings = ParentSettings::instance(); - $this->api = new API(); + $this->credentials = Credentials::instance(); + $this->parentSettings = ParentSettings::instance(); + $this->api = new API(); - add_filter( 'plugin_action_links_' . plugin_basename( LOM_WC_MAIN_FILE ), array($this, 'plugin_action_links')); + add_filter( 'plugin_action_links_' . plugin_basename( LOM_WC_MAIN_FILE ), array( $this, 'plugin_action_links' ) ); } /** @@ -173,7 +179,5 @@ public function include_files() { include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-cancel-order.php'; include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-edit-order.php'; include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-edit-customer.php'; - - } } diff --git a/composer.json b/composer.json index 90e0639..f059c2d 100644 --- a/composer.json +++ b/composer.json @@ -2,5 +2,20 @@ "_note_": "using an older version of brick/money to support from PHP 7.1 and greater", "require": { "brick/money": "0.5.3" - } + }, + "require-dev": { + "php-stubs/wordpress-stubs": "*", + "php-stubs/woocommerce-stubs": "dev-master", + "wp-coding-standards/wpcs": "^3.1" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + "scripts": { + "install-codestandards": [ + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" + ] + } } diff --git a/composer.lock b/composer.lock index 5524959..46a8857 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "55a75bcd13273aaf086e381147473f31", + "content-hash": "ae7a31732b23e12b7e1bb59f3084198e", "packages": [ { "name": "brick/math", @@ -128,10 +128,495 @@ "time": "2021-10-10T11:59:43+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "php-stubs/woocommerce-stubs", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/woocommerce-stubs.git", + "reference": "2f5be3f363ff3d02b4e29404c7895d9d15fd3e73" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/2f5be3f363ff3d02b4e29404c7895d9d15fd3e73", + "reference": "2f5be3f363ff3d02b4e29404c7895d9d15fd3e73", + "shasum": "" + }, + "require": { + "php-stubs/wordpress-stubs": "^5.3 || ^6.0" + }, + "require-dev": { + "php": "~7.1 || ~8.0", + "php-stubs/generator": "^0.8.0" + }, + "suggest": { + "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "default-branch": true, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WooCommerce function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/woocommerce-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "woocommerce", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", + "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v8.9.1" + }, + "time": "2024-05-21T11:47:54+00:00" + }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v6.5.3", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "e611a83292d02055a25f83291a98fadd0c21e092" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/e611a83292d02055a25f83291a98fadd0c21e092", + "reference": "e611a83292d02055a25f83291a98fadd0c21e092", + "shasum": "" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "nikic/php-parser": "^4.13", + "php": "^7.4 || ~8.0.0", + "php-stubs/generator": "^0.8.3", + "phpdocumentor/reflection-docblock": "5.3", + "phpstan/phpstan": "^1.10.49", + "phpunit/phpunit": "^9.5", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.11" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.5.3" + }, + "time": "2024-05-08T02:12:31+00:00" + }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "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": "2023-12-08T16:49:07+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.12", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/87b233b00daf83fb70f40c9a28692be017ea7c6c", + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.10.0 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "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-05-20T13:34:27+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.10.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "8f90f7a53ce271935282967f53d0894f8f1ff877" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/8f90f7a53ce271935282967f53d0894f8f1ff877", + "reference": "8f90f7a53ce271935282967f53d0894f8f1ff877", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "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/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "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" + }, + "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-05-22T21:24:41+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.2.1", + "phpcsstandards/phpcsutils": "^1.0.10", + "squizlabs/php_codesniffer": "^3.9.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/php_codesniffer", + "type": "custom" + } + ], + "time": "2024-03-25T16:39:00+00:00" + } + ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "php-stubs/woocommerce-stubs": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/includes/lom-cancel.php b/includes/lom-cancel.php index 8b6e2e3..c637c7a 100644 --- a/includes/lom-cancel.php +++ b/includes/lom-cancel.php @@ -5,74 +5,73 @@ /** * Cancel a Ledyer order. * - * @param int $order_id Order ID. - * @param bool $action If this was triggered by an action. + * @param int $order_id Order ID. + * @param bool $action If this was triggered by an action. * @param $api The lom api instance */ -function lom_cancel_ledyer_order($order_id, $action = false, $api) { - $options = get_option('lom_settings'); +function lom_cancel_ledyer_order( $order_id, $action = false, $api ) { + $options = get_option( 'lom_settings' ); - // If the cancel is not enabled in lom-settings - if ('no' === $options['lom_auto_cancel']) { - return; - } + // If the cancel is not enabled in lom-settings + if ( 'no' === $options['lom_auto_cancel'] ) { + return; + } - $order = wc_get_order($order_id); + $order = wc_get_order( $order_id ); - // Only support Ledyer orders - $is_ledyer_order = lom_order_placed_with_ledyer($order->get_payment_method()); - if (!$is_ledyer_order) { - return; - } + // Only support Ledyer orders + $is_ledyer_order = lom_order_placed_with_ledyer( $order->get_payment_method() ); + if ( ! $is_ledyer_order ) { + return; + } - // Do nothing if Ledyer order has already been cancelled - if ($order->get_meta('_wc_ledyer_cancelled', true)) { - $order->add_order_note('Ledyer order has already been cancelled.'); - $order->save(); - return; - } + // Do nothing if Ledyer order has already been cancelled + if ( $order->get_meta( '_wc_ledyer_cancelled', true ) ) { + $order->add_order_note( 'Ledyer order has already been cancelled.' ); + $order->save(); + return; + } - $ledyer_order_id = $order->get_meta( '_wc_ledyer_order_id', true); + $ledyer_order_id = $order->get_meta( '_wc_ledyer_order_id', true ); - // Do nothing if we don't have Ledyer order ID. - if (!$ledyer_order_id && !$order->get_meta('_transaction_id', true)) { - $errmsg = 'Ledyer order ID is missing, Ledyer order could not be cancelled at this time.'; - $order->add_order_note($errmsg); - $order->save(); - return; - } + // Do nothing if we don't have Ledyer order ID. + if ( ! $ledyer_order_id && ! $order->get_meta( '_transaction_id', true ) ) { + $errmsg = 'Ledyer order ID is missing, Ledyer order could not be cancelled at this time.'; + $order->add_order_note( $errmsg ); + $order->save(); + return; + } - // Fetch the ledyer order - $ledyer_order = $api->get_order($ledyer_order_id); + // Fetch the ledyer order + $ledyer_order = $api->get_order( $ledyer_order_id ); - if (is_wp_error($ledyer_order)) { - $errmsg = 'Ledyer order could not be cancelled due to an error: ' . $ledyer_order->get_error_message(); - $order->add_order_note($errmsg); - $order->save(); - return; - } + if ( is_wp_error( $ledyer_order ) ) { + $errmsg = 'Ledyer order could not be cancelled due to an error: ' . $ledyer_order->get_error_message(); + $order->add_order_note( $errmsg ); + $order->save(); + return; + } - if ($ledyer_order['uncaptured'] == null) { - $order->add_order_note('Ledyer order can not be cancelled because it has already been captured'); - $order->save(); - return; - } else if (in_array(LedyerOmOrderStatus::cancelled, $ledyer_order['status'])) { - $order->add_order_note('Ledyer order has already been cancelled'); - $order->save(); - return; - } + if ( $ledyer_order['uncaptured'] == null ) { + $order->add_order_note( 'Ledyer order can not be cancelled because it has already been captured' ); + $order->save(); + return; + } elseif ( in_array( LedyerOmOrderStatus::cancelled, $ledyer_order['status'] ) ) { + $order->add_order_note( 'Ledyer order has already been cancelled' ); + $order->save(); + return; + } - $response = $api->cancel_order($ledyer_order_id); + $response = $api->cancel_order( $ledyer_order_id ); - if (!is_wp_error($response)) { - $order->add_order_note('Ledyer order cancelled.'); - $order->update_meta('_wc_ledyer_cancelled', 'yes'); - $order->save(); - return; - } + if ( ! is_wp_error( $response ) ) { + $order->add_order_note( 'Ledyer order cancelled.' ); + $order->update_meta_data( '_wc_ledyer_cancelled', 'yes' ); + $order->save(); + return; + } - $errmsg = 'Ledyer order could not be cancelled due to an error: ' . $response->get_error_message(); - $order->add_order_note($errmsg); - $order->save(); + $errmsg = 'Ledyer order could not be cancelled due to an error: ' . $response->get_error_message(); + $order->add_order_note( $errmsg ); + $order->save(); } - diff --git a/includes/lom-capture.php b/includes/lom-capture.php index 88f2fe5..ce14b1e 100644 --- a/includes/lom-capture.php +++ b/includes/lom-capture.php @@ -5,100 +5,103 @@ /** * Captures a Ledyer order. * - * @param int $order_id Order ID. - * @param bool $action If this was triggered by an action. + * @param int $order_id Order ID. + * @param bool $action If this was triggered by an action. * @param $api The lom api instance */ - function lom_capture_ledyer_order($order_id, $action = false, $api) { - $options = get_option( 'lom_settings' ); - // If the capture on complete is not enabled in lom-settings - if ( 'no' === $options['lom_auto_capture']) { - return; - } +function lom_capture_ledyer_order( $order_id, $action = false, $api ) { + $options = get_option( 'lom_settings', array() ); + $auto_capture = $options['lom_auto_capture'] ?? 'yes'; + $lom_status_mapping_ledyer_error = $options['lom_status_mapping_ledyer_error'] ?? 'wc-on-hold'; + + // If the capture on complete is not enabled in lom-settings. + if ( 'no' === $auto_capture ) { + return; + } - $order = wc_get_order( $order_id ); + $order = wc_get_order( $order_id ); - // Check if the order has been paid. - if ( empty( $order->get_date_paid() ) ) { - return; - } + // Check if the order has been paid. + if ( empty( $order->get_date_paid() ) ) { + return; + } - // Only support Ledyer orders - $is_ledyer_order = lom_order_placed_with_ledyer($order->get_payment_method()); - if (! $is_ledyer_order) { - return; - } + // Only support Ledyer orders + $is_ledyer_order = lom_order_placed_with_ledyer( $order->get_payment_method() ); + if ( ! $is_ledyer_order ) { + return; + } - // Do nothing if Ledyer order was already captured according to the woo-order - if ( $order->get_meta( '_wc_ledyer_capture_id', true ) ) { - $order->add_order_note( 'Ledyer order has already been captured.' ); - $order->save(); - return; - } + // Do nothing if Ledyer order was already captured according to the woo-order + if ( $order->get_meta( '_wc_ledyer_capture_id', true ) ) { + $order->add_order_note( 'Ledyer order has already been captured.' ); + $order->save(); + return; + } - $ledyer_order_id = $order->get_meta( '_wc_ledyer_order_id', true); - - // Do nothing if we don't have Ledyer order ID. - if ( $ledyer_order_id && ! $order->get_meta( '_transaction_id', true )) { - $errmsg = 'Ledyer order ID is missing, Ledyer order could not be captured at this time.'; - if ( 'none' !== $options['lom_status_mapping_ledyer_error'] ) { - $order->update_status( $options['lom_status_mapping_ledyer_error'], $errmsg ); - } else { - $order->add_order_note( $errmsg ); - } - $order->save(); - return; - } + $ledyer_order_id = $order->get_meta( '_wc_ledyer_order_id', true ); - // Fetch the ledyer order - $ledyer_order = $api->get_order($ledyer_order_id); - - if ( is_wp_error( $ledyer_order ) ) { - $errmsg = 'Ledyer order could not be captured due to an error: ' . $ledyer_order->get_error_message(); - if ( 'none' !== $options['lom_status_mapping_ledyer_error'] ) { - $order->update_status( $options['lom_status_mapping_ledyer_error'], $errmsg ); - } else { - $order->add_order_note( $errmsg ); - } - $order->save(); - return; + // Do nothing if we don't have Ledyer order ID. + if ( $ledyer_order_id && ! $order->get_meta( '_transaction_id', true ) ) { + $errmsg = 'Ledyer order ID is missing, Ledyer order could not be captured at this time.'; + if ( 'none' !== $lom_status_mapping_ledyer_error ) { + $order->update_status( $lom_status_mapping_ledyer_error, $errmsg ); + } else { + $order->add_order_note( $errmsg ); } + $order->save(); + return; + } - if (in_array( LedyerOmOrderStatus::fullyCaptured, $ledyer_order['status'])) { - $first_captured = lom_get_first_captured($ledyer_order); - $captured_at = $first_captured['createdAt']; - $formatted_capture_at = date("Y-m-d H:i:s", strtotime($captured_at)); - $capture_id = $first_captured['ledgerId']; - - $order->add_order_note( 'Ledyer order has already been captured on ' . $formatted_capture_at ); - $order->update_meta_data( '_wc_ledyer_capture_id', $capture_id ); - $order->save(); - return; - } else if (in_array( LedyerOmOrderStatus::cancelled, $ledyer_order['status'] )) { - $order->add_order_note( 'Ledyer order failed to capture, the order has already been cancelled' ); - $order->save(); - return; + // Fetch the ledyer order + $ledyer_order = $api->get_order( $ledyer_order_id ); + + if ( is_wp_error( $ledyer_order ) ) { + $errmsg = 'Ledyer order could not be captured due to an error: ' . $ledyer_order->get_error_message(); + if ( 'none' !== $lom_status_mapping_ledyer_error ) { + $order->update_status( $lom_status_mapping_ledyer_error, $errmsg ); + } else { + $order->add_order_note( $errmsg ); } + $order->save(); + return; + } - $orderMapper = new \LedyerOm\OrderMapper($order); - $data = $orderMapper->woo_to_ledyer_capture_order_lines(); - $response = $api->capture_order($ledyer_order_id, $data); + if ( in_array( LedyerOmOrderStatus::fullyCaptured, $ledyer_order['status'] ) ) { + $first_captured = lom_get_first_captured( $ledyer_order ); + $captured_at = $first_captured['createdAt']; + $formatted_capture_at = date( 'Y-m-d H:i:s', strtotime( $captured_at ) ); + $capture_id = $first_captured['ledgerId']; + + $order->add_order_note( 'Ledyer order has already been captured on ' . $formatted_capture_at ); + $order->update_meta_data( '_wc_ledyer_capture_id', $capture_id ); + $order->save(); + return; + } elseif ( in_array( LedyerOmOrderStatus::cancelled, $ledyer_order['status'] ) ) { + $order->add_order_note( 'Ledyer order failed to capture, the order has already been cancelled' ); + $order->save(); + return; + } - if (!is_wp_error($response)) { - $first_captured = lom_get_first_captured($response); - $capture_id = $first_captured['ledgerId']; + $orderMapper = new \LedyerOm\OrderMapper( $order ); + $data = $orderMapper->woo_to_ledyer_capture_order_lines(); + $response = $api->capture_order( $ledyer_order_id, $data ); - $order->add_order_note( 'Ledyer order captured. Capture amount: ' . $order->get_formatted_order_total( '', false ) . '. Capture ID: ' . $capture_id ); - $order->update_meta_data('_wc_ledyer_capture_id', $capture_id, true); - $order->save(); - return; - } + if ( ! is_wp_error( $response ) ) { + $first_captured = lom_get_first_captured( $response ); + $capture_id = $first_captured['ledgerId']; - $errmsg = 'Ledyer order could not be captured due to an error: ' . $response->get_error_message(); - if ( 'none' !== $options['lom_status_mapping_ledyer_error'] ) { - $order->update_status( $options['lom_status_mapping_ledyer_error'], $errmsg ); - } else { - $order->add_order_note( $errmsg ); - } - $order->save(); + $order->add_order_note( 'Ledyer order captured. Capture amount: ' . $order->get_formatted_order_total( '', false ) . '. Capture ID: ' . $capture_id ); + $order->update_meta_data( '_wc_ledyer_capture_id', $capture_id, true ); + $order->save(); + return; + } + + $errmsg = 'Ledyer order could not be captured due to an error: ' . $response->get_error_message(); + if ( 'none' !== $lom_status_mapping_ledyer_error ) { + $order->update_status( $lom_status_mapping_ledyer_error, $errmsg ); + } else { + $order->add_order_note( $errmsg ); } + $order->save(); +} diff --git a/ledyer-order-management-for-woocommerce.php b/ledyer-order-management-for-woocommerce.php index 3302a92..2fedff0 100644 --- a/ledyer-order-management-for-woocommerce.php +++ b/ledyer-order-management-for-woocommerce.php @@ -5,7 +5,7 @@ * Description: Ledyer Order Management for WooCommerce. * Author: Ledyer AB * Author URI: https://www.ledyer.com - * Version: 1.5.0 + * Version: 1.5.1 * Text Domain: ledyer-order-management-for-woocommerce * Domain Path: /languages * @@ -48,12 +48,12 @@ // Declare HPOS compatibility. add_action( - 'before_woocommerce_init', - function () { - if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { - \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); - } - } + 'before_woocommerce_init', + function () { + if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); + } + } ); function ledyerOm() { diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..a5efd00 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,37 @@ + + + WooCommerce dev PHP_CodeSniffer ruleset. + + + */node_modules/* + */vendor/* + + + tests/* + + + build/* + + + *\.(css|js) + + + + + + + + + + + + + + + + + + . + + + \ No newline at end of file diff --git a/readme.txt b/readme.txt index 0f5f9dc..4a558fd 100644 --- a/readme.txt +++ b/readme.txt @@ -3,10 +3,15 @@ Contributors: ledyer Tags: woocommerce, ledyer, ecommerce, e-commerce, order-management Donate link: https://ledyer.com Requires at least: 4.0 -Tested up to: 6.2 -Requires PHP: 7.0 -WC requires at least: 4.0.0 -WC tested up to: 6.9.3 -Stable tag: 1.5.0 +Tested up to: 6.5.4 +Requires PHP: 7.4 +WC requires at least: 5.0.0 +WC tested up to: 8.9.2 +Stable tag: 1.5.1 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html + +== Changelog == += 2024.06.10 - version 1.5.1 = +* Fix - Fix error that could be triggered on cancel order request. +* Fix - Set failed request order status correct even if plugin settings never have been saved. \ No newline at end of file