From 00440ad6ca7e1d525e23ed484a937d0bcde2bed5 Mon Sep 17 00:00:00 2001 From: timjackleus Date: Mon, 8 Jan 2024 12:40:47 +0100 Subject: [PATCH] fix: test this out instead --- .github/workflows/build.yml | 15 +- .prettierrc | 5 + classes/class-ledyer-om-api.php | 92 ++-- classes/class-ledyer-om-credentials.php | 70 +-- classes/class-ledyer-om-customer-mapper.php | 128 ++--- classes/class-ledyer-om-logger.php | 208 ++++---- classes/class-ledyer-om-main.php | 367 +++++++------- classes/class-ledyer-om-order-mapper.php | 508 +++++++++++--------- classes/class-ledyer-om-parent-settings.php | 74 +-- classes/class-ledyer-om-settings.php | 481 +++++++++--------- classes/class-ledyer-om-singleton.php | 100 ++-- includes/lom-cancel.php | 113 +++-- includes/lom-capture.php | 204 ++++---- includes/lom-edit.php | 133 ++--- includes/lom-functions.php | 14 +- includes/lom-refund.php | 88 ++-- includes/lom-types.php | 32 +- package-lock.json | 107 +++++ package.json | 16 + 19 files changed, 1552 insertions(+), 1203 deletions(-) create mode 100644 .prettierrc create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8ca009..06cc914 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,13 +9,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.10.0" + - name: NPM Install + run: npm ci + env: + CI: true - - name: run pretty-php - run: | - wget -O pretty-php.phar https://github.com/lkrms/pretty-php/releases/latest/download/pretty-php.phar - chmod +x pretty-php.phar - pretty-php **/*.php --check + - name: Lint + run: npm run format:check diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..815df78 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "plugins": ["@prettier/plugin-php"], + "useTabs": true, + "tabWidth": 2 +} diff --git a/classes/class-ledyer-om-api.php b/classes/class-ledyer-om-api.php index 5e6361a..bda2543 100644 --- a/classes/class-ledyer-om-api.php +++ b/classes/class-ledyer-om-api.php @@ -8,7 +8,7 @@ namespace LedyerOm; -\defined('ABSPATH') || die (); +\defined("ABSPATH") || die(); use LedyerOm\Requests\Order\Cancel_Order; use LedyerOm\Requests\Order\Capture_Order; @@ -26,48 +26,64 @@ */ class API { - /** - * @param $order_id - * - * @return mixed|\WP_Error - */ - public function get_payment_status($order_id) - { - return (new Payment_Status(array('orderId' => $order_id)))->request(); - } + /** + * @param $order_id + * + * @return mixed|\WP_Error + */ + public function get_payment_status($order_id) + { + return (new Payment_Status(["orderId" => $order_id]))->request(); + } - public function get_order($order_id) - { - return (new Get_Order(array('orderId' => $order_id)))->request(); - } + public function get_order($order_id) + { + return (new Get_Order(["orderId" => $order_id]))->request(); + } - public function capture_order($order_id, $data) - { - return (new Capture_Order(array('orderId' => $order_id, 'data' => $data)))->request(); - } + public function capture_order($order_id, $data) + { + return (new Capture_Order([ + "orderId" => $order_id, + "data" => $data, + ]))->request(); + } - public function refund_order($order_id, $ledger_id) - { - return (new Refund_Order(array('orderId' => $order_id, 'ledgerId' => $ledger_id)))->request(); - } + public function refund_order($order_id, $ledger_id) + { + return (new Refund_Order([ + "orderId" => $order_id, + "ledgerId" => $ledger_id, + ]))->request(); + } - public function partial_refund_order($order_id, $ledger_id, $data) - { - return (new Partial_Refund_Order(array('orderId' => $order_id, 'ledgerId' => $ledger_id, 'data' => $data)))->request(); - } + public function partial_refund_order($order_id, $ledger_id, $data) + { + return (new Partial_Refund_Order([ + "orderId" => $order_id, + "ledgerId" => $ledger_id, + "data" => $data, + ]))->request(); + } - public function cancel_order($order_id) - { - return (new Cancel_Order(array('orderId' => $order_id)))->request(); - } + public function cancel_order($order_id) + { + return (new Cancel_Order(["orderId" => $order_id]))->request(); + } - public function edit_order($order_id, $data) - { - return (new Edit_Order(array('orderId' => $order_id, 'data' => $data)))->request(); - } + public function edit_order($order_id, $data) + { + return (new Edit_Order([ + "orderId" => $order_id, + "data" => $data, + ]))->request(); + } - public function edit_customer($order_id, $data) - { - return (new Edit_Customer(array('orderId' => $order_id, 'data' => $data)))->request(); - } + public function edit_customer($order_id, $data) + { + return (new Edit_Customer([ + "orderId" => $order_id, + "data" => $data, + ]))->request(); + } } diff --git a/classes/class-ledyer-om-credentials.php b/classes/class-ledyer-om-credentials.php index a3e54b1..9a90c5a 100644 --- a/classes/class-ledyer-om-credentials.php +++ b/classes/class-ledyer-om-credentials.php @@ -8,7 +8,7 @@ namespace LedyerOm; -\defined('ABSPATH') || die (); +\defined("ABSPATH") || die(); /** * Credentials class. @@ -17,38 +17,38 @@ */ class Credentials { - use Singleton; - - /** - * Credentials constructor. - */ - public function set_settings() - { - // First try and get credentials from Ledyer checkout - self::$settings = get_option('woocommerce_lco_settings'); - // If that is not found, try and get from Ledyer Payments (to be developed) - } - - /** - * Gets Ledyer API credentials - * - * @return bool|array $credentials - */ - public function get_client_credentials() - { - $test_string = 'yes' === self::$settings['testmode'] ? 'test_' : ''; - $client_id = self::$settings[$test_string . 'merchant_id']; - $client_secret = self::$settings[$test_string . 'shared_secret']; - - if ('' === $client_id || '' === $client_secret) { - return false; - } - - $credentials = array( - 'client_id' => $client_id, - 'client_secret' => htmlspecialchars_decode($client_secret), - ); - - return $credentials; - } + use Singleton; + + /** + * Credentials constructor. + */ + public function set_settings() + { + // First try and get credentials from Ledyer checkout + self::$settings = get_option("woocommerce_lco_settings"); + // If that is not found, try and get from Ledyer Payments (to be developed) + } + + /** + * Gets Ledyer API credentials + * + * @return bool|array $credentials + */ + public function get_client_credentials() + { + $test_string = "yes" === self::$settings["testmode"] ? "test_" : ""; + $client_id = self::$settings[$test_string . "merchant_id"]; + $client_secret = self::$settings[$test_string . "shared_secret"]; + + if ("" === $client_id || "" === $client_secret) { + return false; + } + + $credentials = [ + "client_id" => $client_id, + "client_secret" => htmlspecialchars_decode($client_secret), + ]; + + return $credentials; + } } diff --git a/classes/class-ledyer-om-customer-mapper.php b/classes/class-ledyer-om-customer-mapper.php index afb5665..ecf131b 100644 --- a/classes/class-ledyer-om-customer-mapper.php +++ b/classes/class-ledyer-om-customer-mapper.php @@ -8,77 +8,77 @@ namespace LedyerOm; -defined('ABSPATH') || exit (); +defined("ABSPATH") || exit(); class CustomerMapper { - /** - * WooCommerce order. - * - * @var bool|WC_Order|WC_Order_Refund - */ - public $order; + /** + * WooCommerce order. + * + * @var bool|WC_Order|WC_Order_Refund + */ + public $order; - /** - * Customer mapper constructor. - * - * @param int $order WooCommerce order - */ - public function __construct($order) - { - $this->order = $order; - } + /** + * Customer mapper constructor. + * + * @param int $order WooCommerce order + */ + public function __construct($order) + { + $this->order = $order; + } - public function woo_to_ledyer_customer() - { - return array( - 'billingAddress' => $this->process_billing(), - 'shippingAddress' => $this->process_shipping(), - 'email' => $this->order->get_billing_email(), - 'phone' => $this->order->get_billing_phone(), - ); - } + public function woo_to_ledyer_customer() + { + return [ + "billingAddress" => $this->process_billing(), + "shippingAddress" => $this->process_shipping(), + "email" => $this->order->get_billing_email(), + "phone" => $this->order->get_billing_phone(), + ]; + } - private function process_billing() - { - $attentionName = $_REQUEST['_billing_attention_name']; - $careOf = $_REQUEST['_billing_care_of']; - return array( - 'companyName' => $this->order->get_billing_company(), - 'streetAddress' => $this->order->get_billing_address_1(), - 'postalCode' => $this->order->get_billing_postcode(), - 'city' => $this->order->get_billing_city(), - 'country' => $this->order->get_billing_country(), - 'attentionName' => !empty($attentionName) ? $attentionName : '', - 'careOf' => !empty($careOf) ? $careOf : '', - ); - } + private function process_billing() + { + $attentionName = $_REQUEST["_billing_attention_name"]; + $careOf = $_REQUEST["_billing_care_of"]; + return [ + "companyName" => $this->order->get_billing_company(), + "streetAddress" => $this->order->get_billing_address_1(), + "postalCode" => $this->order->get_billing_postcode(), + "city" => $this->order->get_billing_city(), + "country" => $this->order->get_billing_country(), + "attentionName" => !empty($attentionName) ? $attentionName : "", + "careOf" => !empty($careOf) ? $careOf : "", + ]; + } - private function process_shipping() - { - $attentionName = $_REQUEST['_shipping_attention_name']; - $careOf = $_REQUEST['_shipping_care_of']; + private function process_shipping() + { + $attentionName = $_REQUEST["_shipping_attention_name"]; + $careOf = $_REQUEST["_shipping_care_of"]; - return array( - 'companyName' => $this->order->get_shipping_company(), - 'streetAddress' => $this->order->get_shipping_address_1(), - 'postalCode' => $this->order->get_shipping_postcode(), - 'city' => $this->order->get_shipping_city(), - 'country' => $this->order->get_shipping_country(), - 'attentionName' => !empty($attentionName) ? $attentionName : '', - 'careOf' => !empty($careOf) ? $careOf : '', - 'contact' => $this->process_shipping_contact(), - ); - } + return [ + "companyName" => $this->order->get_shipping_company(), + "streetAddress" => $this->order->get_shipping_address_1(), + "postalCode" => $this->order->get_shipping_postcode(), + "city" => $this->order->get_shipping_city(), + "country" => $this->order->get_shipping_country(), + "attentionName" => !empty($attentionName) ? $attentionName : "", + "careOf" => !empty($careOf) ? $careOf : "", + "contact" => $this->process_shipping_contact(), + ]; + } - private function process_shipping_contact() - { - $shipping_email = $_REQUEST['_shipping_email']; - return array( - 'firstName' => $this->order->get_shipping_first_name(), - 'lastName' => $this->order->get_shipping_last_name(), - 'email' => !empty($shipping_email) ? $shipping_email : '', - 'phone' => $this->order->get_shipping_phone(), - ); - } + private function process_shipping_contact() + { + $shipping_email = $_REQUEST["_shipping_email"]; + return [ + "firstName" => $this->order->get_shipping_first_name(), + "lastName" => $this->order->get_shipping_last_name(), + "email" => !empty($shipping_email) ? $shipping_email : "", + "phone" => $this->order->get_shipping_phone(), + ]; + } } diff --git a/classes/class-ledyer-om-logger.php b/classes/class-ledyer-om-logger.php index e07bf71..2ca59b3 100644 --- a/classes/class-ledyer-om-logger.php +++ b/classes/class-ledyer-om-logger.php @@ -8,7 +8,7 @@ namespace LedyerOm; -defined('ABSPATH') || exit (); +defined("ABSPATH") || exit(); /** * Logger class. @@ -17,110 +17,120 @@ */ class Logger { - /** - * Log message string - * - * @var $log - */ - private static $log; + /** + * Log message string + * + * @var $log + */ + private static $log; - /** - * Logs an event. - * - * @param string $data The data string. - */ - public static function log($data) - { - $loggerEnabled = ledyerOm()->parentSettings->get_logger_enabled(); + /** + * Logs an event. + * + * @param string $data The data string. + */ + public static function log($data) + { + $loggerEnabled = ledyerOm()->parentSettings->get_logger_enabled(); - if ('yes' === $loggerEnabled) { - $message = self::format_data($data); - if (empty(self::$log)) { - self::$log = new \WC_Logger(); - } - $context = ['source' => 'ledyer-log']; - self::$log->log('debug', stripcslashes(wp_json_encode($message)), $context); - } - } + if ("yes" === $loggerEnabled) { + $message = self::format_data($data); + if (empty(self::$log)) { + self::$log = new \WC_Logger(); + } + $context = ["source" => "ledyer-log"]; + self::$log->log( + "debug", + stripcslashes(wp_json_encode($message)), + $context + ); + } + } - /** - * Formats the log data to prevent json error. - * - * @param string $data Json string of data. - * - * @return array - */ - public static function format_data($data) - { - if (isset($data['body'])) { - $data['body'] = json_decode($data['body'], true); - } + /** + * Formats the log data to prevent json error. + * + * @param string $data Json string of data. + * + * @return array + */ + public static function format_data($data) + { + if (isset($data["body"])) { + $data["body"] = json_decode($data["body"], true); + } - return $data; - } + return $data; + } - /** - * Formats the log data to be logged. - * - * @param string $ledyer_order_id The Ledyer order id. - * @param string $method The method. - * @param string $title The title for the log. - * @param array $request_args The request args. - * @param array $response The response. - * @param string $code The status code. - * - * @return array - */ - public static function format_log($ledyer_order_id, $method, $title, $request_args, $response, $code) - { - // Unset the snippet to prevent issues in the response. - if (isset($response['snippet'])) { - unset($response['snippet']); - } - // Unset the snippet to prevent issues in the request body. - if (isset($request_args['body'])) { - $request_body = json_decode($request_args['body'], true); - } + /** + * Formats the log data to be logged. + * + * @param string $ledyer_order_id The Ledyer order id. + * @param string $method The method. + * @param string $title The title for the log. + * @param array $request_args The request args. + * @param array $response The response. + * @param string $code The status code. + * + * @return array + */ + public static function format_log( + $ledyer_order_id, + $method, + $title, + $request_args, + $response, + $code + ) { + // Unset the snippet to prevent issues in the response. + if (isset($response["snippet"])) { + unset($response["snippet"]); + } + // Unset the snippet to prevent issues in the request body. + if (isset($request_args["body"])) { + $request_body = json_decode($request_args["body"], true); + } - return [ - 'id' => $ledyer_order_id, - 'type' => $method, - 'title' => $title, - 'request' => $request_args, - 'response' => [ - 'body' => $request_body ?? $response, - 'code' => $code, - ], - 'timestamp' => gmdate('Y-m-d H:i:s'), - // phpcs:ignore WordPress.DateTime.RestrictedFunctions -- Date is not used for display. - 'stack' => self::get_stack(), - 'plugin_version' => Ledyer_Order_Management_For_WooCommerce::VERSION, - ]; - } + return [ + "id" => $ledyer_order_id, + "type" => $method, + "title" => $title, + "request" => $request_args, + "response" => [ + "body" => $request_body ?? $response, + "code" => $code, + ], + "timestamp" => gmdate("Y-m-d H:i:s"), + // phpcs:ignore WordPress.DateTime.RestrictedFunctions -- Date is not used for display. + "stack" => self::get_stack(), + "plugin_version" => Ledyer_Order_Management_For_WooCommerce::VERSION, + ]; + } - /** - * Gets the stack for the request. - * - * @return array - */ - public static function get_stack() - { - $debug_data = debug_backtrace(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Data is not used for display. - $stack = []; - foreach ($debug_data as $data) { - $extra_data = ''; - if (!in_array($data['function'], ['get_stack', 'format_log'], true)) { - if (in_array($data['function'], ['do_action', 'apply_filters'], true)) { - if (isset($data['object'])) { - $priority = $data['object']->current_priority(); - $name = key($data['object']->current()); - $extra_data = $name . ' : ' . $priority; - } - } - } - $stack[] = $data['function'] . $extra_data; - } + /** + * Gets the stack for the request. + * + * @return array + */ + public static function get_stack() + { + $debug_data = debug_backtrace(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Data is not used for display. + $stack = []; + foreach ($debug_data as $data) { + $extra_data = ""; + if (!in_array($data["function"], ["get_stack", "format_log"], true)) { + if (in_array($data["function"], ["do_action", "apply_filters"], true)) { + if (isset($data["object"])) { + $priority = $data["object"]->current_priority(); + $name = key($data["object"]->current()); + $extra_data = $name . " : " . $priority; + } + } + } + $stack[] = $data["function"] . $extra_data; + } - return $stack; - } + return $stack; + } } diff --git a/classes/class-ledyer-om-main.php b/classes/class-ledyer-om-main.php index 62633ab..1de4794 100644 --- a/classes/class-ledyer-om-main.php +++ b/classes/class-ledyer-om-main.php @@ -9,177 +9,214 @@ namespace LedyerOm; -\defined('ABSPATH') || die (); +\defined("ABSPATH") || die(); class Ledyer_Order_Management_For_WooCommerce { - use Singleton; - - public $credentials; - public $parentSettings; - public $api; - - const VERSION = '1.5.0'; - 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 refunds support to Ledyer Payments and Ledyer Checkout gateways. - add_action('wc_ledyer_payments_supports', array($this, 'add_gateway_support')); - add_action('lco_wc_supports', array($this, 'add_gateway_support')); - - // 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); - } + use Singleton; + + public $credentials; + public $parentSettings; + public $api; + + const VERSION = "1.5.0"; + 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 refunds support to Ledyer Payments and Ledyer Checkout gateways. + add_action("wc_ledyer_payments_supports", [$this, "add_gateway_support"]); + add_action("lco_wc_supports", [$this, "add_gateway_support"]); + + // 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); + }); + + // 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( + $result, + $order_id, + $amount, + $reason, + $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($result, $order_id, $amount, $reason, $this->api); - }, - 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($result, $order_id, $amount, $reason, $this->api); - }, - 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); - } - ); - - // 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'); - } - ); - - // Sync customer details such as shipping and billing - add_action( - 'woocommerce_process_shop_order_meta', - function ($order_id, $action = false) { - 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. - ); - } - - /** - * Adds plugin action link to Ledyer documentation for LOM. - * - * @param array $links Plugin action link before filtering. - * - * @return array Filtered links. - */ - public function plugin_action_links($links) - { - $setting_link = $this->get_setting_link(); - $plugin_links = array( - '' . __('Settings', 'ledyer-order-management-for-woocommerce') . '', - 'Docs', + }, + 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( + $result, + $order_id, + $amount, + $reason, + $this->api ); - - return array_merge($plugin_links, $links); - } - - /** - * Return the proper link for the settings page of LOM. - * - * @return string The full settings page URL. - */ - protected function get_setting_link() - { - return admin_url('admin.php?page=lom-settings'); - } - - public function on_plugins_loaded() - { - if (!defined('WC_VERSION')) { - return; + }, + 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); + }); + + // 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"); + }); + + // Sync customer details such as shipping and billing + add_action( + "woocommerce_process_shop_order_meta", + function ($order_id, $action = false) { + if (!is_admin()) { + return; } - - require_once LOM_WC_PLUGIN_PATH . '/vendor/autoload.php'; - - $this->include_files(); - $this->set_settings(); - - $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')); + 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. + * + * @return array Filtered links. + */ + public function plugin_action_links($links) + { + $setting_link = $this->get_setting_link(); + $plugin_links = [ + '' . + __("Settings", "ledyer-order-management-for-woocommerce") . + "", + 'Docs', + ]; + + return array_merge($plugin_links, $links); + } + + /** + * Return the proper link for the settings page of LOM. + * + * @return string The full settings page URL. + */ + protected function get_setting_link() + { + return admin_url("admin.php?page=lom-settings"); + } + + public function on_plugins_loaded() + { + if (!defined("WC_VERSION")) { + return; } - /** - * Add refunds support to Ledyer Payments gateway. - * - * @param array $features Supported features. - * - * @return array $features Supported features. - */ - public function add_gateway_support($features) - { - $features[] = 'refunds'; - - return $features; - } - - public function include_files() - { - // includes - include_once LOM_WC_PLUGIN_PATH . '/includes/lom-functions.php'; - include_once LOM_WC_PLUGIN_PATH . '/includes/lom-types.php'; - include_once LOM_WC_PLUGIN_PATH . '/includes/lom-capture.php'; - include_once LOM_WC_PLUGIN_PATH . '/includes/lom-refund.php'; - include_once LOM_WC_PLUGIN_PATH . '/includes/lom-cancel.php'; - include_once LOM_WC_PLUGIN_PATH . '/includes/lom-edit.php'; - - // classes - include_once LOM_WC_PLUGIN_PATH . '/classes/class-ledyer-om-settings.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/class-ledyer-om-credentials.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/class-ledyer-om-parent-settings.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/class-ledyer-om-logger.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/class-ledyer-om-order-mapper.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/class-ledyer-om-customer-mapper.php'; - - // api - include_once LOM_WC_PLUGIN_PATH . '/classes/class-ledyer-om-api.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/requests/class-ledyer-om-request.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-order.php'; - - // api endpoints - include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-payment-status.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-get-order.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-capture-order.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-refund-order.php'; - include_once LOM_WC_PLUGIN_PATH . '/classes/requests/order/class-ledyer-om-request-partial-refund-order.php'; - 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'; - } + require_once LOM_WC_PLUGIN_PATH . "/vendor/autoload.php"; + + $this->include_files(); + $this->set_settings(); + + $this->credentials = Credentials::instance(); + $this->parentSettings = ParentSettings::instance(); + $this->api = new API(); + + add_filter("plugin_action_links_" . plugin_basename(LOM_WC_MAIN_FILE), [ + $this, + "plugin_action_links", + ]); + } + + /** + * Add refunds support to Ledyer Payments gateway. + * + * @param array $features Supported features. + * + * @return array $features Supported features. + */ + public function add_gateway_support($features) + { + $features[] = "refunds"; + + return $features; + } + + public function include_files() + { + // includes + include_once LOM_WC_PLUGIN_PATH . "/includes/lom-functions.php"; + include_once LOM_WC_PLUGIN_PATH . "/includes/lom-types.php"; + include_once LOM_WC_PLUGIN_PATH . "/includes/lom-capture.php"; + include_once LOM_WC_PLUGIN_PATH . "/includes/lom-refund.php"; + include_once LOM_WC_PLUGIN_PATH . "/includes/lom-cancel.php"; + include_once LOM_WC_PLUGIN_PATH . "/includes/lom-edit.php"; + + // classes + include_once LOM_WC_PLUGIN_PATH . "/classes/class-ledyer-om-settings.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/class-ledyer-om-credentials.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/class-ledyer-om-parent-settings.php"; + include_once LOM_WC_PLUGIN_PATH . "/classes/class-ledyer-om-logger.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/class-ledyer-om-order-mapper.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/class-ledyer-om-customer-mapper.php"; + + // api + include_once LOM_WC_PLUGIN_PATH . "/classes/class-ledyer-om-api.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/requests/class-ledyer-om-request.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/requests/order/class-ledyer-om-request-order.php"; + + // api endpoints + include_once LOM_WC_PLUGIN_PATH . + "/classes/requests/order/class-ledyer-om-request-payment-status.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/requests/order/class-ledyer-om-request-get-order.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/requests/order/class-ledyer-om-request-capture-order.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/requests/order/class-ledyer-om-request-refund-order.php"; + include_once LOM_WC_PLUGIN_PATH . + "/classes/requests/order/class-ledyer-om-request-partial-refund-order.php"; + 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/classes/class-ledyer-om-order-mapper.php b/classes/class-ledyer-om-order-mapper.php index 6960519..4af61d9 100644 --- a/classes/class-ledyer-om-order-mapper.php +++ b/classes/class-ledyer-om-order-mapper.php @@ -11,256 +11,318 @@ use Brick\Math\RoundingMode; use Brick\Money\Money; -defined('ABSPATH') || exit (); +defined("ABSPATH") || exit(); class OrderMapper { - /** - * Ledyer order lines. - * - * @var array - */ - public $ledyer_order_lines = array(); + /** + * Ledyer order lines. + * + * @var array + */ + public $ledyer_order_lines = []; - /** - * Ledyer order amount in minor units. - * - * @var integer - */ - public $ledyer_total_order_amount = 0; + /** + * Ledyer order amount in minor units. + * + * @var integer + */ + public $ledyer_total_order_amount = 0; - /** - * Ledyer order amount excl vat in minor units. - * - * @var integer - */ - public $ledyer_total_order_amount_excl_vat = 0; + /** + * Ledyer order amount excl vat in minor units. + * + * @var integer + */ + public $ledyer_total_order_amount_excl_vat = 0; - /** - * Ledyer order vat amount in minor units. - * - * @var integer - */ - public $ledyer_total_order_vat_amount = 0; + /** + * Ledyer order vat amount in minor units. + * + * @var integer + */ + public $ledyer_total_order_vat_amount = 0; - /** - * WooCommerce order. - * - * @var bool|WC_Order|WC_Order_Refund - */ - public $order; + /** + * WooCommerce order. + * + * @var bool|WC_Order|WC_Order_Refund + */ + public $order; - /** - * Order mapper constructor. - * - * @param int $order WooCommerce order - */ - public function __construct($order) - { - $this->order = $order; - } + /** + * Order mapper constructor. + * + * @param int $order WooCommerce order + */ + public function __construct($order) + { + $this->order = $order; + } - public function woo_to_ledyer_edit_order_lines() - { - $this->process_order_line_items(); - return array( - 'orderLines' => $this->ledyer_order_lines, - 'totalOrderAmount' => $this->ledyer_total_order_amount, - 'totalOrderAmountExclVat' => $this->ledyer_total_order_amount_excl_vat, - 'totalOrderVatAmount' => $this->ledyer_total_order_vat_amount, - ); - } + public function woo_to_ledyer_edit_order_lines() + { + $this->process_order_line_items(); + return [ + "orderLines" => $this->ledyer_order_lines, + "totalOrderAmount" => $this->ledyer_total_order_amount, + "totalOrderAmountExclVat" => $this->ledyer_total_order_amount_excl_vat, + "totalOrderVatAmount" => $this->ledyer_total_order_vat_amount, + ]; + } - public function woo_to_ledyer_capture_order_lines() - { - $this->process_order_line_items(); - return array( - 'orderLines' => $this->ledyer_order_lines, - 'totalCaptureAmount' => $this->ledyer_total_order_amount, - ); - } + public function woo_to_ledyer_capture_order_lines() + { + $this->process_order_line_items(); + return [ + "orderLines" => $this->ledyer_order_lines, + "totalCaptureAmount" => $this->ledyer_total_order_amount, + ]; + } - public function woo_to_ledyer_refund_order_lines() - { - $this->process_order_line_items(false); + public function woo_to_ledyer_refund_order_lines() + { + $this->process_order_line_items(false); - $refund_order_lines = array_map(function ($n) { - $n['quantity'] = abs($n['quantity']); - $n['totalAmount'] = abs($n['totalAmount']); - $n['totalVatAmount'] = abs($n['totalVatAmount']); - return $n; - }, $this->ledyer_order_lines); + $refund_order_lines = array_map(function ($n) { + $n["quantity"] = abs($n["quantity"]); + $n["totalAmount"] = abs($n["totalAmount"]); + $n["totalVatAmount"] = abs($n["totalVatAmount"]); + return $n; + }, $this->ledyer_order_lines); - return array( - 'orderLines' => $refund_order_lines, - 'totalRefundAmount' => abs($this->ledyer_total_order_amount), - ); - } + return [ + "orderLines" => $refund_order_lines, + "totalRefundAmount" => abs($this->ledyer_total_order_amount), + ]; + } - /** - * Process WooCommerce order items to Ledyer order lines. - */ - private function process_order_line_items($recalc = true) - { - if ($recalc) { - $this->order->calculate_shipping(); - $this->order->calculate_taxes(); - $this->order->calculate_totals(); - } + /** + * Process WooCommerce order items to Ledyer order lines. + */ + private function process_order_line_items($recalc = true) + { + if ($recalc) { + $this->order->calculate_shipping(); + $this->order->calculate_taxes(); + $this->order->calculate_totals(); + } - $total = Money::of($this->order->get_total(), $this->order->get_currency(), null, RoundingMode::HALF_UP); - $totalTax = Money::of($this->order->get_total_tax(), $this->order->get_currency(), null, RoundingMode::HALF_UP); - $totalExclTax = $total->minus($totalTax); - $this->ledyer_total_order_amount = $total->getMinorAmount()->toInt(); - $this->ledyer_total_order_vat_amount = $totalTax->getMinorAmount()->toInt(); - $this->ledyer_total_order_amount_excl_vat = $totalExclTax->getMinorAmount()->toInt(); + $total = Money::of( + $this->order->get_total(), + $this->order->get_currency(), + null, + RoundingMode::HALF_UP + ); + $totalTax = Money::of( + $this->order->get_total_tax(), + $this->order->get_currency(), + null, + RoundingMode::HALF_UP + ); + $totalExclTax = $total->minus($totalTax); + $this->ledyer_total_order_amount = $total->getMinorAmount()->toInt(); + $this->ledyer_total_order_vat_amount = $totalTax->getMinorAmount()->toInt(); + $this->ledyer_total_order_amount_excl_vat = $totalExclTax + ->getMinorAmount() + ->toInt(); - foreach ($this->order->get_items() as $order_item) { - $ledyer_item = $this->process_order_item($order_item, $this->order); - $order_line_item = apply_filters('lom_wc_order_line_item', $ledyer_item, $order_item); - if ($order_line_item) { - $this->ledyer_order_lines[] = $order_line_item; - } - } + foreach ($this->order->get_items() as $order_item) { + $ledyer_item = $this->process_order_item($order_item, $this->order); + $order_line_item = apply_filters( + "lom_wc_order_line_item", + $ledyer_item, + $order_item + ); + if ($order_line_item) { + $this->ledyer_order_lines[] = $order_line_item; + } + } - foreach ($this->order->get_items('shipping') as $order_item) { - $this->ledyer_order_lines[] = $this->process_order_item($order_item, $this->order, 'shippingFee', 1); - } + foreach ($this->order->get_items("shipping") as $order_item) { + $this->ledyer_order_lines[] = $this->process_order_item( + $order_item, + $this->order, + "shippingFee", + 1 + ); + } - foreach ($this->order->get_items('fee') as $order_item) { - $this->ledyer_order_lines[] = $this->process_order_item($order_item, $this->order, 'surcharge', 1); - } + foreach ($this->order->get_items("fee") as $order_item) { + $this->ledyer_order_lines[] = $this->process_order_item( + $order_item, + $this->order, + "surcharge", + 1 + ); + } - // TODO Add more types of gift cards when we are able to test them - // YITH gift cards seems to be processed as discount aka normal coupons so no need to handle them - // PW WooCommerce Gift Cards. - foreach ($this->order->get_items('pw_gift_card') as $gift_card) { - $code = $gift_card->get_card_number(); - $label = esc_html__('Gift card', 'pw-woocommerce-gift-cards') . ' ' . $code; - $gift_card_sku = apply_filters('lco_pw_gift_card_sku', esc_html__('giftcard', 'ledyer-checkout-for-woocommerce'), $code); - $gift_card_amount = intval($gift_card->get_amount() * -100); - $gift_card_amount_minor = $this->amount_to_minor($gift_card->get_amount(), $this->order->get_currency()); - $gift_card_amount = $gift_card_amount_minor * -1; - $order_item = array( - 'type' => 'giftCard', - 'reference' => $gift_card_sku, - 'description' => $label, - 'quantity' => 1, - 'vat' => 0, - 'totalAmount' => $gift_card_amount, - 'totalVatAmount' => 0, - ); - $this->ledyer_order_lines[] = $order_item; - } - } + // TODO Add more types of gift cards when we are able to test them + // YITH gift cards seems to be processed as discount aka normal coupons so no need to handle them + // PW WooCommerce Gift Cards. + foreach ($this->order->get_items("pw_gift_card") as $gift_card) { + $code = $gift_card->get_card_number(); + $label = + esc_html__("Gift card", "pw-woocommerce-gift-cards") . " " . $code; + $gift_card_sku = apply_filters( + "lco_pw_gift_card_sku", + esc_html__("giftcard", "ledyer-checkout-for-woocommerce"), + $code + ); + $gift_card_amount = intval($gift_card->get_amount() * -100); + $gift_card_amount_minor = $this->amount_to_minor( + $gift_card->get_amount(), + $this->order->get_currency() + ); + $gift_card_amount = $gift_card_amount_minor * -1; + $order_item = [ + "type" => "giftCard", + "reference" => $gift_card_sku, + "description" => $label, + "quantity" => 1, + "vat" => 0, + "totalAmount" => $gift_card_amount, + "totalVatAmount" => 0, + ]; + $this->ledyer_order_lines[] = $order_item; + } + } - private function process_order_item($order_item, $order, $ledyerType = null, $quantity = null) - { - return array( - 'type' => $ledyerType ? $ledyerType : $this->get_item_type($order_item), - 'reference' => $this->get_item_reference($order_item), - 'description' => $this->get_item_name($order_item), - 'quantity' => $quantity ? $quantity : $this->get_item_quantity($order_item), - 'vat' => $this->get_item_tax_rate($order, $order_item), - 'totalAmount' => $this->get_item_total_amount($order_item, $order->get_currency()), - 'totalVatAmount' => $this->get_item_tax_amount($order_item, $order->get_currency()), - ); - } + private function process_order_item( + $order_item, + $order, + $ledyerType = null, + $quantity = null + ) { + return [ + "type" => $ledyerType ? $ledyerType : $this->get_item_type($order_item), + "reference" => $this->get_item_reference($order_item), + "description" => $this->get_item_name($order_item), + "quantity" => $quantity + ? $quantity + : $this->get_item_quantity($order_item), + "vat" => $this->get_item_tax_rate($order, $order_item), + "totalAmount" => $this->get_item_total_amount( + $order_item, + $order->get_currency() + ), + "totalVatAmount" => $this->get_item_tax_amount( + $order_item, + $order->get_currency() + ), + ]; + } - private function get_item_type($order_line_item) - { - $product = $order_line_item->get_product(); - return $product && !$product->is_virtual() ? 'physical' : 'digital'; - } + private function get_item_type($order_line_item) + { + $product = $order_line_item->get_product(); + return $product && !$product->is_virtual() ? "physical" : "digital"; + } - private function get_item_reference($order_line_item) - { - if ('line_item' === $order_line_item->get_type()) { - $product = $order_line_item['variation_id'] ? wc_get_product($order_line_item['variation_id']) : wc_get_product($order_line_item['product_id']); - if ($product) { - if ($product->get_sku()) { - $item_reference = $product->get_sku(); - } else { - $item_reference = $product->get_id(); - } - } else { - $item_reference = $order_line_item->get_name(); - } - } elseif ('shipping' === $order_line_item->get_type()) { - $item_reference = $order_line_item->get_method_id() . ':' . $order_line_item->get_instance_id(); - } elseif ('coupon' === $order_line_item->get_type()) { - $item_reference = 'Discount'; - } elseif ('fee' === $order_line_item->get_type()) { - $item_reference = 'Fee'; - } else { - $item_reference = $order_line_item->get_name(); - } + private function get_item_reference($order_line_item) + { + if ("line_item" === $order_line_item->get_type()) { + $product = $order_line_item["variation_id"] + ? wc_get_product($order_line_item["variation_id"]) + : wc_get_product($order_line_item["product_id"]); + if ($product) { + if ($product->get_sku()) { + $item_reference = $product->get_sku(); + } else { + $item_reference = $product->get_id(); + } + } else { + $item_reference = $order_line_item->get_name(); + } + } elseif ("shipping" === $order_line_item->get_type()) { + $item_reference = + $order_line_item->get_method_id() . + ":" . + $order_line_item->get_instance_id(); + } elseif ("coupon" === $order_line_item->get_type()) { + $item_reference = "Discount"; + } elseif ("fee" === $order_line_item->get_type()) { + $item_reference = "Fee"; + } else { + $item_reference = $order_line_item->get_name(); + } - return substr((string) $item_reference, 0, 200); - } + return substr((string) $item_reference, 0, 200); + } - private function get_item_name($order_line_item) - { - $order_line_item_name = $order_line_item->get_name(); - return substr((string) wp_strip_all_tags($order_line_item_name), 0, 200); - } + private function get_item_name($order_line_item) + { + $order_line_item_name = $order_line_item->get_name(); + return substr((string) wp_strip_all_tags($order_line_item_name), 0, 200); + } - private function get_item_quantity($order_line_item) - { - if ($order_line_item->get_quantity()) { - return $order_line_item->get_quantity(); - } else { - return 1; - } - } + private function get_item_quantity($order_line_item) + { + if ($order_line_item->get_quantity()) { + return $order_line_item->get_quantity(); + } else { + return 1; + } + } - public function get_item_tax_rate($order, $order_line_item = false) - { - if ('coupon' === $order_line_item->get_type()) { - return 0; - } - $tax_items = $order->get_items('tax'); - foreach ($tax_items as $tax_item) { - $rate_id = $tax_item->get_rate_id(); - foreach ($order_line_item->get_taxes()['total'] as $key => $value) { - if ('' !== $value) { - if ($rate_id === $key) { - return round(\WC_Tax::_get_tax_rate($rate_id)['tax_rate'] * 100); - } - } - } - } - return 0; - } + public function get_item_tax_rate($order, $order_line_item = false) + { + if ("coupon" === $order_line_item->get_type()) { + return 0; + } + $tax_items = $order->get_items("tax"); + foreach ($tax_items as $tax_item) { + $rate_id = $tax_item->get_rate_id(); + foreach ($order_line_item->get_taxes()["total"] as $key => $value) { + if ("" !== $value) { + if ($rate_id === $key) { + return round(\WC_Tax::_get_tax_rate($rate_id)["tax_rate"] * 100); + } + } + } + } + return 0; + } - private function get_item_total_amount($order_line_item, $currency) - { - if ('shipping' === $order_line_item->get_type() || 'fee' === $order_line_item->get_type()) { - $item_total_amount = $order_line_item->get_total() + $order_line_item->get_total_tax(); - } elseif ('coupon' === $order_line_item->get_type()) { - $item_total_amount = $order_line_item->get_discount(); - } else { - $item_total_amount = $order_line_item->get_total() + $order_line_item->get_total_tax(); - } - return $this->amount_to_minor($item_total_amount, $currency); - } + private function get_item_total_amount($order_line_item, $currency) + { + if ( + "shipping" === $order_line_item->get_type() || + "fee" === $order_line_item->get_type() + ) { + $item_total_amount = + $order_line_item->get_total() + $order_line_item->get_total_tax(); + } elseif ("coupon" === $order_line_item->get_type()) { + $item_total_amount = $order_line_item->get_discount(); + } else { + $item_total_amount = + $order_line_item->get_total() + $order_line_item->get_total_tax(); + } + return $this->amount_to_minor($item_total_amount, $currency); + } - private function get_item_tax_amount($order_line_item, $currency) - { - if (in_array($order_line_item->get_type(), array('line_item', 'fee', 'shipping'), true)) { - $item_tax_amount = $order_line_item->get_total_tax(); - } elseif ('coupon' === $order_line_item->get_type()) { - $item_tax_amount = $order_line_item->get_discount_tax(); - } else { - $item_tax_amount = 0; - } - $amount = $this->amount_to_minor($item_tax_amount, $currency); - return $amount; - } + private function get_item_tax_amount($order_line_item, $currency) + { + if ( + in_array( + $order_line_item->get_type(), + ["line_item", "fee", "shipping"], + true + ) + ) { + $item_tax_amount = $order_line_item->get_total_tax(); + } elseif ("coupon" === $order_line_item->get_type()) { + $item_tax_amount = $order_line_item->get_discount_tax(); + } else { + $item_tax_amount = 0; + } + $amount = $this->amount_to_minor($item_tax_amount, $currency); + return $amount; + } - private function amount_to_minor($amount, $currency) - { - $money = Money::of($amount, $currency, null, RoundingMode::HALF_UP); - return $money->getMinorAmount()->toInt(); - } + private function amount_to_minor($amount, $currency) + { + $money = Money::of($amount, $currency, null, RoundingMode::HALF_UP); + return $money->getMinorAmount()->toInt(); + } } diff --git a/classes/class-ledyer-om-parent-settings.php b/classes/class-ledyer-om-parent-settings.php index fc18e7b..ab241e5 100644 --- a/classes/class-ledyer-om-parent-settings.php +++ b/classes/class-ledyer-om-parent-settings.php @@ -8,7 +8,7 @@ namespace LedyerOm; -\defined('ABSPATH') || die (); +\defined("ABSPATH") || die(); /** * Parent Settings class. @@ -17,34 +17,46 @@ */ class ParentSettings { - use Singleton; - - public function set_settings() - { - // First try and get credentials from Ledyer checkout - self::$settings = get_option('woocommerce_lco_settings'); - - // If that is not found, try and get from Ledyer Payments (to be developed) - } - - public function get_test_environment() - { - $environment = self::$settings['development_test_environment']; - - return apply_filters('lco_wc_credentials_from_session', $environment, self::$settings['testmode']); - } - - public function get_is_test_mode() - { - $test_mode = self::$settings['testmode']; - - return apply_filters('lco_wc_credentials_from_session', $test_mode, self::$settings['testmode']); - } - - public function get_logger_enabled() - { - $logging = self::$settings['logging']; - - return apply_filters('lco_wc_credentials_from_session', $logging, self::$settings['testmode']); - } + use Singleton; + + public function set_settings() + { + // First try and get credentials from Ledyer checkout + self::$settings = get_option("woocommerce_lco_settings"); + + // If that is not found, try and get from Ledyer Payments (to be developed) + } + + public function get_test_environment() + { + $environment = self::$settings["development_test_environment"]; + + return apply_filters( + "lco_wc_credentials_from_session", + $environment, + self::$settings["testmode"] + ); + } + + public function get_is_test_mode() + { + $test_mode = self::$settings["testmode"]; + + return apply_filters( + "lco_wc_credentials_from_session", + $test_mode, + self::$settings["testmode"] + ); + } + + public function get_logger_enabled() + { + $logging = self::$settings["logging"]; + + return apply_filters( + "lco_wc_credentials_from_session", + $logging, + self::$settings["testmode"] + ); + } } diff --git a/classes/class-ledyer-om-settings.php b/classes/class-ledyer-om-settings.php index a1d1dd5..dfa8cc5 100644 --- a/classes/class-ledyer-om-settings.php +++ b/classes/class-ledyer-om-settings.php @@ -5,8 +5,8 @@ * * @package LedyerOm */ -if (!defined('ABSPATH')) { - exit; +if (!defined("ABSPATH")) { + exit(); } /** @@ -14,275 +14,304 @@ */ class Ledyer_Order_Management_For_WooCommerce_Settings { - /** - * Class constructor. - */ - public function __construct() - { - // WP Settings API. - add_action('admin_menu', array($this, 'add_menu'), 101); - add_action('admin_init', array($this, 'register_settings')); + /** + * Class constructor. + */ + public function __construct() + { + // WP Settings API. + add_action("admin_menu", [$this, "add_menu"], 101); + add_action("admin_init", [$this, "register_settings"]); - // ledyer add-on. - add_filter('ledyer_addons_settings_pages', array($this, 'register_settings_page'), 1); - add_action('ledyer_addons_settings_tab', array($this, 'redirect_to_settings_page'), 999999); - } + // ledyer add-on. + add_filter( + "ledyer_addons_settings_pages", + [$this, "register_settings_page"], + 1 + ); + add_action( + "ledyer_addons_settings_tab", + [$this, "redirect_to_settings_page"], + 999999 + ); + } - /** - * Redirect to the settings page for LOM - * - * @return void - */ - public function redirect_to_settings_page() - { - global $wp; + /** + * Redirect to the settings page for LOM + * + * @return void + */ + public function redirect_to_settings_page() + { + global $wp; - $query_args = array( - 'page' => 'lom-settings', - ); - $url = add_query_arg($query_args, $wp->request); - header('Location: ' . $url); - wp_die(); - } + $query_args = [ + "page" => "lom-settings", + ]; + $url = add_query_arg($query_args, $wp->request); + header("Location: " . $url); + wp_die(); + } - /** - * Adds the submenue to the checkout addons page. - * - * @return void - */ - public function add_menu() - { - $submenu = add_submenu_page( - 'checkout-addons', - __( - 'Ledyer Order Management', - 'ledyer-order-management-for-woocommerce' - ), - __( - 'Ledyer Order Management', - 'ledyer-order-management-for-woocommerce' - ), - 'manage_woocommerce', - 'lom-settings', - array($this, 'settings_page') - ); - } + /** + * Adds the submenue to the checkout addons page. + * + * @return void + */ + public function add_menu() + { + $submenu = add_submenu_page( + "checkout-addons", + __("Ledyer Order Management", "ledyer-order-management-for-woocommerce"), + __("Ledyer Order Management", "ledyer-order-management-for-woocommerce"), + "manage_woocommerce", + "lom-settings", + [$this, "settings_page"] + ); + } - /** - * Generates the HTML for the page. - * - * @return void - */ - public function settings_page() - { - $this->add_page_tabs(); - $this->get_settings_links(); - ?> + /** + * Generates the HTML for the page. + * + * @return void + */ + public function settings_page() + { + $this->add_page_tabs(); + $this->get_settings_links(); + ?>
- - + +
+ /** + * HTML For the input field. + * + * @return void + */ + public function field_auto_capture_render() + { + $options = get_option("lom_settings"); + $val = isset($options["lom_auto_capture"]) + ? $options["lom_auto_capture"] + : "yes"; + ?> + /** + * HTML For the input field. + * + * @return void + */ + public function field_auto_cancel_render() + { + $options = get_option("lom_settings"); + $val = isset($options["lom_auto_cancel"]) + ? $options["lom_auto_cancel"] + : "yes"; + ?> + /** + * HTML For the input field. + * + * @return void + */ + public function field_auto_update_render() + { + $options = get_option("lom_settings"); + $val = isset($options["lom_auto_update"]) + ? $options["lom_auto_update"] + : "yes"; + ?> + function field_status_error_ledyer_woo_render() + { + $options = get_option("lom_settings"); + $current_value = isset($options["lom_status_mapping_ledyer_error"]) + ? $options["lom_status_mapping_ledyer_error"] + : "wc-on-hold"; + $order_statuses = wc_get_order_statuses(); + $order_statuses["none"] = "-"; + ?> __('Settings', 'ledyer-checkout-for-woocommerce'), - ); - $pages = array( - 'settings' => 'lom-settings', - ); - ?> + /** + * Adds tabs to the Addons page. + * + * @param string $current Wich tab is to be selected. + * @return void + */ + public function add_page_tabs($current = "settings") + { + $tabs = [ + "settings" => __("Settings", "ledyer-checkout-for-woocommerce"), + ]; + $pages = [ + "settings" => "lom-settings", + ]; + ?> + $pages = apply_filters("ledyer_addons_settings_pages", []); + $i = count($pages); + ?>

- $title) { - $query_args = array( - 'page' => $slug, - ); - $i - 1; - ?> - + $title) { + + $query_args = [ + "page" => $slug, + ]; + $i - 1; + ?> + + } ?>

set_settings(); - $this->actions(); - $this->filters(); - } + /** + * Construct the class + * + * @return void + */ + private function __construct() + { + $this->set_settings(); + $this->actions(); + $this->filters(); + } - /** - * Different add_actions is added here - * - * @return void - */ - public function actions() {} + /** + * Different add_actions is added here + * + * @return void + */ + public function actions() + { + } - /** - * Different add_filters is added here - * - * @return void - */ - public function filters() {} + /** + * Different add_filters is added here + * + * @return void + */ + public function filters() + { + } - /** - * Set settings - * - * @return void - */ - public function set_settings() {} + /** + * Set settings + * + * @return void + */ + public function set_settings() + { + } } diff --git a/includes/lom-cancel.php b/includes/lom-cancel.php index 446b3c1..fa30089 100644 --- a/includes/lom-cancel.php +++ b/includes/lom-cancel.php @@ -1,6 +1,6 @@ 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.'); - update_post_meta($order_id, '_wc_ledyer_cancelled', 'yes'); - $order->save(); - return; - } + if (!is_wp_error($response)) { + $order->add_order_note("Ledyer order cancelled."); + update_post_meta($order_id, "_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 452048a..7fdef03 100644 --- a/includes/lom-capture.php +++ b/includes/lom-capture.php @@ -1,6 +1,6 @@ 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; - } - - // 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; - } - - // 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; - } - - 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; - } - - $orderMapper = new \LedyerOm\OrderMapper($order); - $data = $orderMapper->woo_to_ledyer_capture_order_lines(); - $response = $api->capture_order($ledyer_order_id, $data); - - if (!is_wp_error($response)) { - $first_captured = lom_get_first_captured($response); - $capture_id = $first_captured['ledgerId']; - - $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' !== $options['lom_status_mapping_ledyer_error']) { - $order->update_status($options['lom_status_mapping_ledyer_error'], $errmsg); - } else { - $order->add_order_note($errmsg); - } - $order->save(); + $options = get_option("lom_settings"); + // If the capture on complete is not enabled in lom-settings + if ("no" === $options["lom_auto_capture"]) { + return; + } + + $order = wc_get_order($order_id); + + // 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; + } + + // 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; + } + + // 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; + } + + 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; + } + + $orderMapper = new \LedyerOm\OrderMapper($order); + $data = $orderMapper->woo_to_ledyer_capture_order_lines(); + $response = $api->capture_order($ledyer_order_id, $data); + + if (!is_wp_error($response)) { + $first_captured = lom_get_first_captured($response); + $capture_id = $first_captured["ledgerId"]; + + $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" !== $options["lom_status_mapping_ledyer_error"]) { + $order->update_status($options["lom_status_mapping_ledyer_error"], $errmsg); + } else { + $order->add_order_note($errmsg); + } + $order->save(); } diff --git a/includes/lom-edit.php b/includes/lom-edit.php index 4ac98a7..0d57a88 100644 --- a/includes/lom-edit.php +++ b/includes/lom-edit.php @@ -1,6 +1,6 @@ get_meta('_wc_ledyer_order_id', true); - - if (!$ledyer_order_id && !$order->get_meta('_transaction_id', true)) { - $order->add_order_note('Ledyer order ID is missing, Ledyer order could not be updated at this time.'); - $order->save(); - return; - } - - $ledyer_order = $api->get_order($ledyer_order_id); - - if (is_wp_error($ledyer_order)) { - $errmsg = 'Ledyer order could not be updated due to an error: ' . $ledyer_order->get_error_message(); - $order->add_order_note($errmsg); - $order->save(); - return; - } - - if (!lom_is_order_editable($ledyer_order)) { - $order->add_order_note('Ledyer order has been captured or cancelled, Ledyer order could not be updated at this time.'); - $order->save(); - return; - } - - if ('order' === $syncType) { - lom_process_order_sync($order, $api, $ledyer_order_id); - } else if ('customer' === $syncType) { - lom_process_customer_sync($order, $api, $ledyer_order_id); - } + $options = get_option("lom_settings"); + if ("no" === $options["lom_auto_update"]) { + return; + } + + $order = wc_get_order($order_id); + + if (!lom_allow_editing($order)) { + return; + } + + $ledyer_order_id = $order->get_meta("_wc_ledyer_order_id", true); + + if (!$ledyer_order_id && !$order->get_meta("_transaction_id", true)) { + $order->add_order_note( + "Ledyer order ID is missing, Ledyer order could not be updated at this time." + ); + $order->save(); + return; + } + + $ledyer_order = $api->get_order($ledyer_order_id); + + if (is_wp_error($ledyer_order)) { + $errmsg = + "Ledyer order could not be updated due to an error: " . + $ledyer_order->get_error_message(); + $order->add_order_note($errmsg); + $order->save(); + return; + } + + if (!lom_is_order_editable($ledyer_order)) { + $order->add_order_note( + "Ledyer order has been captured or cancelled, Ledyer order could not be updated at this time." + ); + $order->save(); + return; + } + + if ("order" === $syncType) { + lom_process_order_sync($order, $api, $ledyer_order_id); + } elseif ("customer" === $syncType) { + lom_process_customer_sync($order, $api, $ledyer_order_id); + } } function lom_allow_editing($order) { - $is_ledyer_order = lom_order_placed_with_ledyer($order->get_payment_method()); - if (!$is_ledyer_order) { - return false; - } + $is_ledyer_order = lom_order_placed_with_ledyer($order->get_payment_method()); + if (!$is_ledyer_order) { + return false; + } - if ($order->has_status(array('completed', 'refunded', 'cancelled'))) { - return false; - } + if ($order->has_status(["completed", "refunded", "cancelled"])) { + return false; + } - return true; + return true; } function lom_is_order_editable($ledyer_order) { - return count($ledyer_order['status']) == 1 && in_array(LedyerOmOrderStatus::uncaptured, $ledyer_order['status']); + return count($ledyer_order["status"]) == 1 && + in_array(LedyerOmOrderStatus::uncaptured, $ledyer_order["status"]); } function lom_process_order_sync($order, $api, $ledyer_order_id) { - $orderMapper = new \LedyerOm\OrderMapper($order); - $data = $orderMapper->woo_to_ledyer_edit_order_lines(); - $response = $api->edit_order($ledyer_order_id, $data); - lom_handle_sync_response($order, $response); + $orderMapper = new \LedyerOm\OrderMapper($order); + $data = $orderMapper->woo_to_ledyer_edit_order_lines(); + $response = $api->edit_order($ledyer_order_id, $data); + lom_handle_sync_response($order, $response); } function lom_process_customer_sync($order, $api, $ledyer_order_id) { - $customerMapper = new \LedyerOm\CustomerMapper($order); - $data = $customerMapper->woo_to_ledyer_customer(); - $response = $api->edit_customer($ledyer_order_id, $data); - lom_handle_sync_response($order, $response); + $customerMapper = new \LedyerOm\CustomerMapper($order); + $data = $customerMapper->woo_to_ledyer_customer(); + $response = $api->edit_customer($ledyer_order_id, $data); + lom_handle_sync_response($order, $response); } function lom_handle_sync_response($order, $response) { - if (is_wp_error($response)) { - $errmsg = 'Sync could not be completed due to an error: ' . $response->get_error_message(); - $order->add_order_note($errmsg); - $order->save(); - } + if (is_wp_error($response)) { + $errmsg = + "Sync could not be completed due to an error: " . + $response->get_error_message(); + $order->add_order_note($errmsg); + $order->save(); + } } diff --git a/includes/lom-functions.php b/includes/lom-functions.php index 431aeea..b51ab6c 100644 --- a/includes/lom-functions.php +++ b/includes/lom-functions.php @@ -5,19 +5,19 @@ * * @package LedyerOm */ -\defined('ABSPATH') || die (); +\defined("ABSPATH") || die(); function lom_order_placed_with_ledyer($payment_method) { - if (in_array($payment_method, array('ledyer_payments', 'lco'))) { - return true; - } + if (in_array($payment_method, ["ledyer_payments", "lco"])) { + return true; + } - return false; + return false; } function lom_get_first_captured($ledyer_order) { - $captured = $ledyer_order['captured']; - return $captured[0]; + $captured = $ledyer_order["captured"]; + return $captured[0]; } diff --git a/includes/lom-refund.php b/includes/lom-refund.php index 4413320..396a550 100644 --- a/includes/lom-refund.php +++ b/includes/lom-refund.php @@ -1,6 +1,6 @@ get_payment_method())) { - return false; - } + // Only support Ledyer orders + if (!lom_order_placed_with_ledyer($order->get_payment_method())) { + return false; + } - // Check if the order was captured - if (!lom_is_order_captured($order)) { - lom_add_order_note_and_save($order, 'Ledyer order has not been captured / not captured through Woocommerce and therefore cannot be refunded.'); - return false; - } + // Check if the order was captured + if (!lom_is_order_captured($order)) { + lom_add_order_note_and_save( + $order, + "Ledyer order has not been captured / not captured through Woocommerce and therefore cannot be refunded." + ); + return false; + } - $ledyer_order_id = $order->get_meta('_wc_ledyer_order_id', true); - $ledyer_order = $api->get_order($ledyer_order_id); + $ledyer_order_id = $order->get_meta("_wc_ledyer_order_id", true); + $ledyer_order = $api->get_order($ledyer_order_id); - if (is_wp_error($ledyer_order)) { - return lom_handle_wp_error($order, $ledyer_order, 'refunded'); - } + if (is_wp_error($ledyer_order)) { + return lom_handle_wp_error($order, $ledyer_order, "refunded"); + } - $captured_ledger_id = $ledyer_order['captured'][0]['ledgerId']; - $refund_order = $order->get_refunds()[0]; - $orderMapper = new \LedyerOm\OrderMapper($refund_order); - $data = $orderMapper->woo_to_ledyer_refund_order_lines(); - $response = $api->partial_refund_order($ledyer_order_id, $captured_ledger_id, $data); + $captured_ledger_id = $ledyer_order["captured"][0]["ledgerId"]; + $refund_order = $order->get_refunds()[0]; + $orderMapper = new \LedyerOm\OrderMapper($refund_order); + $data = $orderMapper->woo_to_ledyer_refund_order_lines(); + $response = $api->partial_refund_order( + $ledyer_order_id, + $captured_ledger_id, + $data + ); - if (!is_wp_error($response)) { - lom_process_successful_refund($order, $amount); - return true; - } + if (!is_wp_error($response)) { + lom_process_successful_refund($order, $amount); + return true; + } - return lom_handle_wp_error($order, $response, 'refunded'); + return lom_handle_wp_error($order, $response, "refunded"); } function lom_is_order_captured($order): bool { - return $order->get_meta('_wc_ledyer_capture_id', true) ? true : false; + return $order->get_meta("_wc_ledyer_capture_id", true) ? true : false; } function lom_add_order_note_and_save($order, $note) { - $order->add_order_note($note); - $order->save(); + $order->add_order_note($note); + $order->save(); } function lom_handle_wp_error($order, $wp_error, $action) { - $errmsg = 'Ledyer order could not be ' . $action . ' due to an error: ' . $wp_error->get_error_message(); - lom_add_order_note_and_save($order, $errmsg); - return false; + $errmsg = + "Ledyer order could not be " . + $action . + " due to an error: " . + $wp_error->get_error_message(); + lom_add_order_note_and_save($order, $errmsg); + return false; } function lom_process_successful_refund($order, $amount) { - $formatted_amount = wc_price($amount, array('currency' => $order->get_meta('_order_currency', true))); - lom_add_order_note_and_save($order, $formatted_amount . ' refunded via Ledyer.'); - $order->update_meta_data('_wc_ledyer_capture_id', false); - $order->save(); + $formatted_amount = wc_price($amount, [ + "currency" => $order->get_meta("_order_currency", true), + ]); + lom_add_order_note_and_save( + $order, + $formatted_amount . " refunded via Ledyer." + ); + $order->update_meta_data("_wc_ledyer_capture_id", false); + $order->save(); } diff --git a/includes/lom-types.php b/includes/lom-types.php index 6deaa0c..95d5b3a 100644 --- a/includes/lom-types.php +++ b/includes/lom-types.php @@ -1,26 +1,26 @@ =6" + } + }, + "node_modules/mem": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/mem/-/mem-9.0.2.tgz", + "integrity": "sha512-F2t4YIv9XQUBHt6AOJ0y7lSmP1+cY7Fm1DRh9GClTGzKST7UWLMx6ly9WZdLH/G/ppM5RL4MlQfRT71ri9t19A==", + "dev": true, + "dependencies": { + "map-age-cleaner": "^0.1.3", + "mimic-fn": "^4.0.0" + }, + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sindresorhus/mem?sponsor=1" + } + }, + "node_modules/mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-defer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", + "integrity": "sha512-wB3wfAxZpk2AzOfUMJNL+d36xothRSyj8EXOa4f6GMqYDN9BJaaSISbsk+wS9abmnebVw95C2Kb5t85UmpCxuw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/php-parser": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/php-parser/-/php-parser-3.1.5.tgz", + "integrity": "sha512-jEY2DcbgCm5aclzBdfW86GM6VEIWcSlhTBSHN1qhJguVePlYe28GhwS0yoeLYXpM2K8y6wzLwrbq814n2PHSoQ==", + "dev": true + }, + "node_modules/prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c3c74a9 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "ledyer-order-management-for-woocommerce", + "version": "1.0.0", + "description": "Ledyer order management for Woocommerce", + "main": "index.js", + "scripts": { + "format": "prettier --write **/*.php", + "format:check": "prettier --write **/*.php --check" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@prettier/plugin-php": "0.22.1", + "prettier": "3.1.1" + } +}