mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add eligibility notice.
This commit is contained in:
parent
ad018766a6
commit
dc77deea79
4 changed files with 102 additions and 9 deletions
|
@ -10,6 +10,8 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\Googlepay;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
|
||||
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||
|
@ -46,6 +48,66 @@ class GooglepayModule implements ModuleInterface {
|
|||
$button->initialize();
|
||||
|
||||
if ( ! $c->get( 'googlepay.available' ) ) {
|
||||
|
||||
$apm_status = $c->get( 'googlepay.helpers.apm-product-status' );
|
||||
assert( $apm_status instanceof ApmProductStatus );
|
||||
|
||||
// TODO: refactor the notices.
|
||||
if ( $apm_status->has_request_failure() ) {
|
||||
|
||||
add_filter(
|
||||
Repository::NOTICES_FILTER,
|
||||
/**
|
||||
* Adds seller status notice.
|
||||
*
|
||||
* @param array $notices The notices.
|
||||
* @return array
|
||||
*
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
static function ( $notices ) use ( $c ): array {
|
||||
|
||||
$message = sprintf(
|
||||
__(
|
||||
'<p>There was an error getting your PayPal seller status. Some features may be disabled.</p><p>Certify that you connected to your account via our onboarding process.</p>',
|
||||
'woocommerce-paypal-payments'
|
||||
)
|
||||
);
|
||||
|
||||
// Name the key so it can be overridden.
|
||||
$notices['error_product_status'] = new Message( $message, 'error', true, 'ppcp-notice-wrapper' );
|
||||
return $notices;
|
||||
}
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
add_filter(
|
||||
Repository::NOTICES_FILTER,
|
||||
/**
|
||||
* Adds GooglePay not available notice.
|
||||
*
|
||||
* @param array $notices The notices.
|
||||
* @return array
|
||||
*
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
static function ( $notices ) use ( $c ): array {
|
||||
|
||||
$message = sprintf(
|
||||
__(
|
||||
'Google Pay is not available on your PayPal account.',
|
||||
'woocommerce-paypal-payments'
|
||||
)
|
||||
);
|
||||
|
||||
$notices[] = new Message( $message, 'warning', true, 'ppcp-notice-wrapper' );
|
||||
return $notices;
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,13 @@ class ApmProductStatus {
|
|||
*/
|
||||
private $current_status = null;
|
||||
|
||||
/**
|
||||
* If there was a request failure.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $has_request_failure = false;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
|
@ -93,7 +100,8 @@ class ApmProductStatus {
|
|||
$seller_status = $this->partners_endpoint->seller_status();
|
||||
} catch ( Throwable $error ) {
|
||||
// It may be a transitory error, don't persist the status.
|
||||
$this->current_status = false;
|
||||
$this->has_request_failure = true;
|
||||
$this->current_status = false;
|
||||
return $this->current_status;
|
||||
}
|
||||
|
||||
|
@ -118,6 +126,15 @@ class ApmProductStatus {
|
|||
return $this->current_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if there was a request failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_request_failure(): bool {
|
||||
return $this->has_request_failure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the persisted result to force a recheck.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue