Version Description
- 2020.03.23 =
- Fix - Inventory/Stock updates as a result of checkout via PayPal Standard does not reflect on the Square item.
- Fix - Error when trying to save an external product with the modified 'sync with square' value.
- Fix - Move product check on a possibly invalid product out of the try block avoiding potential further errors.
Download this release
Release Info
| Developer | automattic |
| Plugin | |
| Version | 2.1.1 |
| Comparing to | |
| See all releases | |
Code changes from version 2.1.0 to 2.1.1
- i18n/languages/woocommerce-square.pot +10 -10
- includes/Handlers/Order.php +45 -3
- includes/Handlers/Product.php +36 -25
- includes/Plugin.php +1 -1
- readme.txt +7 -2
- woocommerce-square.php +2 -2
i18n/languages/woocommerce-square.pot
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
# This file is distributed under the GNU General Public License v3.0.
|
| 3 |
msgid ""
|
| 4 |
msgstr ""
|
| 5 |
-
"Project-Id-Version: WooCommerce Square 2.1.
|
| 6 |
"Report-Msgid-Bugs-To: "
|
| 7 |
"https://github.com/woocommerce/woocommerce-square/issues\n"
|
| 8 |
-
"POT-Creation-Date: 2020-
|
| 9 |
"MIME-Version: 1.0\n"
|
| 10 |
"Content-Type: text/plain; charset=utf-8\n"
|
| 11 |
"Content-Transfer-Encoding: 8bit\n"
|
|
@@ -2965,37 +2965,37 @@ msgstr ""
|
|
| 2965 |
msgid "Unknown Error"
|
| 2966 |
msgstr ""
|
| 2967 |
|
| 2968 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2969 |
msgid "Job data key \"%s\" not set"
|
| 2970 |
msgstr ""
|
| 2971 |
|
| 2972 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2973 |
msgid "Job data key \"%s\" is not an array"
|
| 2974 |
msgstr ""
|
| 2975 |
|
| 2976 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2977 |
msgid "Every %d Minutes"
|
| 2978 |
msgstr ""
|
| 2979 |
|
| 2980 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2981 |
msgid "Background Processing Test"
|
| 2982 |
msgstr ""
|
| 2983 |
|
| 2984 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2985 |
msgid "Run Test"
|
| 2986 |
msgstr ""
|
| 2987 |
|
| 2988 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2989 |
msgid ""
|
| 2990 |
"This tool will test whether your server is capable of processing background "
|
| 2991 |
"jobs."
|
| 2992 |
msgstr ""
|
| 2993 |
|
| 2994 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2995 |
msgid "Success! You should be able to process background jobs."
|
| 2996 |
msgstr ""
|
| 2997 |
|
| 2998 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:
|
| 2999 |
msgid ""
|
| 3000 |
"Could not connect. Please ask your hosting company to ensure your server "
|
| 3001 |
"has loopback connections enabled."
|
| 2 |
# This file is distributed under the GNU General Public License v3.0.
|
| 3 |
msgid ""
|
| 4 |
msgstr ""
|
| 5 |
+
"Project-Id-Version: WooCommerce Square 2.1.1\n"
|
| 6 |
"Report-Msgid-Bugs-To: "
|
| 7 |
"https://github.com/woocommerce/woocommerce-square/issues\n"
|
| 8 |
+
"POT-Creation-Date: 2020-03-20 15:35:44+00:00\n"
|
| 9 |
"MIME-Version: 1.0\n"
|
| 10 |
"Content-Type: text/plain; charset=utf-8\n"
|
| 11 |
"Content-Transfer-Encoding: 8bit\n"
|
| 2965 |
msgid "Unknown Error"
|
| 2966 |
msgstr ""
|
| 2967 |
|
| 2968 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:644
|
| 2969 |
msgid "Job data key \"%s\" not set"
|
| 2970 |
msgstr ""
|
| 2971 |
|
| 2972 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:648
|
| 2973 |
msgid "Job data key \"%s\" is not an array"
|
| 2974 |
msgstr ""
|
| 2975 |
|
| 2976 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:884
|
| 2977 |
msgid "Every %d Minutes"
|
| 2978 |
msgstr ""
|
| 2979 |
|
| 2980 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:1048
|
| 2981 |
msgid "Background Processing Test"
|
| 2982 |
msgstr ""
|
| 2983 |
|
| 2984 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:1049
|
| 2985 |
msgid "Run Test"
|
| 2986 |
msgstr ""
|
| 2987 |
|
| 2988 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:1050
|
| 2989 |
msgid ""
|
| 2990 |
"This tool will test whether your server is capable of processing background "
|
| 2991 |
"jobs."
|
| 2992 |
msgstr ""
|
| 2993 |
|
| 2994 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:1068
|
| 2995 |
msgid "Success! You should be able to process background jobs."
|
| 2996 |
msgstr ""
|
| 2997 |
|
| 2998 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/utilities/class-sv-wp-background-job-handler.php:1071
|
| 2999 |
msgid ""
|
| 3000 |
"Could not connect. Please ask your hosting company to ensure your server "
|
| 3001 |
"has loopback connections enabled."
|
includes/Handlers/Order.php
CHANGED
|
@@ -64,6 +64,9 @@ class Order {
|
|
| 64 |
// ADD hooks for stock syncs based on changes from orders not from this gateway
|
| 65 |
add_action( 'woocommerce_checkout_order_processed', [ $this, 'maybe_sync_stock_for_order_via_other_gateway' ], 10, 3 );
|
| 66 |
|
|
|
|
|
|
|
|
|
|
| 67 |
// ADD hooks to listen to refunds on orders from other gateways.
|
| 68 |
add_action( 'woocommerce_order_refunded', [ $this, 'maybe_sync_stock_for_refund_from_other_gateway' ], 10, 2 );
|
| 69 |
}
|
|
@@ -84,6 +87,33 @@ class Order {
|
|
| 84 |
return $hidden;
|
| 85 |
}
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
/**
|
| 89 |
* Checks if we should sync stock for this order.
|
|
@@ -99,12 +129,24 @@ class Order {
|
|
| 99 |
*/
|
| 100 |
public function maybe_sync_stock_for_order_via_other_gateway( $order_id, $posted_data, $order ) {
|
| 101 |
|
| 102 |
-
|
|
|
|
| 103 |
return;
|
| 104 |
}
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
return;
|
| 109 |
}
|
| 110 |
|
| 64 |
// ADD hooks for stock syncs based on changes from orders not from this gateway
|
| 65 |
add_action( 'woocommerce_checkout_order_processed', [ $this, 'maybe_sync_stock_for_order_via_other_gateway' ], 10, 3 );
|
| 66 |
|
| 67 |
+
// Add specific hook for paypal IPN callback
|
| 68 |
+
add_action( 'valid-paypal-standard-ipn-request', [ $this, 'maybe_sync_stock_for_order_via_paypal' ], 10, 1 );
|
| 69 |
+
|
| 70 |
// ADD hooks to listen to refunds on orders from other gateways.
|
| 71 |
add_action( 'woocommerce_order_refunded', [ $this, 'maybe_sync_stock_for_refund_from_other_gateway' ], 10, 2 );
|
| 72 |
}
|
| 87 |
return $hidden;
|
| 88 |
}
|
| 89 |
|
| 90 |
+
/**
|
| 91 |
+
* Add hooks to ensure PayPal IPN callbacks are added caches and considered for inventory changes
|
| 92 |
+
* when the sync happens. This also adds the shutdown hook to ensure sync happens if needed at
|
| 93 |
+
* a later stage.
|
| 94 |
+
*
|
| 95 |
+
* @since 2.1.1
|
| 96 |
+
*
|
| 97 |
+
* @param array $posted values returned from PayPal Standard IPN callback.
|
| 98 |
+
*/
|
| 99 |
+
public function maybe_sync_stock_for_order_via_paypal( $posted ) {
|
| 100 |
+
if ( empty( $posted[ 'custom' ] ) ) {
|
| 101 |
+
return;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
$raw_order = json_decode( $posted[ 'custom' ] );
|
| 105 |
+
if ( empty( $raw_order->order_id ) ) {
|
| 106 |
+
return;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
$order = wc_get_order( $raw_order->order_id );
|
| 110 |
+
|
| 111 |
+
if ( ! $order || ! $order instanceof \WC_Order ) {
|
| 112 |
+
return;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
$this->sync_stock_for_order( $order );
|
| 116 |
+
}
|
| 117 |
|
| 118 |
/**
|
| 119 |
* Checks if we should sync stock for this order.
|
| 129 |
*/
|
| 130 |
public function maybe_sync_stock_for_order_via_other_gateway( $order_id, $posted_data, $order ) {
|
| 131 |
|
| 132 |
+
// Confirm we are not processing the order through the Square gateway.
|
| 133 |
+
if ( ! $order instanceof \WC_Order || Plugin::GATEWAY_ID === $order->get_payment_method() ) {
|
| 134 |
return;
|
| 135 |
}
|
| 136 |
|
| 137 |
+
$this->sync_stock_for_order( $order );
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* For a given order sync stock if inventory sync is enabled.
|
| 142 |
+
*
|
| 143 |
+
* @since 2.1.1
|
| 144 |
+
*
|
| 145 |
+
* @param \WC_Order $order the order for which the stock must be synced.
|
| 146 |
+
*/
|
| 147 |
+
protected function sync_stock_for_order( $order ) {
|
| 148 |
+
|
| 149 |
+
if ( ! wc_square()->get_settings_handler()->is_inventory_sync_enabled() ) {
|
| 150 |
return;
|
| 151 |
}
|
| 152 |
|
includes/Handlers/Product.php
CHANGED
|
@@ -217,22 +217,25 @@ class Product {
|
|
| 217 |
* Updates a product image from a URL provided by Square (helper method).
|
| 218 |
*
|
| 219 |
* Note: does not save the product for persistence. If opening to public, consider changing this behavior.
|
|
|
|
| 220 |
*
|
| 221 |
* @since 2.0.0
|
| 222 |
*
|
| 223 |
-
* @param \WC_Product|int $
|
| 224 |
* @param string $image_id
|
| 225 |
-
* @
|
|
|
|
| 226 |
*/
|
| 227 |
-
public static function update_image_from_square( $
|
| 228 |
|
| 229 |
-
$product = is_numeric( $
|
| 230 |
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
-
|
| 234 |
-
throw new Framework\SV_WC_Plugin_Exception( 'Invalid product' );
|
| 235 |
-
}
|
| 236 |
|
| 237 |
$image_response = wc_square()->get_api()->retrieve_catalog_object( $image_id );
|
| 238 |
|
|
@@ -242,6 +245,10 @@ class Product {
|
|
| 242 |
|
| 243 |
$image_url = $image_response->get_data()->getObject()->getImageData()->getUrl();
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
// grab remote image to upload into WordPress before attaching to product
|
| 246 |
$url_parts = parse_url( $image_url );
|
| 247 |
$url_parts = explode( '/', $url_parts['path'] );
|
|
@@ -398,6 +405,10 @@ class Product {
|
|
| 398 |
/**
|
| 399 |
* Sets a product's synced with Square status.
|
| 400 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
* @since 2.0.0
|
| 402 |
*
|
| 403 |
* @param \WC_Product|int $product a valid product object or product ID
|
|
@@ -406,29 +417,29 @@ class Product {
|
|
| 406 |
*/
|
| 407 |
public static function set_synced_with_square( $product, $synced = 'yes' ) {
|
| 408 |
|
| 409 |
-
$success = false;
|
| 410 |
$product = is_numeric( $product ) ? wc_get_product( $product ) : $product;
|
| 411 |
|
| 412 |
-
if ( $product instanceof \WC_Product
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
wp_delete_object_term_relationships( $product->get_id(), [ self::SYNCED_WITH_SQUARE_TAXONOMY ] );
|
| 416 |
-
|
| 417 |
-
if ( 'yes' === $synced ) {
|
| 418 |
-
|
| 419 |
-
$set_term = wp_set_post_terms( $product->get_id(), [ $synced ], self::SYNCED_WITH_SQUARE_TAXONOMY );
|
| 420 |
-
$success = is_array( $set_term );
|
| 421 |
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
}
|
| 425 |
|
| 426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
|
| 428 |
-
|
|
|
|
| 429 |
|
| 430 |
-
|
| 431 |
-
|
|
|
|
|
|
|
|
|
|
| 432 |
}
|
| 433 |
|
| 434 |
return $success;
|
| 217 |
* Updates a product image from a URL provided by Square (helper method).
|
| 218 |
*
|
| 219 |
* Note: does not save the product for persistence. If opening to public, consider changing this behavior.
|
| 220 |
+
* This function handles its own exceptions and logs them.
|
| 221 |
*
|
| 222 |
* @since 2.0.0
|
| 223 |
*
|
| 224 |
+
* @param \WC_Product|int $given_product product object or product ID
|
| 225 |
* @param string $image_id
|
| 226 |
+
* @todo Look at ussages of this function. Does it even need to return anything?
|
| 227 |
+
* @return \WC_Product|int The product id of object that was passed in.
|
| 228 |
*/
|
| 229 |
+
public static function update_image_from_square( $given_product, $image_id ) {
|
| 230 |
|
| 231 |
+
$product = is_numeric( $given_product ) ? wc_get_product( $given_product ) : $given_product;
|
| 232 |
|
| 233 |
+
if ( ! $product instanceof \WC_Product ) {
|
| 234 |
+
wc_square()->log( sprintf( 'Could not import image from Square at %1$s for attaching to product: Invalid product.', $image_url ) );
|
| 235 |
+
return $given_product;
|
| 236 |
+
}
|
| 237 |
|
| 238 |
+
try {
|
|
|
|
|
|
|
| 239 |
|
| 240 |
$image_response = wc_square()->get_api()->retrieve_catalog_object( $image_id );
|
| 241 |
|
| 245 |
|
| 246 |
$image_url = $image_response->get_data()->getObject()->getImageData()->getUrl();
|
| 247 |
|
| 248 |
+
if ( empty( $image_url ) ) {
|
| 249 |
+
throw new Framework\SV_WC_Plugin_Exception( 'Square image url empty' );
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
// grab remote image to upload into WordPress before attaching to product
|
| 253 |
$url_parts = parse_url( $image_url );
|
| 254 |
$url_parts = explode( '/', $url_parts['path'] );
|
| 405 |
/**
|
| 406 |
* Sets a product's synced with Square status.
|
| 407 |
*
|
| 408 |
+
* This function has a side effect where we also set the Product's
|
| 409 |
+
* manage stock value. We ignore external type product when setting this manage
|
| 410 |
+
* stock value.
|
| 411 |
+
*
|
| 412 |
* @since 2.0.0
|
| 413 |
*
|
| 414 |
* @param \WC_Product|int $product a valid product object or product ID
|
| 417 |
*/
|
| 418 |
public static function set_synced_with_square( $product, $synced = 'yes' ) {
|
| 419 |
|
|
|
|
| 420 |
$product = is_numeric( $product ) ? wc_get_product( $product ) : $product;
|
| 421 |
|
| 422 |
+
if ( ! $product instanceof \WC_Product || ! in_array( $synced, [ 'yes', 'no' ], true ) ) {
|
| 423 |
+
return false;
|
| 424 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
|
| 426 |
+
// ensure only one term is associated with the product at any time
|
| 427 |
+
wp_delete_object_term_relationships( $product->get_id(), [ self::SYNCED_WITH_SQUARE_TAXONOMY ] );
|
|
|
|
| 428 |
|
| 429 |
+
// we have already set the value to "no" above by deleting the term relationship
|
| 430 |
+
// so it is safe to return with true.
|
| 431 |
+
if ( 'no' === $synced ) {
|
| 432 |
+
return true;
|
| 433 |
+
}
|
| 434 |
|
| 435 |
+
$set_term = wp_set_post_terms( $product->get_id(), [ $synced ], self::SYNCED_WITH_SQUARE_TAXONOMY );
|
| 436 |
+
$success = is_array( $set_term );
|
| 437 |
|
| 438 |
+
// Function side effect see phpDoc for details:
|
| 439 |
+
if ( wc_square()->get_settings_handler()->is_inventory_sync_enabled()
|
| 440 |
+
&& 'external' !== $product->get_type() ) {
|
| 441 |
+
$product->set_manage_stock( ! $product->is_type( 'variable' ) );
|
| 442 |
+
$product->save();
|
| 443 |
}
|
| 444 |
|
| 445 |
return $success;
|
includes/Plugin.php
CHANGED
|
@@ -42,7 +42,7 @@ class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
|
|
| 42 |
|
| 43 |
|
| 44 |
/** plugin version number */
|
| 45 |
-
const VERSION = '2.1.
|
| 46 |
|
| 47 |
/** plugin ID */
|
| 48 |
const PLUGIN_ID = 'square';
|
| 42 |
|
| 43 |
|
| 44 |
/** plugin version number */
|
| 45 |
+
const VERSION = '2.1.1';
|
| 46 |
|
| 47 |
/** plugin ID */
|
| 48 |
const PLUGIN_ID = 'square';
|
readme.txt
CHANGED
|
@@ -2,9 +2,9 @@
|
|
| 2 |
Contributors: automattic, royho, woothemes, bor0
|
| 3 |
Tags: credit card, square, woocommerce, inventory sync
|
| 4 |
Requires at least: 4.6
|
| 5 |
-
Tested up to: 5.
|
| 6 |
Requires PHP: 5.6
|
| 7 |
-
Stable tag: 2.1.
|
| 8 |
License: GPLv3
|
| 9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
| 10 |
|
|
@@ -72,6 +72,11 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
|
|
| 72 |
|
| 73 |
== Changelog ==
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
= 2.1.0 - 2020.02.11 =
|
| 76 |
* Feature - Add support for SCA (3D Secure 2)
|
| 77 |
* Fix - Minor fixes to the Sync completed emails
|
| 2 |
Contributors: automattic, royho, woothemes, bor0
|
| 3 |
Tags: credit card, square, woocommerce, inventory sync
|
| 4 |
Requires at least: 4.6
|
| 5 |
+
Tested up to: 5.4
|
| 6 |
Requires PHP: 5.6
|
| 7 |
+
Stable tag: 2.1.1
|
| 8 |
License: GPLv3
|
| 9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
| 10 |
|
| 72 |
|
| 73 |
== Changelog ==
|
| 74 |
|
| 75 |
+
= 2.1.1 - 2020.03.23 =
|
| 76 |
+
* Fix - Inventory/Stock updates as a result of checkout via PayPal Standard does not reflect on the Square item.
|
| 77 |
+
* Fix - Error when trying to save an external product with the modified 'sync with square' value.
|
| 78 |
+
* Fix - Move product check on a possibly invalid product out of the try block avoiding potential further errors.
|
| 79 |
+
|
| 80 |
= 2.1.0 - 2020.02.11 =
|
| 81 |
* Feature - Add support for SCA (3D Secure 2)
|
| 82 |
* Fix - Minor fixes to the Sync completed emails
|
woocommerce-square.php
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Plugin Name: WooCommerce Square
|
| 4 |
-
* Version: 2.1.
|
| 5 |
* Plugin URI: https://woocommerce.com/products/square/
|
| 6 |
* Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
|
| 7 |
* Author: WooCommerce
|
|
@@ -19,7 +19,7 @@
|
|
| 19 |
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
|
| 20 |
*
|
| 21 |
* WC requires at least: 3.0
|
| 22 |
-
* WC tested up to:
|
| 23 |
*/
|
| 24 |
|
| 25 |
defined( 'ABSPATH' ) or exit;
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Plugin Name: WooCommerce Square
|
| 4 |
+
* Version: 2.1.1
|
| 5 |
* Plugin URI: https://woocommerce.com/products/square/
|
| 6 |
* Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
|
| 7 |
* Author: WooCommerce
|
| 19 |
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
|
| 20 |
*
|
| 21 |
* WC requires at least: 3.0
|
| 22 |
+
* WC tested up to: 4.0
|
| 23 |
*/
|
| 24 |
|
| 25 |
defined( 'ABSPATH' ) or exit;
|
