Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
04f162c
Add delete_test_account boolean to the route config
elazzabi Jul 4, 2025
857fea3
Delete test account if needed
elazzabi Jul 4, 2025
9640e20
Add /test_drive_account/migrate_to_live route
elazzabi Jul 7, 2025
f93964d
Add transients management for onboarding to live process
elazzabi Jul 7, 2025
cffeccb
Add early exploration for migrate_test_drive_account_to_live function
elazzabi Jul 7, 2025
3f861b8
Revert "Delete test account if needed"
elazzabi Jul 7, 2025
4ac2939
Revert "Add delete_test_account boolean to the route config"
elazzabi Jul 7, 2025
f3779fc
Pass self assessment data to migration function
elazzabi Jul 7, 2025
10febdf
Get current capabilities and use the create_embedded_kyc_session func…
elazzabi Jul 7, 2025
2f80e2a
Move the refresh of the account data to finally
elazzabi Jul 7, 2025
5e03bda
Fix function response type in the controller
elazzabi Jul 7, 2025
8f28e35
If there is a migration happening, return an empty array
elazzabi Jul 7, 2025
1f514b6
Update the migrate_test_drive_account_to_live function to return the …
elazzabi Jul 7, 2025
c14138b
remove extra line
elazzabi Jul 7, 2025
c079f80
add test cases
elazzabi Jul 7, 2025
c758131
Revert new route definition
elazzabi Jul 9, 2025
fa834a2
Add migrate to live query param
elazzabi Jul 9, 2025
e7f66ac
Add migrate_to_live to onboarding request
elazzabi Jul 9, 2025
4e5e93b
remove unnecessary tests
elazzabi Jul 9, 2025
4846ae5
revert earlier changes around new endpoint and lockers
elazzabi Jul 9, 2025
83dde5a
accept boolean for create_embedded_kyc_session and pass it down the c…
elazzabi Jul 9, 2025
e93b576
Check for is_onboarding_init_in_progress instead of is_onboarding_mig…
elazzabi Jul 9, 2025
84f6202
Fix failing test
elazzabi Jul 11, 2025
91eb1e5
Add migrate_to_live flag
elazzabi Jul 11, 2025
39d91f7
add changelog
elazzabi Jul 11, 2025
ed1087a
Merge branch 'develop' into fix/sync-call-account-migration
elazzabi Jul 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/account-migration-feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Make it possible to migrate a test account to a live account
10 changes: 9 additions & 1 deletion includes/admin/class-wc-rest-payments-onboarding-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public function register_routes() {
],
],
],
'migrate_to_live' => [
'required' => false,
'description' => 'Whether to migrate the account to live.',
'type' => 'boolean',
'default' => false,
],
],
]
);
Expand Down Expand Up @@ -227,11 +233,13 @@ public function create_embedded_kyc_session( WP_REST_Request $request ) {
$self_assessment_data = ! empty( $request->get_param( 'self_assessment' ) ) ? wc_clean( wp_unslash( $request->get_param( 'self_assessment' ) ) ) : [];
$progressive = ! empty( $request->get_param( 'progressive' ) ) && filter_var( $request->get_param( 'progressive' ), FILTER_VALIDATE_BOOLEAN );
$capabilities = ! empty( $request->get_param( 'capabilities' ) ) ? wc_clean( wp_unslash( $request->get_param( 'capabilities' ) ) ) : [];
$migrate_to_live = ! empty( $request->get_param( 'migrate_to_live' ) ) && filter_var( $request->get_param( 'migrate_to_live' ), FILTER_VALIDATE_BOOLEAN );

$account_session = $this->onboarding_service->create_embedded_kyc_session(
$self_assessment_data,
$progressive,
$capabilities
$capabilities,
$migrate_to_live
);

if ( $account_session ) {
Expand Down
6 changes: 6 additions & 0 deletions includes/class-wc-payments-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,12 @@ public function get_cached_account_data( bool $force_refresh = false ) {
return [];
}

// Check if there's an ongoing migration to live payments.
if ( $this->onboarding_service->is_onboarding_init_in_progress() ) {
// Return empty array to indicate no account is connected yet.
return [];
}

$refreshed = false;

$account = $this->database_cache->get_or_add(
Expand Down
6 changes: 4 additions & 2 deletions includes/class-wc-payments-onboarding-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ public function should_enable_woopay( bool $default_value, array $capabilities )
* @param array $capabilities Optional. List keyed by capabilities IDs (payment methods) with boolean values
* indicating whether the capability should be requested when the account is created
* and enabled in the settings.
* @param bool $migrate_to_live Whether to migrate the account to live.
*
* @return array Session data.
*
* @throws API_Exception|Exception
*/
public function create_embedded_kyc_session( array $self_assessment_data, bool $progressive = false, array $capabilities = [] ): array {
public function create_embedded_kyc_session( array $self_assessment_data, bool $progressive = false, array $capabilities = [], bool $migrate_to_live = false ): array {
if ( ! $this->payments_api_client->is_server_connected() ) {
return [];
}
Expand Down Expand Up @@ -339,7 +340,8 @@ public function create_embedded_kyc_session( array $self_assessment_data, bool $
WC_Payments_Utils::array_filter_recursive( $account_data ), // nosemgrep: audit.php.lang.misc.array-filter-no-callback -- output of array_filter is escaped.
$actioned_notes,
$progressive,
$this->get_referral_code()
$this->get_referral_code(),
$migrate_to_live
);
} catch ( API_Exception $e ) {
$this->clear_onboarding_init_in_progress();
Expand Down
5 changes: 4 additions & 1 deletion includes/wc-payment-api/class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ public function get_onboarding_data(
* @param array $actioned_notes Actioned notes to be sent.
* @param bool $progressive Whether progressive onboarding should be enabled for this onboarding.
* @param ?string $referral_code Referral code to be used for onboarding.
* @param ?bool $migrate_to_live Whether to migrate the account to live.
*
* @return array
*
Expand All @@ -1107,7 +1108,8 @@ public function initialize_onboarding_embedded_kyc(
array $account_data = [],
array $actioned_notes = [],
bool $progressive = false,
?string $referral_code = null
?string $referral_code = null,
?bool $migrate_to_live = false
): array {
$request_args = apply_filters(
'wc_payments_get_onboarding_data_args',
Expand All @@ -1118,6 +1120,7 @@ public function initialize_onboarding_embedded_kyc(
'actioned_notes' => $actioned_notes,
'create_live_account' => $live_account,
'progressive' => $progressive,
'migrate_to_live' => $migrate_to_live,
]
);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test-class-wc-payments-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ public function test_maybe_handle_onboarding_init_stripe_onboarding_another_onbo

// There is another onboarding started.
$this->mock_onboarding_service
->expects( $this->once() )
->expects( $this->atLeastOnce() )
->method( 'is_onboarding_init_in_progress' )
->willReturn( true );

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test-class-wc-payments-onboarding-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class WC_Payments_Onboarding_Service_Test extends WCPAY_UnitTestCase {
/**
* Mock Database_Cache
*
* @var MockObject
* @var Database_Cache|MockObject
*/
private $mock_database_cache;

/**
* Mock WC_Payments_Session_Service
*
* @var MockObject
* @var WC_Payments_Session_Service|MockObject
*/
private $mock_session_service;

Expand Down
Loading