Skip to content

Commit 13a8145

Browse files
committed
refactor: 🔥 Remove the delayed country check
During onboarding we can now directly fetch the merchant country without requiring a separate request. We still keep the retry logic as a fallback if the back-off triggers for some reason and to populate the country for already onboarded merchants.
1 parent fa1d441 commit 13a8145

3 files changed

Lines changed: 1 addition & 91 deletions

File tree

‎modules/ppcp-settings/src/Service/MerchantDataResolver.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,6 @@ public function ensure_country_resolved(): void {
7373
$this->schedule_retry( 1 );
7474
}
7575

76-
/**
77-
* Connect-time entry point. The connecting request holds a login-bearer API
78-
* client that cannot call seller_status(), so defer the first attempt to a
79-
* fresh, fully-connected request via an immediate async action.
80-
*/
81-
public function schedule_after_connect(): void {
82-
if ( ! $this->needs_resolution() ) {
83-
return;
84-
}
85-
86-
if ( ! function_exists( 'as_enqueue_async_action' ) || ! function_exists( 'as_next_scheduled_action' ) ) {
87-
return;
88-
}
89-
90-
$args = array( 'attempt' => 1 );
91-
92-
if ( as_next_scheduled_action( self::RETRY_HOOK, $args ) ) {
93-
return;
94-
}
95-
96-
as_enqueue_async_action( self::RETRY_HOOK, $args );
97-
}
98-
9976
/**
10077
* ActionScheduler retry handler.
10178
*

‎modules/ppcp-settings/src/SettingsModule.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static function () use ( $container ): void {
374374

375375
$country_resolver = $container->get( 'settings.service.merchant-data-resolver' );
376376
assert( $country_resolver instanceof MerchantDataResolver );
377-
$country_resolver->schedule_after_connect();
377+
$country_resolver->ensure_country_resolved();
378378

379379
$onboarding_profile = $container->get( 'settings.data.onboarding' );
380380
assert( $onboarding_profile instanceof OnboardingProfile );

‎tests/PHPUnit/Settings/Service/MerchantDataResolverTest.php‎

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -288,71 +288,4 @@ public function test_ensure_country_resolved_does_not_duplicate_pending_retry():
288288
$resolver = $this->create_resolver();
289289
$this->assertNull( $resolver->ensure_country_resolved() );
290290
}
291-
292-
/**
293-
* GIVEN a merchant that is not connected to PayPal
294-
* WHEN schedule_after_connect() runs
295-
* THEN no async action is enqueued
296-
*/
297-
public function test_schedule_after_connect_does_nothing_when_merchant_is_not_connected(): void {
298-
$this->general_settings->shouldReceive( 'is_merchant_connected' )->andReturn( false );
299-
$this->general_settings->shouldNotReceive( 'get_merchant_data' );
300-
301-
expect( 'as_enqueue_async_action' )->never();
302-
303-
$resolver = $this->create_resolver();
304-
$this->assertNull( $resolver->schedule_after_connect() );
305-
}
306-
307-
/**
308-
* GIVEN a connected merchant whose country is already known
309-
* WHEN schedule_after_connect() runs
310-
* THEN no async action is enqueued
311-
*/
312-
public function test_schedule_after_connect_does_nothing_when_country_already_known(): void {
313-
$this->general_settings->shouldReceive( 'is_merchant_connected' )->andReturn( true );
314-
$this->general_settings->shouldReceive( 'get_merchant_data' )
315-
->andReturn( $this->merchant_data( 'DE' ) );
316-
317-
expect( 'as_enqueue_async_action' )->never();
318-
319-
$resolver = $this->create_resolver();
320-
$this->assertNull( $resolver->schedule_after_connect() );
321-
}
322-
323-
/**
324-
* GIVEN a connected merchant with an unresolved country and no pending retry
325-
* WHEN schedule_after_connect() runs
326-
* THEN an immediate async action is enqueued for attempt 1
327-
*/
328-
public function test_schedule_after_connect_enqueues_async_first_attempt_when_country_is_empty(): void {
329-
$this->general_settings->shouldReceive( 'is_merchant_connected' )->andReturn( true );
330-
$this->general_settings->shouldReceive( 'get_merchant_data' )
331-
->andReturn( $this->merchant_data( '' ) );
332-
333-
expect( 'as_enqueue_async_action' )->once()->with(
334-
MerchantDataResolver::RETRY_HOOK,
335-
array( 'attempt' => 1 )
336-
);
337-
338-
$resolver = $this->create_resolver();
339-
$this->assertNull( $resolver->schedule_after_connect() );
340-
}
341-
342-
/**
343-
* GIVEN a connected merchant with an unresolved country and a retry already pending
344-
* WHEN schedule_after_connect() runs
345-
* THEN no duplicate async action is enqueued
346-
*/
347-
public function test_schedule_after_connect_does_not_enqueue_when_retry_already_pending(): void {
348-
$this->general_settings->shouldReceive( 'is_merchant_connected' )->andReturn( true );
349-
$this->general_settings->shouldReceive( 'get_merchant_data' )
350-
->andReturn( $this->merchant_data( '' ) );
351-
352-
when( 'as_next_scheduled_action' )->justReturn( true );
353-
expect( 'as_enqueue_async_action' )->never();
354-
355-
$resolver = $this->create_resolver();
356-
$this->assertNull( $resolver->schedule_after_connect() );
357-
}
358291
}

0 commit comments

Comments
 (0)