Changeset 3379243
- Timestamp:
- 10/16/2025 06:18:56 AM (5 months ago)
- Location:
- ai-story-maker/trunk
- Files:
-
- 4 edited
-
README.txt (modified) (2 diffs)
-
admin/class-aistma-admin.php (modified) (3 diffs)
-
ai-story-maker.php (modified) (1 diff)
-
includes/class-aistma-story-generator.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ai-story-maker/trunk/README.txt
r3379225 r3379243 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.4 7 Stable tag: 2.1. 17 Stable tag: 2.1.2 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 331 331 == Changelog == 332 332 333 = 2.1.2 = 334 * **Maintenance Release** 335 * Version bump for WordPress.org deployment 336 * Ensured compatibility with latest WordPress version 337 * Minor documentation updates 338 333 339 = 2.1.1 = 334 340 * **Security & Code Quality Improvements** -
ai-story-maker/trunk/admin/class-aistma-admin.php
r3379225 r3379243 1147 1147 ); 1148 1148 } 1149 1150 // If subscription check failed but we have an error message, log it for debugging 1151 if ( isset( $subscription_status['error'] ) ) { 1152 $this->aistma_log_manager->log( 'warning', 'Subscription validation failed: ' . $subscription_status['error'] ); 1153 } 1154 1155 // Try fallback: check if UI shows active subscription (packages-summary endpoint) 1156 $fallback_check = $this->check_subscription_via_packages_api(); 1157 if ( $fallback_check['valid'] ) { 1158 $this->aistma_log_manager->log( 'info', 'Subscription validated via packages API fallback' ); 1159 return array( 1160 'valid' => true, 1161 'message' => __( 'Valid subscription found (via packages API)', 'ai-story-maker' ), 1162 'type' => 'subscription' 1163 ); 1164 } 1165 1149 1166 } catch ( \Exception $e ) { 1150 // Subscription check failed, continue to API key check 1167 // Subscription check failed, log the exception and continue to API key check 1168 $this->aistma_log_manager->log( 'warning', 'Subscription check exception: ' . $e->getMessage() ); 1151 1169 } 1152 1170 … … 1251 1269 1252 1270 /** 1271 * Fallback method to check subscription via packages API (same as UI). 1272 * 1273 * @return array Validation result. 1274 */ 1275 private function check_subscription_via_packages_api() { 1276 try { 1277 $settings_page = AISTMA_Settings_Page::get_instance(); 1278 $response_body = $settings_page->aistma_get_available_packages(); 1279 1280 // Parse the response similar to how the UI does it 1281 $decoded_wrapper = json_decode( $response_body, true ); 1282 if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded_wrapper ) && isset( $decoded_wrapper['body'] ) ) { 1283 $packages_json = is_string( $decoded_wrapper['body'] ) ? $decoded_wrapper['body'] : json_encode( $decoded_wrapper['body'] ); 1284 } else { 1285 $packages_json = $response_body; 1286 } 1287 1288 $packages = json_decode( $packages_json, true ); 1289 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $packages ) ) { 1290 return array( 'valid' => false, 'error' => 'Invalid packages response' ); 1291 } 1292 1293 // Check if any package shows an active subscription 1294 foreach ( $packages as $package ) { 1295 if ( is_array( $package ) && isset( $package['subscription_status'] ) && isset( $package['subscription_info'] ) ) { 1296 $subscription_info = $package['subscription_info']; 1297 // Check if subscription is active and has credits 1298 if ( isset( $subscription_info['credits_total'] ) && isset( $subscription_info['credits_used'] ) ) { 1299 $credits_remaining = $subscription_info['credits_total'] - $subscription_info['credits_used']; 1300 if ( $credits_remaining > 0 ) { 1301 $this->aistma_log_manager->log( 'info', 'Active subscription found via packages API: ' . $credits_remaining . ' credits remaining' ); 1302 return array( 'valid' => true, 'credits_remaining' => $credits_remaining ); 1303 } 1304 } 1305 } 1306 } 1307 1308 return array( 'valid' => false, 'error' => 'No active subscription found in packages API' ); 1309 } catch ( \Exception $e ) { 1310 $this->aistma_log_manager->log( 'error', 'Error checking subscription via packages API: ' . $e->getMessage() ); 1311 return array( 'valid' => false, 'error' => 'Packages API check failed: ' . $e->getMessage() ); 1312 } 1313 } 1314 1315 /** 1253 1316 * Get subscription status (helper method). 1254 1317 * … … 1256 1319 */ 1257 1320 private function aistma_get_subscription_status() { 1258 // This method should be implemented based on your subscription checking logic 1259 // For now, we'll use a simplified version 1260 $master_url = defined( 'AISTMA_MASTER_URL' ) ? AISTMA_MASTER_URL : ''; 1261 if ( empty( $master_url ) ) { 1262 return array( 'valid' => false, 'error' => 'Master URL not configured' ); 1263 } 1264 1265 $current_domain = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ?? '' ) ); 1266 if ( empty( $current_domain ) ) { 1267 return array( 'valid' => false, 'error' => 'Domain not detected' ); 1268 } 1269 1270 // Make API call to check subscription status 1271 $response = wp_remote_get( 1272 $master_url . 'wp-json/exaig/v1/verify-subscription?domain=' . urlencode( $current_domain ), 1273 array( 'timeout' => 10 ) 1274 ); 1275 1276 if ( is_wp_error( $response ) ) { 1277 return array( 'valid' => false, 'error' => 'API request failed: ' . $response->get_error_message() ); 1278 } 1279 1280 $body = wp_remote_retrieve_body( $response ); 1281 $data = json_decode( $body, true ); 1282 1283 if ( isset( $data['valid'] ) && $data['valid'] ) { 1284 return array( 1285 'valid' => true, 1286 'domain' => $current_domain, 1287 'package_name' => $data['package_name'] ?? 'Unknown', 1288 'package_id' => $data['package_id'] ?? null 1289 ); 1290 } 1291 1292 return array( 'valid' => false, 'error' => 'No valid subscription found' ); 1321 // Use the story generator's subscription status method 1322 $story_generator = new AISTMA_Story_Generator(); 1323 return $story_generator->aistma_get_subscription_status(); 1293 1324 } 1294 1325 -
ai-story-maker/trunk/ai-story-maker.php
r3379225 r3379243 4 4 * Plugin URI: https://www.storymakerplugin.com/ 5 5 * Description: AI-powered content generator for WordPress — create engaging stories with a single click. 6 * Version: 2.1. 16 * Version: 2.1.2 7 7 * Author: Hayan Mamoun 8 8 * Author URI: https://exedotcom.ca -
ai-story-maker/trunk/includes/class-aistma-story-generator.php
r3379225 r3379243 1008 1008 1009 1009 if ( empty( $master_url ) ) { 1010 $this->aistma_log_manager->log( 'error', 'API Gateway URL not configured' ); 1010 1011 $this->subscription_status = array( 1011 1012 'valid' => false, 1012 1013 'domain' => $domain, 1014 'error' => 'API Gateway URL not configured', 1013 1015 ); 1014 1016 return $this->subscription_status; … … 1017 1019 // Make API call to master server to check subscription status 1018 1020 $api_url = trailingslashit( $master_url ) . 'wp-json/exaig/v1/verify-subscription?domain=' . urlencode( $domain ); 1021 1022 $this->aistma_log_manager->log( 'info', 'Checking subscription status for domain: ' . $domain . ' at URL: ' . $api_url ); 1019 1023 1020 1024 $response = wp_remote_get( $api_url, array( … … 1022 1026 'headers' => array( 1023 1027 'User-Agent' => 'AI-Story-Maker/1.0', 1028 'X-Caller-Url' => home_url(), 1029 'X-Caller-IP' => isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '', 1024 1030 ), 1025 1031 ) ); … … 1038 1044 $response_code = wp_remote_retrieve_response_code( $response ); 1039 1045 $response_body = wp_remote_retrieve_body( $response ); 1046 1047 $this->aistma_log_manager->log( 'info', 'Subscription API response code: ' . $response_code . ', body: ' . substr( $response_body, 0, 500 ) ); 1048 1040 1049 $data = json_decode( $response_body, true ); 1041 1050 1042 1051 if ( $response_code !== 200 ) { 1043 $this->aistma_log_manager->log( 'error', 'API error checking subscription status. Response code: ' . $response_code );1052 $this->aistma_log_manager->log( 'error', 'API error checking subscription status. Response code: ' . $response_code . ', Body: ' . $response_body ); 1044 1053 $this->subscription_status = array( 1045 1054 'valid' => false, … … 1051 1060 1052 1061 if ( json_last_error() !== JSON_ERROR_NONE ) { 1053 $this->aistma_log_manager->log( 'error', 'Invalid JSON response from subscription API ');1062 $this->aistma_log_manager->log( 'error', 'Invalid JSON response from subscription API. Body: ' . $response_body ); 1054 1063 $this->subscription_status = array( 1055 1064 'valid' => false, … … 1061 1070 // if valid but status is "active_no_credits" then set the status to false and set the message to "No credits remaining" 1062 1071 if ( isset( $data['valid'] ) && $data['valid'] && isset( $data['status'] ) && $data['status'] === 'active_no_credits' ) { 1072 $this->aistma_log_manager->log( 'info', 'Subscription valid but no credits remaining for domain: ' . $domain ); 1063 1073 $this->subscription_status = array( 1064 1074 'valid' => false, … … 1081 1091 ); 1082 1092 } else { 1083 //$this->aistma_log_manager->log( 'info', 'No active subscription found for domain: ' . $domain);1093 $this->aistma_log_manager->log( 'info', 'No active subscription found for domain: ' . $domain . ', message: ' . ( $data['message'] ?? 'No message' ) ); 1084 1094 $this->subscription_status = array( 1085 1095 'valid' => false,
Note: See TracChangeset
for help on using the changeset viewer.