Merge pull request #657 from woocommerce/PCP-687-do-not-call-partner-referrals-si

Cache partner referrals signup links
This commit is contained in:
Emili Castells 2022-06-14 15:05:15 +02:00 committed by GitHub
commit 259f824dac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 165 additions and 22 deletions

View file

@ -219,7 +219,19 @@ return array(
$cache = new Cache( 'ppcp-paypal-bearer' );
$bearer = $container->get( 'api.bearer' );
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id );
$signup_link_cache = $container->get( 'onboarding.signup-link-cache' );
$signup_link_ids = $container->get( 'onboarding.signup-link-ids' );
return new SettingsListener(
$settings,
$fields,
$webhook_registrar,
$cache,
$state,
$bearer,
$page_id,
$signup_link_cache,
$signup_link_ids
);
},
'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
@ -2217,7 +2229,7 @@ return array(
);
},
'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool {
'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool {
try {
$token = $container->get( 'api.bearer' )->bearer();
return $token->vaulting_available();
@ -2226,7 +2238,7 @@ return array(
}
},
'button.helper.vaulting-label' => static function ( ContainerInterface $container ): string {
'button.helper.vaulting-label' => static function ( ContainerInterface $container ): string {
$vaulting_label = __( 'Enable saved cards and subscription features on your store.', 'woocommerce-paypal-payments' );
if ( ! $container->get( 'wcgateway.helper.vaulting-scope' ) ) {
@ -2248,7 +2260,7 @@ return array(
return $vaulting_label;
},
'wcgateway.settings.fields.pay-later-label' => static function ( ContainerInterface $container ): string {
'wcgateway.settings.fields.pay-later-label' => static function ( ContainerInterface $container ): string {
$pay_later_label = '<span class="ppcp-pay-later-enabled-label">%s</span>';
$pay_later_label .= '<span class="ppcp-pay-later-disabled-label">';
$pay_later_label .= __( "You have PayPal vaulting enabled, that's why Pay Later Messaging options are unavailable now. You cannot use both features at the same time.", 'woocommerce-paypal-payments' );

View file

@ -81,6 +81,20 @@ class SettingsListener {
*/
protected $page_id;
/**
* The signup link cache.
*
* @var Cache
*/
protected $signup_link_cache;
/**
* Signup link ids
*
* @var array
*/
protected $signup_link_ids;
/**
* SettingsListener constructor.
*
@ -91,6 +105,8 @@ class SettingsListener {
* @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.
*/
public function __construct(
Settings $settings,
@ -99,7 +115,9 @@ class SettingsListener {
Cache $cache,
State $state,
Bearer $bearer,
string $page_id
string $page_id,
Cache $signup_link_cache,
array $signup_link_ids
) {
$this->settings = $settings;
@ -109,6 +127,8 @@ class SettingsListener {
$this->state = $state;
$this->bearer = $bearer;
$this->page_id = $page_id;
$this->signup_link_cache = $signup_link_cache;
$this->signup_link_ids = $signup_link_ids;
}
/**
@ -260,6 +280,12 @@ class SettingsListener {
true
) ) {
$this->webhook_registrar->unregister();
foreach ( $this->signup_link_ids as $key ) {
if ( $this->signup_link_cache->has( $key ) ) {
$this->signup_link_cache->delete( $key );
}
}
}
}