false,'message'=>'POST required.']);exit;} try{ include_once './Home_include.php'; require_once __DIR__.'/PA_SHOP_RECOVERY_REQUEST.php'; $admin=PAShopRecoveryRequest::admin($PAAPP_CONFIG_DB_LINK,$_COOKIE['PHPSESSID']??null,$_POST['DUMMYSESSID']??null,$_SERVER['REMOTE_ADDR']??null); if(session_status()!==PHP_SESSION_ACTIVE || session_id()!==($_COOKIE['PHPSESSID']??null))throw new RuntimeException('Session confirmation unavailable.'); $root='/opt/SA/DEV/WEB/SHOP/wp-content/plugins/pa-device-transaction/'; require_once $root.'PA_SHOP_ACTIVATION_RECOVERY.php'; $gate=PAShopActivationRecovery::effectiveGate($PASYSCONF['SHOP']??[]); $id=$_POST['transaction_id']??''; if(!is_string($id)||!preg_match('/^[1-9][0-9]{0,17}$/D',$id))throw new RuntimeException('Invalid transaction reference.'); // Preflight uses no WordPress bootstrap and no external adapters. $preflight=new PAShopActivationRecovery($PAAPP_CONFIG_DB_LINK,function(){return false;},function(){return false;},$gate); $row=$preflight->inspect($admin,(int)$id); if(($_POST['action']??'')==='prepare'){ $data=PAShopRecoveryRequest::issue($_SESSION,$admin,$row); echo json_encode(['status'=>true,'data'=>$data]);exit; } if(($_POST['action']??'')!=='recover')throw new RuntimeException('Unknown recovery action.'); $command=PAShopRecoveryRequest::consume($_SESSION,$admin,$_POST); if(!session_write_close())throw new RuntimeException('Confirmation could not be saved.'); $recoveryDB=$PAAPP_CONFIG_DB_LINK; $timezone=new DateTimeZone(date_default_timezone_get()); foreach(['WP_USE_THEMES'=>false,'WP_ADMIN'=>true,'DOING_AJAX'=>true,'DISABLE_WP_CRON'=>true,'WP_MEMORY_LIMIT'=>'256M'] as $k=>$v)if(!defined($k))define($k,$v); if(!function_exists('wcs_get_subscription'))(function($timezone){ ob_start();try{require_once '/opt/SA/DEV/WEB/SHOP/wp-load.php';}finally{ob_end_clean();date_default_timezone_set($timezone->getName());} })($timezone); if(!function_exists('wcs_get_subscription'))throw new RuntimeException('Subscriptions unavailable.'); require_once $root.'PA_SHOP_RECOVERY_ADAPTER.php'; $load=function($id){$sub=wcs_get_subscription($id);if($sub)$sub->get_data_store()->read($sub);return $sub;}; $adapter=new PAShopRecoveryAdapter($recoveryDB,$load,$timezone); $recovery=new PAShopActivationRecovery($recoveryDB,[$adapter,'validate'],[$adapter,'release'],$gate); $result=$recovery->recover($command['admin'],$command['id'],$command['revision'],$command['request'],$command['reason']); echo json_encode(['status'=>true,'data'=>$result]); }catch(Throwable $e){ // Do not expose SQL, credentials or vendor exception details. echo json_encode(['status'=>false,'message'=>'Recovery was not confirmed. Refresh and review the activation. Recovery may be disabled, permission denied, or the confirmation expired. Do not create another purchase.']); }