You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if ( ! $this->reader_service || ! $this->reader_service->get_merchant_id() ) {
259
-
// Try to reinitialize services if they're missing
260
-
if ( ! empty( $this->api_key ) ) {
261
-
$this->init_services();
262
-
}
263
-
264
-
// Check again after potential reinitialization
265
-
if ( ! $this->reader_service || ! $this->reader_service->get_merchant_id() ) {
266
-
echo'<div class="woocommerce-error">';
267
-
echo'<p>' . esc_html__( 'SumUp Terminal is not properly configured. Please contact the store administrator.', 'sumup-terminal-for-woocommerce' ) . '</p>';
268
-
echo'</div>';
257
+
// Check if services are available and API key is valid
echo'<p>' . esc_html__( 'SumUp Terminal is not properly configured. Please contact the store administrator.', 'sumup-terminal-for-woocommerce' ) . '</p>';
261
+
echo'</div>';
269
262
270
-
return;
271
-
}
263
+
return;
264
+
}
265
+
266
+
// Check if we can get the merchant code (this will use caching)
echo'<p>' . esc_html__( 'SumUp Terminal is not properly configured. Please contact the store administrator.', 'sumup-terminal-for-woocommerce' ) . '</p>';
271
+
echo'</div>';
272
+
273
+
return;
272
274
}
273
275
274
276
// Get available readers
@@ -347,10 +349,17 @@ public function payment_fields(): void {
347
349
* @return bool
348
350
*/
349
351
publicfunctionprocess_admin_options() {
350
-
$result = parent::process_admin_options();
352
+
$old_api_key = $this->api_key;
353
+
$result = parent::process_admin_options();
351
354
352
355
// Reload the API key and reinitialize services.
353
356
$this->api_key = $this->get_option( 'api_key' );
357
+
358
+
// Clear cache if API key changed
359
+
if ( $old_api_key !== $this->api_key && $this->profile_service ) {
360
+
$this->profile_service->clear_cache();
361
+
}
362
+
354
363
$this->init_services();
355
364
356
365
return$result;
@@ -467,14 +476,11 @@ private function init_services(): void {
// Note: We no longer fetch merchant_code here to avoid unnecessary API calls.
483
+
// The merchant_code will be fetched lazily when needed and cached.
478
484
}
479
485
480
486
@@ -489,10 +495,10 @@ private function get_connection_status_html() {
489
495
return$this->render_status_card( 'error', __( 'API Key Required', 'sumup-terminal-for-woocommerce' ), __( 'Enter your SumUp API Key above to connect to SumUp.', 'sumup-terminal-for-woocommerce' ) );
490
496
}
491
497
492
-
// Test the API key.
493
-
$api_key_valid = $this->test_api_key();
498
+
// Get the profile once and use it for all checks (this will use caching)
499
+
$profile = $this->profile_service->get_profile();
494
500
495
-
if ( ! $api_key_valid ) {
501
+
if ( ! $profile ) {
496
502
return$this->render_status_card( 'error', __( 'Connection Failed', 'sumup-terminal-for-woocommerce' ), __( 'Unable to connect to SumUp. Please check your API key.', 'sumup-terminal-for-woocommerce' ) );
497
503
}
498
504
@@ -502,9 +508,9 @@ private function get_connection_status_html() {
502
508
// 1. API Connection Status.
503
509
$html .= $this->render_status_card( 'success', __( 'Connected to SumUp', 'sumup-terminal-for-woocommerce' ), __( 'API key is valid and ready to process payments.', 'sumup-terminal-for-woocommerce' ) );
504
510
505
-
// 2. Merchant Information.
511
+
// 2. Merchant Information (pass the profile to avoid another API call).
0 commit comments