Add GooglePay onboarding improvements.

This commit is contained in:
Pedro Silva 2023-09-11 10:04:38 +01:00
parent bad21380b3
commit b703f17bbf
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
7 changed files with 31 additions and 16 deletions

View file

@ -37,12 +37,15 @@ return array(
// If GooglePay is configured.
'googlepay.available' => static function ( ContainerInterface $container ): bool {
/**
* $status = $container->get( 'googlepay.helpers.apm-product-status' );
* assert( $status instanceof ApmProductStatus );
* return $status->is_active();
*/
return true; // TODO: must test further.
if ( apply_filters( 'woocommerce_paypal_payments_googlepay_validate_product_status', false ) ) {
$status = $container->get( 'googlepay.helpers.apm-product-status' );
assert( $status instanceof ApmProductStatus );
/**
* If merchant isn't onboarded by use via /v1/customer/partner-referrals this returns false as the api call fails.
*/
return apply_filters( 'woocommerce_paypal_payments_googlepay_product_status', $status->is_active() );
}
return true;
},
'googlepay.helpers.apm-product-status' => static function( ContainerInterface $container ): ApmProductStatus {
@ -61,7 +64,7 @@ return array(
* Returns which countries and currency combinations can be used for GooglePay.
*/
return apply_filters(
'woocommerce_paypal_payments_supported_country_currency_matrix',
'woocommerce_paypal_payments_googlepay_supported_country_currency_matrix',
array(
'US' => array(
'AUD',

View file

@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/**
* Class GooglepayModule
@ -77,10 +78,15 @@ class GooglepayModule implements ModuleInterface {
// Clear product status handling.
add_action(
'woocommerce_paypal_payments_clear_apm_product_status',
function() use ( $c ): void {
function( Settings $settings = null ) use ( $c ): void {
$apm_status = $c->get( 'googlepay.helpers.apm-product-status' );
assert( $apm_status instanceof ApmProductStatus );
$apm_status->clear();
if ( ! $settings instanceof Settings ) {
$settings = null;
}
$apm_status->clear( $settings );
}
);

View file

@ -121,13 +121,19 @@ class ApmProductStatus {
/**
* Clears the persisted result to force a recheck.
*
* @param Settings|null $settings The settings object.
* We accept a Settings object to don't override other sequential settings that are being updated elsewhere.
* @return void
*/
public function clear(): void {
public function clear( Settings $settings = null ): void {
if ( null === $settings ) {
$settings = $this->settings;
}
$this->current_status = null;
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_UNDEFINED );
$this->settings->persist();
$settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_UNDEFINED );
$settings->persist();
}
}

View file

@ -134,7 +134,7 @@ class LoginSellerEndpoint implements EndpointInterface {
$this->settings->set( 'products_dcc_enabled', null );
$this->settings->set( 'products_pui_enabled', null );
$this->settings->persist();
do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
do_action( 'woocommerce_paypal_payments_clear_apm_product_status', $this->settings );
$endpoint = $is_sandbox ? $this->login_seller_sandbox : $this->login_seller_production;
$credentials = $endpoint->credentials_for(

View file

@ -238,7 +238,7 @@ class OnboardingRESTController {
$settings->set( 'products_dcc_enabled', null );
$settings->set( 'products_pui_enabled', null );
do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
do_action( 'woocommerce_paypal_payments_clear_apm_product_status', $settings );
if ( ! $settings->persist() ) {
return new \WP_Error(

View file

@ -391,7 +391,7 @@ class SettingsListener {
if ( self::CREDENTIALS_UNCHANGED !== $credentials_change_status ) {
$this->settings->set( 'products_dcc_enabled', null );
$this->settings->set( 'products_pui_enabled', null );
do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
do_action( 'woocommerce_paypal_payments_clear_apm_product_status', $this->settings );
}
if ( in_array(

View file

@ -286,7 +286,7 @@ class WCGatewayModule implements ModuleInterface {
$settings->set( 'products_dcc_enabled', false );
$settings->set( 'products_pui_enabled', false );
$settings->persist();
do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
do_action( 'woocommerce_paypal_payments_clear_apm_product_status', $settings );
// Update caches.
$dcc_status = $c->get( 'wcgateway.helper.dcc-product-status' );