* `use` is never relative - absolute is always used so backslash is not needed

* Move process_legacy_payment code to rest api class

* Move storeapi directory

* Updated namespaces and moved tests
This commit is contained in:
Mike Jolley 2020-04-22 15:39:19 +01:00 committed by GitHub
parent 5a2ee88905
commit 953712941b
79 changed files with 180 additions and 179 deletions

View File

@ -9,10 +9,7 @@ namespace Automattic\WooCommerce\Blocks;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\Payments\PaymentResult;
use Automattic\WooCommerce\Blocks\Payments\PaymentContext;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\NoticeHandler;
/**
* Library class.
@ -32,7 +29,6 @@ class Library {
add_filter( 'woocommerce_register_shop_order_post_statuses', array( __CLASS__, 'register_draft_order_post_status' ) );
add_filter( 'woocommerce_valid_order_statuses_for_payment', array( __CLASS__, 'append_draft_order_post_status' ) );
add_action( 'woocommerce_cleanup_draft_orders', array( __CLASS__, 'delete_expired_draft_orders' ) );
add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( __CLASS__, 'process_legacy_payment' ), 999, 2 );
}
/**
@ -206,55 +202,4 @@ class Library {
"
);
}
/**
* Attempt to process a payment for the checkout API if no payment methods support the
* woocommerce_rest_checkout_process_payment_with_context action.
*
* @param PaymentContext $context Holds context for the payment.
* @param PaymentResult $result Result of the payment.
*/
public static function process_legacy_payment( PaymentContext $context, PaymentResult &$result ) {
if ( $result->status ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification
$post_data = $_POST;
// Set constants.
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
// Add the payment data from the API to the POST global.
$_POST = $context->payment_data;
// Call the process payment method of the chosen gatway.
$payment_method_object = $context->get_payment_method_instance();
if ( ! $payment_method_object instanceof \WC_Payment_Gateway ) {
return;
}
$payment_method_object->validate_fields();
// If errors were thrown, we need to abort.
NoticeHandler::convert_notices_to_exceptions( 'woocommerce_rest_payment_error' );
// Process Payment.
$gateway_result = $payment_method_object->process_payment( $context->order->get_id() );
// Restore $_POST data.
$_POST = $post_data;
// If `process_payment` added notices, clear them. Notices are not displayed from the API -- payment should fail,
// and a generic notice will be shown instead if payment failed.
wc_clear_notices();
// Handle result.
$result->set_status( isset( $gateway_result['result'] ) && 'success' === $gateway_result['result'] ? 'success' : 'failure' );
// set payment_details from result.
$result->set_payment_details( array_merge( $result->payment_details, $gateway_result ) );
$result->set_redirect_url( $gateway_result['redirect'] );
}
}

View File

@ -9,8 +9,12 @@ namespace Automattic\WooCommerce\Blocks;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController;
use \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController;
use Automattic\WooCommerce\Blocks\StoreApi\RoutesController;
use Automattic\WooCommerce\Blocks\StoreApi\SchemaController;
use Automattic\WooCommerce\Blocks\Payments\PaymentResult;
use Automattic\WooCommerce\Blocks\Payments\PaymentContext;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\NoticeHandler;
/**
* RestApi class.
@ -24,6 +28,7 @@ class RestApi {
add_action( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ), 10 );
add_filter( 'rest_authentication_errors', array( __CLASS__, 'maybe_init_cart_session' ), 1 );
add_filter( 'rest_authentication_errors', array( __CLASS__, 'store_api_authentication' ) );
add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( __CLASS__, 'process_legacy_payment' ), 999, 2 );
}
/**
@ -129,4 +134,55 @@ class RestApi {
'product-reviews' => __NAMESPACE__ . '\RestApi\Controllers\ProductReviews',
];
}
/**
* Attempt to process a payment for the checkout API if no payment methods support the
* woocommerce_rest_checkout_process_payment_with_context action.
*
* @param PaymentContext $context Holds context for the payment.
* @param PaymentResult $result Result of the payment.
*/
public static function process_legacy_payment( PaymentContext $context, PaymentResult &$result ) {
if ( $result->status ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification
$post_data = $_POST;
// Set constants.
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
// Add the payment data from the API to the POST global.
$_POST = $context->payment_data;
// Call the process payment method of the chosen gatway.
$payment_method_object = $context->get_payment_method_instance();
if ( ! $payment_method_object instanceof \WC_Payment_Gateway ) {
return;
}
$payment_method_object->validate_fields();
// If errors were thrown, we need to abort.
NoticeHandler::convert_notices_to_exceptions( 'woocommerce_rest_payment_error' );
// Process Payment.
$gateway_result = $payment_method_object->process_payment( $context->order->get_id() );
// Restore $_POST data.
$_POST = $post_data;
// If `process_payment` added notices, clear them. Notices are not displayed from the API -- payment should fail,
// and a generic notice will be shown instead if payment failed.
wc_clear_notices();
// Handle result.
$result->set_status( isset( $gateway_result['result'] ) && 'success' === $gateway_result['result'] ? 'success' : 'failure' );
// set payment_details from result.
$result->set_payment_details( array_merge( $result->payment_details, $gateway_result ) );
$result->set_redirect_url( $gateway_result['redirect'] );
}
}

