Fix block errors when not onboarded

This commit is contained in:
Alex P 2023-12-08 15:01:14 +02:00
parent ab0fcadb06
commit 2985687b4e
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 10 additions and 6 deletions

View file

@ -236,7 +236,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
'id' => $this->gateway->id,
'title' => $this->gateway->title,
'description' => $this->gateway->description,
'enabled' => $this->settings_status->is_smart_button_enabled_for_location( $script_data['context'] ),
'enabled' => $this->settings_status->is_smart_button_enabled_for_location( $script_data['context'] ?? 'checkout' ),
'fundingSource' => $this->session_handler->funding_source(),
'finalReviewEnabled' => $this->final_review_enabled,
'addPlaceOrderMethod' => $this->add_place_order_method,

View file

@ -12,7 +12,7 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
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 +25,7 @@ class CartScriptParamsEndpoint implements EndpointInterface {
/**
* The SmartButton.
*
* @var SmartButton
* @var SmartButtonInterface
*/
private $smart_button;
@ -39,11 +39,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;
@ -73,6 +73,10 @@ class CartScriptParamsEndpoint implements EndpointInterface {
$include_shipping = (bool) wc_clean( wp_unslash( $_GET['shipping'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$script_data = $this->smart_button->script_data();
if ( ! $script_data ) {
wp_send_json_error();
return false;
}
$total = (float) WC()->cart->get_total( 'numeric' );