$store['store_url'], 'consumer_key' => Security::decrypt($store['consumer_key']), 'consumer_secret' => Security::decrypt($store['consumer_secret']), 'webhook_secret' => $store['webhook_secret'] ?? null ]; } /** * Save or update WooCommerce connection */ public static function saveStore(int $companyId, string $storeUrl, string $consumerKey, string $consumerSecret, ?string $webhookSecret = null): string { $encryptedKey = Security::encrypt($consumerKey); $encryptedSecret = Security::encrypt($consumerSecret); $existing = self::findByCompany($companyId); $data = [ 'company_id' => $companyId, 'store_url' => rtrim($storeUrl, '/'), 'consumer_key' => $encryptedKey, 'consumer_secret' => $encryptedSecret, 'webhook_secret' => $webhookSecret ]; if ($existing) { self::update($existing['id'], $data); return $existing['id']; } else { return self::create($data); } } /** * Delete WooCommerce connection */ public static function deleteByCompany(int $companyId): int { return Database::execute( "DELETE FROM " . static::$table . " WHERE company_id = ?", [$companyId] ); } }