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
|
@ -24,6 +24,8 @@ return array(
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$is_available = $container->get( 'googlepay.available' );
|
||||||
|
|
||||||
$insert_after = function( array $array, string $key, array $new ): array {
|
$insert_after = function( array $array, string $key, array $new ): array {
|
||||||
$keys = array_keys( $array );
|
$keys = array_keys( $array );
|
||||||
$index = array_search( $key, $keys, true );
|
$index = array_search( $key, $keys, true );
|
||||||
|
@ -66,6 +68,15 @@ return array(
|
||||||
->action_visible( 'googlepay_button_language' )
|
->action_visible( 'googlepay_button_language' )
|
||||||
->action_visible( 'googlepay_button_shipping_enabled' )
|
->action_visible( 'googlepay_button_shipping_enabled' )
|
||||||
->to_array(),
|
->to_array(),
|
||||||
|
$display_manager
|
||||||
|
->rule()
|
||||||
|
->condition_is_true( $is_available )
|
||||||
|
->action_enable( 'googlepay_button_enabled' )
|
||||||
|
->action_enable( 'googlepay_button_type' )
|
||||||
|
->action_enable( 'googlepay_button_color' )
|
||||||
|
->action_enable( 'googlepay_button_language' )
|
||||||
|
->action_enable( 'googlepay_button_shipping_enabled' )
|
||||||
|
->to_array(),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Googlepay;
|
||||||
|
|
||||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodTypeInterface;
|
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodTypeInterface;
|
||||||
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator;
|
||||||
use WooCommerce\PayPalCommerce\Googlepay\Assets\BlocksPaymentMethod;
|
use WooCommerce\PayPalCommerce\Googlepay\Assets\BlocksPaymentMethod;
|
||||||
use WooCommerce\PayPalCommerce\Googlepay\Assets\Button;
|
use WooCommerce\PayPalCommerce\Googlepay\Assets\Button;
|
||||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmApplies;
|
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmApplies;
|
||||||
|
@ -37,7 +38,7 @@ return array(
|
||||||
|
|
||||||
// If GooglePay is configured.
|
// If GooglePay is configured.
|
||||||
'googlepay.available' => static function ( ContainerInterface $container ): bool {
|
'googlepay.available' => static function ( ContainerInterface $container ): bool {
|
||||||
if ( apply_filters( 'woocommerce_paypal_payments_googlepay_validate_product_status', false ) ) {
|
if ( apply_filters( 'woocommerce_paypal_payments_googlepay_validate_product_status', true ) ) {
|
||||||
$status = $container->get( 'googlepay.helpers.apm-product-status' );
|
$status = $container->get( 'googlepay.helpers.apm-product-status' );
|
||||||
assert( $status instanceof ApmProductStatus );
|
assert( $status instanceof ApmProductStatus );
|
||||||
/**
|
/**
|
||||||
|
@ -48,13 +49,15 @@ return array(
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
'googlepay.helpers.apm-product-status' => static function( ContainerInterface $container ): ApmProductStatus {
|
'googlepay.helpers.apm-product-status' => SingletonDecorator::make(
|
||||||
return new ApmProductStatus(
|
static function( ContainerInterface $container ): ApmProductStatus {
|
||||||
$container->get( 'wcgateway.settings' ),
|
return new ApmProductStatus(
|
||||||
$container->get( 'api.endpoint.partners' ),
|
$container->get( 'wcgateway.settings' ),
|
||||||
$container->get( 'onboarding.state' )
|
$container->get( 'api.endpoint.partners' ),
|
||||||
);
|
$container->get( 'onboarding.state' )
|
||||||
},
|
);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The matrix which countries and currency combinations can be used for GooglePay.
|
* The matrix which countries and currency combinations can be used for GooglePay.
|
||||||
|
|
|
@ -10,6 +10,8 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\Googlepay;
|
namespace WooCommerce\PayPalCommerce\Googlepay;
|
||||||
|
|
||||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
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\Button\Assets\ButtonInterface;
|
||||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||||
|
@ -46,6 +48,66 @@ class GooglepayModule implements ModuleInterface {
|
||||||
$button->initialize();
|
$button->initialize();
|
||||||
|
|
||||||
if ( ! $c->get( 'googlepay.available' ) ) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,13 @@ class ApmProductStatus {
|
||||||
*/
|
*/
|
||||||
private $current_status = null;
|
private $current_status = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there was a request failure.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $has_request_failure = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The settings.
|
* The settings.
|
||||||
*
|
*
|
||||||
|
@ -93,7 +100,8 @@ class ApmProductStatus {
|
||||||
$seller_status = $this->partners_endpoint->seller_status();
|
$seller_status = $this->partners_endpoint->seller_status();
|
||||||
} catch ( Throwable $error ) {
|
} catch ( Throwable $error ) {
|
||||||
// It may be a transitory error, don't persist the status.
|
// 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;
|
return $this->current_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +126,15 @@ class ApmProductStatus {
|
||||||
return $this->current_status;
|
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.
|
* Clears the persisted result to force a recheck.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue