mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Fix merge conflicts
This commit is contained in:
commit
baee53e90f
60 changed files with 3162 additions and 366 deletions
|
@ -337,7 +337,8 @@ return array(
|
|||
$signup_link_cache,
|
||||
$signup_link_ids,
|
||||
$pui_status_cache,
|
||||
$dcc_status_cache
|
||||
$dcc_status_cache,
|
||||
$container->get( 'http.redirector' )
|
||||
);
|
||||
},
|
||||
'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
|
||||
|
@ -645,7 +646,7 @@ return array(
|
|||
>',
|
||||
'</a>'
|
||||
),
|
||||
'options' => $container->get( 'wcgateway.all-funding-sources' ),
|
||||
'options' => $container->get( 'wcgateway.settings.funding-sources' ),
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
State::STATE_ONBOARDED,
|
||||
|
@ -883,6 +884,17 @@ return array(
|
|||
'sofort' => _x( 'Sofort', 'Name of payment method', 'woocommerce-paypal-payments' ),
|
||||
'venmo' => _x( 'Venmo', 'Name of payment method', 'woocommerce-paypal-payments' ),
|
||||
'trustly' => _x( 'Trustly', 'Name of payment method', 'woocommerce-paypal-payments' ),
|
||||
'paylater' => _x( 'Pay Later', 'Name of payment method', 'woocommerce-paypal-payments' ),
|
||||
);
|
||||
},
|
||||
'wcgateway.settings.funding-sources' => static function( ContainerInterface $container ): array {
|
||||
return array_diff_key(
|
||||
$container->get( 'wcgateway.all-funding-sources' ),
|
||||
array_flip(
|
||||
array(
|
||||
'paylater',
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -941,7 +953,8 @@ return array(
|
|||
$settings,
|
||||
$partner_endpoint,
|
||||
$container->get( 'dcc.status-cache' ),
|
||||
$container->get( 'api.helpers.dccapplies' )
|
||||
$container->get( 'api.helpers.dccapplies' ),
|
||||
$container->get( 'onboarding.state' )
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -953,9 +966,11 @@ return array(
|
|||
|
||||
'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
|
||||
return new FundingSourceRenderer(
|
||||
$container->get( 'wcgateway.settings' )
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.all-funding-sources' )
|
||||
);
|
||||
},
|
||||
|
||||
'wcgateway.checkout-helper' => static function ( ContainerInterface $container ): CheckoutHelper {
|
||||
return new CheckoutHelper();
|
||||
},
|
||||
|
@ -1009,7 +1024,8 @@ return array(
|
|||
return new PayUponInvoiceProductStatus(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'api.endpoint.partners' ),
|
||||
$container->get( 'pui.status-cache' )
|
||||
$container->get( 'pui.status-cache' ),
|
||||
$container->get( 'onboarding.state' )
|
||||
);
|
||||
},
|
||||
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
|
||||
|
@ -1250,7 +1266,7 @@ return array(
|
|||
|
||||
$dcc_enabled = $dcc_product_status->dcc_is_active();
|
||||
|
||||
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
|
||||
$enabled_status_text = esc_html__( 'Status: Available', 'woocommerce-paypal-payments' );
|
||||
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
|
||||
|
||||
$dcc_button_text = $dcc_enabled
|
||||
|
@ -1283,7 +1299,7 @@ return array(
|
|||
|
||||
$pui_enabled = $pui_product_status->pui_is_active();
|
||||
|
||||
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
|
||||
$enabled_status_text = esc_html__( 'Status: Available', 'woocommerce-paypal-payments' );
|
||||
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
|
||||
|
||||
$enable_pui_url = $environment->current_environment_is( Environment::PRODUCTION )
|
||||
|
@ -1334,24 +1350,10 @@ return array(
|
|||
assert( $settings instanceof Settings );
|
||||
|
||||
$button_locations = $container->get( 'wcgateway.button.locations' );
|
||||
unset( $button_locations['mini-cart'] );
|
||||
|
||||
$smart_button_selected_locations = $settings->has( 'smart_button_locations' ) ? $settings->get( 'smart_button_locations' ) : array();
|
||||
$pay_later_button_locations = array();
|
||||
|
||||
if ( empty( $smart_button_selected_locations ) ) {
|
||||
return $pay_later_button_locations;
|
||||
}
|
||||
|
||||
foreach ( $button_locations as $location_key => $location ) {
|
||||
if ( ! in_array( $location_key, $smart_button_selected_locations, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pay_later_button_locations[ $location_key ] = $location;
|
||||
}
|
||||
|
||||
return $pay_later_button_locations;
|
||||
return array_intersect_key( $button_locations, array_flip( $smart_button_selected_locations ) );
|
||||
},
|
||||
'wcgateway.ppcp-gateways' => static function ( ContainerInterface $container ): array {
|
||||
return array(
|
||||
|
|
|
@ -22,13 +22,32 @@ class FundingSourceRenderer {
|
|||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* Map funding source ID -> human-readable name.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $funding_sources;
|
||||
|
||||
/**
|
||||
* The IDs of the sources belonging to PayPal that do not need to mention "via PayPal".
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $own_funding_sources = array( 'venmo', 'paylater' );
|
||||
|
||||
/**
|
||||
* FundingSourceRenderer constructor.
|
||||
*
|
||||
* @param ContainerInterface $settings The settings.
|
||||
* @param ContainerInterface $settings The settings.
|
||||
* @param array<string, string> $funding_sources Map funding source ID -> human-readable name.
|
||||
*/
|
||||
public function __construct( ContainerInterface $settings ) {
|
||||
$this->settings = $settings;
|
||||
public function __construct(
|
||||
ContainerInterface $settings,
|
||||
array $funding_sources
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->funding_sources = $funding_sources;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,9 +56,17 @@ class FundingSourceRenderer {
|
|||
* @param string $id The ID of the funding source, such as 'venmo'.
|
||||
*/
|
||||
public function render_name( string $id ): string {
|
||||
if ( 'venmo' === $id ) {
|
||||
return __( 'Venmo', 'woocommerce-paypal-payments' );
|
||||
if ( array_key_exists( $id, $this->funding_sources ) ) {
|
||||
if ( in_array( $id, $this->own_funding_sources, true ) ) {
|
||||
return $this->funding_sources[ $id ];
|
||||
}
|
||||
return sprintf(
|
||||
/* translators: %s - Sofort, BLIK, iDeal, Mercado Pago, etc. */
|
||||
__( '%s (via PayPal)', 'woocommerce-paypal-payments' ),
|
||||
$this->funding_sources[ $id ]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->settings->has( 'title' ) ?
|
||||
$this->settings->get( 'title' )
|
||||
: __( 'PayPal', 'woocommerce-paypal-payments' );
|
||||
|
@ -51,9 +78,14 @@ class FundingSourceRenderer {
|
|||
* @param string $id The ID of the funding source, such as 'venmo'.
|
||||
*/
|
||||
public function render_description( string $id ): string {
|
||||
if ( 'venmo' === $id ) {
|
||||
return __( 'Pay via Venmo.', 'woocommerce-paypal-payments' );
|
||||
if ( array_key_exists( $id, $this->funding_sources ) ) {
|
||||
return sprintf(
|
||||
/* translators: %s - Sofort, BLIK, iDeal, Mercado Pago, etc. */
|
||||
__( 'Pay via %s.', 'woocommerce-paypal-payments' ),
|
||||
$this->funding_sources[ $id ]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->settings->has( 'description' ) ?
|
||||
$this->settings->get( 'description' )
|
||||
: __( 'Pay via PayPal.', 'woocommerce-paypal-payments' );
|
||||
|
|
|
@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
@ -57,6 +58,13 @@ class DCCProductStatus {
|
|||
*/
|
||||
protected $dcc_applies;
|
||||
|
||||
/**
|
||||
* The onboarding state.
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
private $onboarding_state;
|
||||
|
||||
/**
|
||||
* DccProductStatus constructor.
|
||||
*
|
||||
|
@ -64,17 +72,20 @@ class DCCProductStatus {
|
|||
* @param PartnersEndpoint $partners_endpoint The Partner Endpoint.
|
||||
* @param Cache $cache The cache.
|
||||
* @param DccApplies $dcc_applies The dcc applies helper.
|
||||
* @param State $onboarding_state The onboarding state.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
PartnersEndpoint $partners_endpoint,
|
||||
Cache $cache,
|
||||
DccApplies $dcc_applies
|
||||
DccApplies $dcc_applies,
|
||||
State $onboarding_state
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
$this->cache = $cache;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->onboarding_state = $onboarding_state;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,6 +94,10 @@ class DCCProductStatus {
|
|||
* @return bool
|
||||
*/
|
||||
public function dcc_is_active() : bool {
|
||||
if ( $this->onboarding_state->current_state() < State::STATE_ONBOARDED ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->cache->has( self::DCC_STATUS_CACHE_KEY ) ) {
|
||||
return (bool) $this->cache->get( self::DCC_STATUS_CACHE_KEY );
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use Throwable;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
@ -49,21 +50,31 @@ class PayUponInvoiceProductStatus {
|
|||
*/
|
||||
private $partners_endpoint;
|
||||
|
||||
/**
|
||||
* The onboarding status
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
private $onboarding_state;
|
||||
|
||||
/**
|
||||
* PayUponInvoiceProductStatus constructor.
|
||||
*
|
||||
* @param Settings $settings The Settings.
|
||||
* @param PartnersEndpoint $partners_endpoint The Partner Endpoint.
|
||||
* @param Cache $cache The cache.
|
||||
* @param State $onboarding_state The onboarding state.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
PartnersEndpoint $partners_endpoint,
|
||||
Cache $cache
|
||||
Cache $cache,
|
||||
State $onboarding_state
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
$this->cache = $cache;
|
||||
$this->onboarding_state = $onboarding_state;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,6 +83,10 @@ class PayUponInvoiceProductStatus {
|
|||
* @return bool
|
||||
*/
|
||||
public function pui_is_active() : bool {
|
||||
if ( $this->onboarding_state->current_state() < State::STATE_ONBOARDED ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->cache->has( self::PUI_STATUS_CACHE_KEY ) ) {
|
||||
return (bool) $this->cache->get( self::PUI_STATUS_CACHE_KEY );
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +36,6 @@ class SettingsStatus {
|
|||
* Check whether Pay Later message is enabled either for checkout, cart or product page.
|
||||
*
|
||||
* @return bool true if is enabled, otherwise false.
|
||||
* @throws NotFoundException When a setting was not found.
|
||||
*/
|
||||
public function is_pay_later_messaging_enabled(): bool {
|
||||
$messaging_enabled = $this->settings->has( 'pay_later_messaging_enabled' ) && $this->settings->get( 'pay_later_messaging_enabled' );
|
||||
|
@ -51,27 +49,15 @@ class SettingsStatus {
|
|||
*
|
||||
* @param string $location The location setting name.
|
||||
* @return bool true if is enabled, otherwise false.
|
||||
* @throws NotFoundException When a setting was not found.
|
||||
*/
|
||||
public function is_pay_later_messaging_enabled_for_location( string $location ): bool {
|
||||
if ( ! $this->is_pay_later_messaging_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$selected_locations = $this->settings->has( 'pay_later_messaging_locations' ) ? $this->settings->get( 'pay_later_messaging_locations' ) : array();
|
||||
|
||||
if ( empty( $selected_locations ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array( $location, $selected_locations, true );
|
||||
return $this->is_pay_later_messaging_enabled() && $this->is_enabled_for_location( 'pay_later_messaging_locations', $location );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether Pay Later button is enabled either for checkout, cart or product page.
|
||||
*
|
||||
* @return bool true if is enabled, otherwise false.
|
||||
* @throws NotFoundException When a setting was not found.
|
||||
*/
|
||||
public function is_pay_later_button_enabled(): bool {
|
||||
$pay_later_button_enabled = $this->settings->has( 'pay_later_button_enabled' ) && $this->settings->get( 'pay_later_button_enabled' );
|
||||
|
@ -85,45 +71,11 @@ class SettingsStatus {
|
|||
*
|
||||
* @param string $location The location.
|
||||
* @return bool true if is enabled, otherwise false.
|
||||
* @throws NotFoundException When a setting was not found.
|
||||
*/
|
||||
public function is_pay_later_button_enabled_for_location( string $location ): bool {
|
||||
if ( ! $this->is_pay_later_button_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$selected_locations = $this->settings->has( 'pay_later_button_locations' ) ? $this->settings->get( 'pay_later_button_locations' ) : array();
|
||||
|
||||
if ( empty( $selected_locations ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array( $location, $selected_locations, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether Pay Later button is enabled for a given context.
|
||||
*
|
||||
* @param string $context The context.
|
||||
* @return bool true if is enabled, otherwise false.
|
||||
* @throws NotFoundException When a setting was not found.
|
||||
*/
|
||||
public function is_pay_later_button_enabled_for_context( string $context ): bool {
|
||||
if ( ! $this->is_pay_later_button_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$selected_locations = $this->settings->has( 'pay_later_button_locations' ) ? $this->settings->get( 'pay_later_button_locations' ) : array();
|
||||
|
||||
if ( empty( $selected_locations ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$enabled_for_current_location = $this->is_pay_later_button_enabled_for_location( $context );
|
||||
$enabled_for_product = $this->is_pay_later_button_enabled_for_location( 'product' );
|
||||
$enabled_for_mini_cart = $this->is_pay_later_button_enabled_for_location( 'mini-cart' );
|
||||
|
||||
return $context === 'product' ? $enabled_for_product || $enabled_for_mini_cart : $enabled_for_current_location;
|
||||
return $this->is_pay_later_button_enabled() &&
|
||||
( $this->is_enabled_for_location( 'pay_later_button_locations', $location ) ||
|
||||
( 'product' === $location && $this->is_enabled_for_location( 'pay_later_button_locations', 'mini-cart' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +85,33 @@ class SettingsStatus {
|
|||
* @return bool true if is enabled, otherwise false.
|
||||
*/
|
||||
public function is_smart_button_enabled_for_location( string $location ): bool {
|
||||
$selected_locations = $this->settings->has( 'smart_button_locations' ) ? $this->settings->get( 'smart_button_locations' ) : array();
|
||||
return $this->is_enabled_for_location( 'smart_button_locations', $location );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts the context value to match the location settings.
|
||||
*
|
||||
* @param string $location The location/context.
|
||||
* @return string
|
||||
*/
|
||||
protected function normalize_location( string $location ): string {
|
||||
if ( 'pay-now' === $location ) {
|
||||
$location = 'checkout';
|
||||
}
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the locations field in the settings includes the given location.
|
||||
*
|
||||
* @param string $setting_name The name of the enabled locations field in the settings.
|
||||
* @param string $location The location.
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_enabled_for_location( string $setting_name, string $location ): bool {
|
||||
$location = $this->normalize_location( $location );
|
||||
|
||||
$selected_locations = $this->settings->has( $setting_name ) ? $this->settings->get( $setting_name ) : array();
|
||||
|
||||
if ( empty( $selected_locations ) ) {
|
||||
return false;
|
||||
|
|
|
@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\Http\RedirectorInterface;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
|
||||
|
@ -111,20 +112,28 @@ class SettingsListener {
|
|||
*/
|
||||
protected $dcc_status_cache;
|
||||
|
||||
/**
|
||||
* The HTTP redirector.
|
||||
*
|
||||
* @var RedirectorInterface
|
||||
*/
|
||||
protected $redirector;
|
||||
|
||||
/**
|
||||
* SettingsListener constructor.
|
||||
*
|
||||
* @param Settings $settings The settings.
|
||||
* @param array $setting_fields The setting fields.
|
||||
* @param WebhookRegistrar $webhook_registrar The Webhook Registrar.
|
||||
* @param Cache $cache The Cache.
|
||||
* @param State $state The state.
|
||||
* @param Bearer $bearer The bearer.
|
||||
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
|
||||
* @param Cache $signup_link_cache The signup link cache.
|
||||
* @param array $signup_link_ids Signup link ids.
|
||||
* @param Cache $pui_status_cache The PUI status cache.
|
||||
* @param Cache $dcc_status_cache The DCC status cache.
|
||||
* @param Settings $settings The settings.
|
||||
* @param array $setting_fields The setting fields.
|
||||
* @param WebhookRegistrar $webhook_registrar The Webhook Registrar.
|
||||
* @param Cache $cache The Cache.
|
||||
* @param State $state The state.
|
||||
* @param Bearer $bearer The bearer.
|
||||
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
|
||||
* @param Cache $signup_link_cache The signup link cache.
|
||||
* @param array $signup_link_ids Signup link ids.
|
||||
* @param Cache $pui_status_cache The PUI status cache.
|
||||
* @param Cache $dcc_status_cache The DCC status cache.
|
||||
* @param RedirectorInterface $redirector The HTTP redirector.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
|
@ -137,7 +146,8 @@ class SettingsListener {
|
|||
Cache $signup_link_cache,
|
||||
array $signup_link_ids,
|
||||
Cache $pui_status_cache,
|
||||
Cache $dcc_status_cache
|
||||
Cache $dcc_status_cache,
|
||||
RedirectorInterface $redirector
|
||||
) {
|
||||
|
||||
$this->settings = $settings;
|
||||
|
@ -151,6 +161,7 @@ class SettingsListener {
|
|||
$this->signup_link_ids = $signup_link_ids;
|
||||
$this->pui_status_cache = $pui_status_cache;
|
||||
$this->dcc_status_cache = $dcc_status_cache;
|
||||
$this->redirector = $redirector;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,12 +209,13 @@ class SettingsListener {
|
|||
$redirect_url = add_query_arg( 'ppcp-onboarding-error', '1', $redirect_url );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_url, 302 );
|
||||
exit;
|
||||
$this->redirector->redirect( $redirect_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent enabling both Pay Later messaging and PayPal vaulting
|
||||
*
|
||||
* @throws RuntimeException When API request fails.
|
||||
*/
|
||||
public function listen_for_vaulting_enabled() {
|
||||
if ( ! $this->is_valid_site_request() || State::STATE_ONBOARDED !== $this->state->current_state() ) {
|
||||
|
@ -223,16 +235,7 @@ class SettingsListener {
|
|||
$this->settings->set( 'vault_enabled_dcc', false );
|
||||
$this->settings->persist();
|
||||
|
||||
add_action(
|
||||
'admin_notices',
|
||||
function () use ( $exception ) {
|
||||
printf(
|
||||
'<div class="notice notice-error"><p>%1$s</p><p>%2$s</p></div>',
|
||||
esc_html__( 'Authentication with PayPal failed: ', 'woocommerce-paypal-payments' ) . esc_attr( $exception->getMessage() ),
|
||||
wp_kses_post( __( 'Please verify your API Credentials and try again to connect your PayPal business account. Visit the <a href="https://docs.woocommerce.com/document/woocommerce-paypal-payments/" target="_blank">plugin documentation</a> for more information about the setup.', 'woocommerce-paypal-payments' ) )
|
||||
);
|
||||
}
|
||||
);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -324,16 +327,6 @@ class SettingsListener {
|
|||
}
|
||||
$this->settings->persist();
|
||||
|
||||
if ( $credentials_change_status ) {
|
||||
if ( in_array(
|
||||
$credentials_change_status,
|
||||
array( self::CREDENTIALS_ADDED, self::CREDENTIALS_CHANGED ),
|
||||
true
|
||||
) ) {
|
||||
$this->webhook_registrar->register();
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) {
|
||||
$this->cache->delete( PayPalBearer::CACHE_KEY );
|
||||
}
|
||||
|
@ -347,7 +340,7 @@ class SettingsListener {
|
|||
}
|
||||
|
||||
$redirect_url = false;
|
||||
if ( self::CREDENTIALS_ADDED === $credentials_change_status ) {
|
||||
if ( self::CREDENTIALS_UNCHANGED !== $credentials_change_status ) {
|
||||
$redirect_url = $this->get_onboarding_redirect_url();
|
||||
}
|
||||
|
||||
|
@ -356,8 +349,7 @@ class SettingsListener {
|
|||
}
|
||||
|
||||
if ( $redirect_url ) {
|
||||
wp_safe_redirect( $redirect_url, 302 );
|
||||
exit;
|
||||
$this->redirector->redirect( $redirect_url );
|
||||
}
|
||||
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
|
@ -534,6 +526,8 @@ class SettingsListener {
|
|||
|
||||
/**
|
||||
* Prevent enabling tracking if it is not enabled for merchant account.
|
||||
*
|
||||
* @throws RuntimeException When API request fails.
|
||||
*/
|
||||
public function listen_for_tracking_enabled(): void {
|
||||
if ( State::STATE_ONBOARDED !== $this->state->current_state() ) {
|
||||
|
@ -551,16 +545,7 @@ class SettingsListener {
|
|||
$this->settings->set( 'tracking_enabled', false );
|
||||
$this->settings->persist();
|
||||
|
||||
add_action(
|
||||
'admin_notices',
|
||||
function () use ( $exception ) {
|
||||
printf(
|
||||
'<div class="notice notice-error"><p>%1$s</p><p>%2$s</p></div>',
|
||||
esc_html__( 'Authentication with PayPal failed: ', 'woocommerce-paypal-payments' ) . esc_attr( $exception->getMessage() ),
|
||||
wp_kses_post( __( 'Please verify your API Credentials and try again to connect your PayPal business account. Visit the <a href="https://docs.woocommerce.com/document/woocommerce-paypal-payments/" target="_blank">plugin documentation</a> for more information about the setup.', 'woocommerce-paypal-payments' ) )
|
||||
);
|
||||
}
|
||||
);
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway;
|
|||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Throwable;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
use WC_Order;
|
||||
|
@ -179,7 +180,7 @@ class WCGatewayModule implements ModuleInterface {
|
|||
$c->get( 'onboarding.environment' ),
|
||||
$settings_status->is_pay_later_button_enabled(),
|
||||
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
|
||||
$c->get( 'wcgateway.all-funding-sources' )
|
||||
$c->get( 'wcgateway.settings.funding-sources' )
|
||||
);
|
||||
$assets->register_assets();
|
||||
}
|
||||
|
@ -453,14 +454,30 @@ class WCGatewayModule implements ModuleInterface {
|
|||
'admin_init',
|
||||
static function () use ( $container ) {
|
||||
$listener = $container->get( 'wcgateway.settings.listener' );
|
||||
/**
|
||||
* The settings listener.
|
||||
*
|
||||
* @var SettingsListener $listener
|
||||
*/
|
||||
assert( $listener instanceof SettingsListener );
|
||||
|
||||
$listener->listen_for_merchant_id();
|
||||
$listener->listen_for_vaulting_enabled();
|
||||
$listener->listen_for_tracking_enabled();
|
||||
|
||||
try {
|
||||
$listener->listen_for_vaulting_enabled();
|
||||
$listener->listen_for_tracking_enabled();
|
||||
} catch ( RuntimeException $exception ) {
|
||||
add_action(
|
||||
'admin_notices',
|
||||
function () use ( $exception ) {
|
||||
printf(
|
||||
'<div class="notice notice-error"><p>%1$s</p><p>%2$s</p></div>',
|
||||
esc_html__( 'Authentication with PayPal failed: ', 'woocommerce-paypal-payments' ) . esc_attr( $exception->getMessage() ),
|
||||
wp_kses_post(
|
||||
__(
|
||||
'Please verify your API Credentials and try again to connect your PayPal business account. Visit the <a href="https://docs.woocommerce.com/document/woocommerce-paypal-payments/" target="_blank">plugin documentation</a> for more information about the setup.',
|
||||
'woocommerce-paypal-payments'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue