@@ -145,10 +145,7 @@ public function get_onboarding_details( string $location, string $rest_path, ?st
145
145
// Since getting the onboarding details is not idempotent, we will check it as an action.
146
146
$ this ->check_if_onboarding_action_is_acceptable ();
147
147
148
- if ( empty ( $ source ) ) {
149
- // If no source is provided, we duse the default.
150
- $ source = self ::SESSION_ENTRY_DEFAULT ;
151
- }
148
+ $ source = $ this ->validate_onboarding_source ( $ source );
152
149
153
150
return array (
154
151
// This state is high-level data, independent of the type of onboarding flow.
@@ -376,9 +373,7 @@ public function mark_onboarding_step_started( string $step_id, string $location,
376
373
$ result = $ this ->save_nox_profile_onboarding_step_entry ( $ step_id , $ location , 'statuses ' , $ statuses );
377
374
378
375
if ( $ result ) {
379
- if ( empty ( $ source ) ) {
380
- $ source = self ::SESSION_ENTRY_DEFAULT ;
381
- }
376
+ $ source = $ this ->validate_onboarding_source ( $ source );
382
377
383
378
// Record an event for the step being started.
384
379
$ this ->record_event (
@@ -460,9 +455,7 @@ public function mark_onboarding_step_completed( string $step_id, string $locatio
460
455
$ result = $ this ->save_nox_profile_onboarding_step_entry ( $ step_id , $ location , 'statuses ' , $ statuses );
461
456
462
457
if ( $ result ) {
463
- if ( empty ( $ source ) ) {
464
- $ source = self ::SESSION_ENTRY_DEFAULT ;
465
- }
458
+ $ source = $ this ->validate_onboarding_source ( $ source );
466
459
467
460
// Record an event for the step being completed.
468
461
$ this ->record_event (
@@ -937,9 +930,7 @@ public function onboarding_test_account_init( string $location, ?string $source
937
930
// Lock the onboarding to prevent concurrent actions.
938
931
$ this ->set_onboarding_lock ();
939
932
940
- if ( empty ( $ source ) ) {
941
- $ source = self ::SESSION_ENTRY_DEFAULT ;
942
- }
933
+ $ source = $ this ->validate_onboarding_source ( $ source );
943
934
944
935
try {
945
936
// Call the WooPayments API to initialize the test account.
@@ -1078,9 +1069,7 @@ public function get_onboarding_kyc_session( string $location, array $self_assess
1078
1069
// Lock the onboarding to prevent concurrent actions.
1079
1070
$ this ->set_onboarding_lock ();
1080
1071
1081
- if ( empty ( $ source ) ) {
1082
- $ source = self ::SESSION_ENTRY_DEFAULT ;
1083
- }
1072
+ $ source = $ this ->validate_onboarding_source ( $ source );
1084
1073
1085
1074
try {
1086
1075
// Call the WooPayments API to get the KYC session.
@@ -1202,9 +1191,7 @@ public function finish_onboarding_kyc_session( string $location, ?string $source
1202
1191
// Lock the onboarding to prevent concurrent actions.
1203
1192
$ this ->set_onboarding_lock ();
1204
1193
1205
- if ( empty ( $ source ) ) {
1206
- $ source = self ::SESSION_ENTRY_DEFAULT ;
1207
- }
1194
+ $ source = $ this ->validate_onboarding_source ( $ source );
1208
1195
1209
1196
try {
1210
1197
// Call the WooPayments API to finalize the KYC session.
@@ -1372,9 +1359,7 @@ public function reset_onboarding( string $location, string $from = '', ?string $
1372
1359
// Lock the onboarding to prevent concurrent actions.
1373
1360
$ this ->set_onboarding_lock ();
1374
1361
1375
- if ( empty ( $ source ) ) {
1376
- $ source = self ::SESSION_ENTRY_DEFAULT ;
1377
- }
1362
+ $ source = $ this ->validate_onboarding_source ( $ source );
1378
1363
1379
1364
// Before resetting the account, record its details for tracking purposes.
1380
1365
$ event_props = array (
@@ -1462,9 +1447,7 @@ public function disable_test_account( string $location, string $from = '', ?stri
1462
1447
// Lock the onboarding to prevent concurrent actions.
1463
1448
$ this ->set_onboarding_lock ();
1464
1449
1465
- if ( empty ( $ source ) ) {
1466
- $ source = self ::SESSION_ENTRY_DEFAULT ;
1467
- }
1450
+ $ source = $ this ->validate_onboarding_source ( $ source );
1468
1451
1469
1452
try {
1470
1453
// Call the WooPayments API to disable the test account and prepare for the switch to live.
@@ -2469,4 +2452,24 @@ private function get_overview_page_url(): string {
2469
2452
admin_url ( 'admin.php ' )
2470
2453
);
2471
2454
}
2455
+
2456
+ /**
2457
+ * Check the onboarding source and ensure it is a valid value.
2458
+ *
2459
+ * @param string|null $source The source of the onboarding request.
2460
+ *
2461
+ * @return string The validated onboarding source.
2462
+ */
2463
+ private function validate_onboarding_source ( ?string $ source ): string {
2464
+ if ( empty ( $ source ) ) {
2465
+ return self ::SESSION_ENTRY_DEFAULT ;
2466
+ }
2467
+
2468
+ $ valid_sources = array (
2469
+ self ::SESSION_ENTRY_DEFAULT ,
2470
+ self ::SESSION_ENTRY_LYS ,
2471
+ );
2472
+
2473
+ return in_array ( $ source , $ valid_sources , true ) ? $ source : self ::SESSION_ENTRY_DEFAULT ;
2474
+ }
2472
2475
}
0 commit comments