View File

@ -12,9 +12,9 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WP_Error;
use \WP_REST_Server;
use \WP_REST_Controller;
use WP_Error;
use WP_REST_Server;
use WP_REST_Controller;
/**
* Cart API.

View File

@ -12,7 +12,7 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WC_REST_Product_Attribute_Terms_Controller;
use WC_REST_Product_Attribute_Terms_Controller;
/**
* REST API Product Attribute Terms controller class.

View File

@ -12,7 +12,7 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WC_REST_Product_Attributes_Controller;
use WC_REST_Product_Attributes_Controller;
/**
* REST API Product Attributes controller class.

View File

@ -12,7 +12,7 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WC_REST_Product_Categories_Controller;
use WC_REST_Product_Categories_Controller;
/**
* REST API Product Categories controller class.

View File

@ -13,7 +13,7 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WC_REST_Controller;
use WC_REST_Controller;
/**
* REST API Product Reviews controller class.

View File

@ -12,7 +12,7 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WC_REST_Product_Tags_Controller;
use WC_REST_Product_Tags_Controller;
/**
* REST API Product Tags controller class.

View File

@ -12,7 +12,7 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WC_REST_Products_Controller;
use WC_REST_Products_Controller;
use Automattic\WooCommerce\Blocks\RestApi\Utilities\ProductImages;
/**

View File

@ -12,7 +12,7 @@ namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;
use \WC_REST_Product_Variations_Controller;
use WC_REST_Product_Variations_Controller;
/**
* REST API variations controller class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* Cart class.

View File

@ -6,11 +6,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas\AbstractSchema;
use Automattic\WooCommerce\Blocks\StoreApi\Schemas\AbstractSchema;
/**
* AbstractRoute class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* Cart class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartAddItem class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartApplyCoupon class.

View File

@ -6,11 +6,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartCoupons class.

View File

@ -6,11 +6,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartCouponsByCode class.

View File

@ -6,11 +6,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartItems class.

View File

@ -6,11 +6,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartItemsByKey class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartRemoveCoupon class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartRemoveItem class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartSelectShippingRate class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartUpdateItem class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartUpdateShipping class.

View File

@ -5,14 +5,14 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\OrderController;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ReserveStock;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ReserveStockException;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\OrderController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\ReserveStock;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\ReserveStockException;
use Automattic\WooCommerce\Blocks\Payments\PaymentResult;
use Automattic\WooCommerce\Blocks\Payments\PaymentContext;

View File

@ -6,11 +6,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\TermQuery;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\TermQuery;
/**
* ProductAttributeTerms class.

View File

@ -6,7 +6,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;

View File

@ -6,7 +6,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;

View File

@ -8,11 +8,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ProductQueryFilters;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\ProductQueryFilters;
/**
* ProductCollectionData route.

View File

@ -6,12 +6,12 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\Pagination;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ProductQuery;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\Pagination;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\ProductQuery;
/**
* Products class.

View File

@ -6,7 +6,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
/**
* ReserveStockRouteExceptionException class.

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes;
namespace Automattic\WooCommerce\Blocks\StoreApi\Routes;
defined( 'ABSPATH' ) || exit;

View File

@ -6,7 +6,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi;
namespace Automattic\WooCommerce\Blocks\StoreApi;
defined( 'ABSPATH' ) || exit;

View File

@ -6,7 +6,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi;
namespace Automattic\WooCommerce\Blocks\StoreApi;
defined( 'ABSPATH' ) || exit;

View File

@ -7,7 +7,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
/**
* CartCouponSchema class.

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;
@ -406,7 +406,7 @@ class CartItemSchema extends ProductSchema {
if ( \class_exists( '\Automattic\WooCommerce\Checkout\Helpers\ReserveStock' ) ) {
$reserve_stock = new \Automattic\WooCommerce\Checkout\Helpers\ReserveStock();
} else {
$reserve_stock = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ReserveStock();
$reserve_stock = new \Automattic\WooCommerce\Blocks\StoreApi\Utilities\ReserveStock();
}
$reserved_stock = $reserve_stock->get_reserved_stock( $product, $draft_order );

View File

@ -5,9 +5,9 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
defined( 'ABSPATH' ) || exit;

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;
use \WC_Shipping_Rate as ShippingRate;
use WC_Shipping_Rate as ShippingRate;
/**
* CartShippingRateSchema class.

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -7,7 +7,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas;
namespace Automattic\WooCommerce\Blocks\StoreApi\Schemas;
defined( 'ABSPATH' ) || exit;

View File

@ -5,12 +5,12 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes\RouteException;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\NoticeHandler;
use Automattic\WooCommerce\Blocks\StoreApi\Routes\RouteException;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\NoticeHandler;
/**
* Woo Cart Controller class.
@ -630,7 +630,7 @@ class CartController {
if ( \class_exists( '\Automattic\WooCommerce\Checkout\Helpers\ReserveStock' ) ) {
$reserve_stock_controller = new \Automattic\WooCommerce\Checkout\Helpers\ReserveStock();
} else {
$reserve_stock_controller = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ReserveStock();
$reserve_stock_controller = new \Automattic\WooCommerce\Blocks\StoreApi\Utilities\ReserveStock();
}
$draft_order = wc()->session->get( 'store_api_draft_order', 0 );

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes\RouteException;
use Automattic\WooCommerce\Blocks\StoreApi\Routes\RouteException;
/**
* NoticeHandler class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes\RouteException;
use Automattic\WooCommerce\Blocks\StoreApi\Routes\RouteException;
/**
* OrderController class.

View File

@ -5,7 +5,7 @@
* @package Automattic/WooCommerce/RestApi
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;

View File

@ -5,11 +5,11 @@
* @package Automattic/WooCommerce/RestApi
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ProductQuery;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\ProductQuery;
/**
* Product Query filters class.

View File

@ -5,11 +5,11 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;
use \WC_Tax;
use WC_Tax;
/**
* Product Query class.

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
/**
* ReserveStockException class.

View File

@ -5,7 +5,7 @@
* @package WooCommerce/Blocks
*/
namespace Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\StoreApi\Utilities;
defined( 'ABSPATH' ) || exit;

