false,'message'=>'POST required.']);exit; } try { include_once './Home_include.php'; require_once __DIR__.'/PA_SHOP_RECOVERY_REQUEST.php'; require_once __DIR__.'/PA_SHOP_RENEWAL_RECONCILIATION_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.'); } $shop=$PASYSCONF['SHOP']??[]; $gate=$shop['RENEWAL_RECONCILIATION']??[]; $restorationGate=$shop['RENEWAL_RESTORATION']??[]; if (($gate['Enabled']??false)!==true || ($gate['Policy']??'')!=='carrier_confirmed_backend_v1' || !is_array($gate['AllowedAdminIDs']??null) || !is_array($gate['AllowedClientIDs']??null) || !in_array($admin,$gate['AllowedAdminIDs'],true) || ($shop['ACTIVATION']['Enabled']??false)!==true || ($shop['RENEWAL']['Enabled']??false)!==true || ($restorationGate['Enabled']??false)!==true || ($restorationGate['Policy']??'')!=='verified_replacement_restoration_v1') { throw new RuntimeException('Backend reconciliation is disabled.'); } $order=$_POST['replacement_order_id']??null; $action=$_POST['action']??null; if (!is_string($order)||!preg_match('/^[1-9][0-9]{0,17}$/D',$order) || !in_array($action,['prepare','apply'],true)) { throw new RuntimeException('Invalid reconciliation request.'); } $command=null; if ($action==='apply') { $command=PAShopRenewalReconciliationRequest::consume($_SESSION,$admin,$_POST); if (!session_write_close()) throw new RuntimeException('Confirmation could not be saved.'); } $db=$PAAPP_CONFIG_DB_LINK; $hostTimezone=date_default_timezone_get(); foreach (['WP_USE_THEMES'=>false,'WP_ADMIN'=>true,'DOING_AJAX'=>true, 'DISABLE_WP_CRON'=>true,'WP_MEMORY_LIMIT'=>'256M'] as $key=>$value) { if (!defined($key)) define($key,$value); } if (!function_exists('wcs_get_subscription')) { (function($hostTimezone) { ob_start(); try {require_once '/opt/SA/DEV/WEB/SHOP/wp-load.php';} finally {ob_end_clean();date_default_timezone_set($hostTimezone);} })($hostTimezone); } if (!function_exists('wcs_get_subscription')) throw new RuntimeException('Subscriptions unavailable.'); $timezone=wp_timezone(); require_once '/opt/SA/DEV/WEB/SHOP/wp-content/plugins/pa-device-transaction/PA_SHOP_RENEWAL_RECONCILIATION.php'; $carrier=null; if ($action==='apply') { require_once '/opt/SA/DEV/WEB/SHOP/wp-content/plugins/pa-device-transaction/PA_SHOP_CARRIER.php'; $carrierConfig=$PASYSCONF['CARRIER']['ONCE']??[]; $carrier=new PAShopCarrier($carrierConfig['URLAUTH']??'',$carrierConfig['APIKEY']??''); } $worker=new PAShopRenewalReconciliation($db,$timezone,$gate,$restorationGate,$carrier); if ($action==='prepare') { $result=PAShopRenewalReconciliationRequest::issue($_SESSION,$admin,(int)$order, $worker->inspect($admin,(int)$order)); } else { $result=$worker->reconcile($command['admin'],$command['order'], $command['fingerprint'],$command['request'],$command['reason']); } echo json_encode(['status'=>true,'data'=>$result]); } catch (Throwable $error) { echo json_encode(['status'=>false,'message'=>'Backend reconciliation was not confirmed. Review the carrier, payment and tracker audits before another action.']); }