diff --git a/modules/ppcp-button/src/Endpoint/CartScriptParamsEndpoint.php b/modules/ppcp-button/src/Endpoint/CartScriptParamsEndpoint.php index 316d2c000..848923876 100644 --- a/modules/ppcp-button/src/Endpoint/CartScriptParamsEndpoint.php +++ b/modules/ppcp-button/src/Endpoint/CartScriptParamsEndpoint.php @@ -13,6 +13,7 @@ use Psr\Log\LoggerInterface; use Throwable; use WooCommerce\PayPalCommerce\ApiClient\Entity\Money; use WooCommerce\PayPalCommerce\Button\Assets\SmartButton; +use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; /** * Class CartScriptParamsEndpoint. @@ -25,7 +26,7 @@ class CartScriptParamsEndpoint implements EndpointInterface { /** * The SmartButton. * - * @var SmartButton + * @var SmartButtonInterface */ private $smart_button; @@ -39,11 +40,11 @@ class CartScriptParamsEndpoint implements EndpointInterface { /** * CartScriptParamsEndpoint constructor. * - * @param SmartButton $smart_button he SmartButton. - * @param LoggerInterface $logger The logger. + * @param SmartButtonInterface $smart_button he SmartButton. + * @param LoggerInterface $logger The logger. */ public function __construct( - SmartButton $smart_button, + SmartButtonInterface $smart_button, LoggerInterface $logger ) { $this->smart_button = $smart_button; @@ -66,6 +67,11 @@ class CartScriptParamsEndpoint implements EndpointInterface { */ public function handle_request(): bool { try { + if ( ! $this->smart_button instanceof SmartButton ) { + wp_send_json_error(); + return false; + } + if ( is_callable( 'wc_maybe_define_constant' ) ) { wc_maybe_define_constant( 'WOOCOMMERCE_CART', true ); } diff --git a/modules/ppcp-button/src/Endpoint/SimulateCartEndpoint.php b/modules/ppcp-button/src/Endpoint/SimulateCartEndpoint.php index 1040cc680..36069e463 100644 --- a/modules/ppcp-button/src/Endpoint/SimulateCartEndpoint.php +++ b/modules/ppcp-button/src/Endpoint/SimulateCartEndpoint.php @@ -13,6 +13,7 @@ use Exception; use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\ApiClient\Entity\Money; use WooCommerce\PayPalCommerce\Button\Assets\SmartButton; +use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; use WooCommerce\PayPalCommerce\Button\Helper\CartProductsHelper; /** @@ -25,7 +26,7 @@ class SimulateCartEndpoint extends AbstractCartEndpoint { /** * The SmartButton. * - * @var SmartButton + * @var SmartButtonInterface */ private $smart_button; @@ -39,14 +40,14 @@ class SimulateCartEndpoint extends AbstractCartEndpoint { /** * ChangeCartEndpoint constructor. * - * @param SmartButton $smart_button The SmartButton. - * @param \WC_Cart $cart The current WC cart object. - * @param RequestData $request_data The request data helper. - * @param CartProductsHelper $cart_products The cart products helper. - * @param LoggerInterface $logger The logger. + * @param SmartButtonInterface $smart_button The SmartButton. + * @param \WC_Cart $cart The current WC cart object. + * @param RequestData $request_data The request data helper. + * @param CartProductsHelper $cart_products The cart products helper. + * @param LoggerInterface $logger The logger. */ public function __construct( - SmartButton $smart_button, + SmartButtonInterface $smart_button, \WC_Cart $cart, RequestData $request_data, CartProductsHelper $cart_products, @@ -68,6 +69,11 @@ class SimulateCartEndpoint extends AbstractCartEndpoint { * @throws Exception On error. */ protected function handle_data(): bool { + if ( ! $this->smart_button instanceof SmartButton ) { + wp_send_json_error(); + return false; + } + $products = $this->products_from_request(); if ( ! $products ) {