View File

@ -9,7 +9,7 @@
namespace Automattic\WooCommerce\Blocks\Utils;
use \WP_Query;
use WP_Query;
defined( 'ABSPATH' ) || exit;

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case as TestCase;
@ -352,7 +352,7 @@ class Cart extends TestCase {
* Test conversion of cart item to rest response.
*/
public function test_prepare_item_for_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'cart' );
$cart = wc()->cart;
$response = $controller->prepare_item_for_response( $cart, new \WP_REST_Request() );
@ -372,7 +372,7 @@ class Cart extends TestCase {
* Test schema matches responses.
*/
public function test_schema_matches_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'cart' );
$schema = $controller->get_item_schema();
$cart = wc()->cart;

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case as TestCase;
@ -156,7 +156,7 @@ class CartCoupons extends TestCase {
* Test conversion of cart item to rest response.
*/
public function test_prepare_item_for_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'cart-coupons' );
$response = $controller->prepare_item_for_response( $this->coupon->get_code(), new \WP_REST_Request() );
@ -170,7 +170,7 @@ class CartCoupons extends TestCase {
* Test schema matches responses.
*/
public function test_schema_matches_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'cart-coupons' );
$schema = $controller->get_item_schema();
$response = $controller->prepare_item_for_response( $this->coupon->get_code(), new \WP_REST_Request() );

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case as TestCase;
@ -212,7 +212,7 @@ class CartItems extends TestCase {
* Test conversion of cart item to rest response.
*/
public function test_prepare_item_for_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'cart-items' );
$cart = wc()->cart->get_cart();
$response = $controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
@ -238,7 +238,7 @@ class CartItems extends TestCase {
* Tests schema of both products in cart to cover as much schema as possible.
*/
public function test_schema_matches_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'cart-items' );
$schema = $controller->get_item_schema();
$cart = wc()->cart->get_cart();

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case as TestCase;
@ -68,8 +68,8 @@ class ProductAttributeTerms extends TestCase {
* Test conversion of product to rest response.
*/
public function test_prepare_item_for_response() {
$schema = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\Schemas\TermSchema();
$controller = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\Routes\ProductAttributeTerms( $schema );
$schema = new \Automattic\WooCommerce\Blocks\StoreApi\Schemas\TermSchema();
$controller = new \Automattic\WooCommerce\Blocks\StoreApi\Routes\ProductAttributeTerms( $schema );
$response = $controller->prepare_item_for_response( get_term_by( 'name', 'test', 'pa_size' ), new \WP_REST_Request() );
$data = $response->get_data();
@ -84,7 +84,7 @@ class ProductAttributeTerms extends TestCase {
* Test collection params getter.
*/
public function test_get_collection_params() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'product-attribute-terms' );
$params = $controller->get_collection_params();
@ -97,7 +97,7 @@ class ProductAttributeTerms extends TestCase {
* Test schema matches responses.
*/
public function test_schema_matches_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'product-attribute-terms' );
$schema = $controller->get_item_schema();
$response = $controller->prepare_item_for_response( get_term_by( 'name', 'test', 'pa_size' ), new \WP_REST_Request() );

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case as TestCase;
@ -78,7 +78,7 @@ class ProductAttributes extends TestCase {
* Test conversion of product to rest response.
*/
public function test_prepare_item_for_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'product-attributes' );
$response = $controller->prepare_item_for_response( $this->attributes[0], new \WP_REST_Request() );
$data = $response->get_data();
@ -95,7 +95,7 @@ class ProductAttributes extends TestCase {
* Test schema matches responses.
*/
public function test_schema_matches_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'product-attributes' );
$schema = $controller->get_item_schema();
$response = $controller->prepare_item_for_response( $this->attributes[0], new \WP_REST_Request() );

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case as TestCase;
@ -163,7 +163,7 @@ class ProductCollectionData extends TestCase {
* Test collection params getter.
*/
public function test_get_collection_params() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'product-collection-data' );
$params = $controller->get_collection_params();
@ -178,7 +178,7 @@ class ProductCollectionData extends TestCase {
public function test_schema_matches_response() {
ProductHelper::create_variation_product();
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'product-collection-data' );
$schema = $controller->get_item_schema();

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case as TestCase;
@ -103,8 +103,8 @@ class Products extends TestCase {
* Test conversion of prdouct to rest response.
*/
public function test_prepare_item_for_response() {
$schemas = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController();
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( $schemas );
$schemas = new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController();
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( $schemas );
$schema = $schemas->get( 'product' );
$controller = $routes->get( 'products' );
$response = $controller->prepare_item_for_response( $this->products[0], new \WP_REST_Request() );
@ -131,7 +131,7 @@ class Products extends TestCase {
* Test collection params getter.
*/
public function test_get_collection_params() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'products' );
$params = $controller->get_collection_params();
@ -169,7 +169,7 @@ class Products extends TestCase {
* Test schema matches responses.
*/
public function test_schema_matches_response() {
$routes = new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\RestApi\StoreApi\SchemaController() );
$routes = new \Automattic\WooCommerce\Blocks\StoreApi\RoutesController( new \Automattic\WooCommerce\Blocks\StoreApi\SchemaController() );
$controller = $routes->get( 'products' );
$schema = $controller->get_item_schema();
$response = $controller->prepare_item_for_response( $this->products[0], new \WP_REST_Request() );

View File

@ -5,12 +5,12 @@
* @package WooCommerce\Blocks\Tests
*/
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\StoreApi\Utilities;
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Utilities;
use PHPUnit\Framework\TestCase;
use \WC_Helper_Order as OrderHelper;
use \WC_Helper_Product as ProductHelper;
use Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ReserveStock;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\ReserveStock;
/**
* ReserveStock Utility Tests.
@ -47,7 +47,7 @@ class ReserveStockTests extends TestCase {
/**
* Test that trying to reserve stock too much throws an exception.
*
* @expectedException Automattic\WooCommerce\Blocks\RestApi\StoreApi\Utilities\ReserveStockException
* @expectedException Automattic\WooCommerce\Blocks\StoreApi\Utilities\ReserveStockException
*/
public function test_reserve_stock_for_order_throws_exception() {
$class = new ReserveStock();