You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudInvoiceDetailContractT...

450 lines
27 KiB
PHP

<?php
// Static public-contract checks: keep invoice identifiers tenant-scoped and
// prevent the internal invoice number from leaking into browser responses.
$root = dirname(__DIR__);
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$section = static function (string $source, string $start, string $end): string {
$offset = strpos($source, $start);
if ($offset === false) {
return '';
}
$limit = strpos($source, $end, $offset + strlen($start));
return $limit === false ? substr($source, $offset)
: substr($source, $offset, $limit - $offset);
};
$pageRoutes = file_get_contents($root . '/config/routes.php');
$apiRoutes = file_get_contents($root . '/config/routes_cloud.php');
$pageController = file_get_contents($root . '/app/Controllers/CloudPageController.php');
$apiController = file_get_contents($root . '/app/Controllers/CloudApiController.php');
$apiMiddleware = file_get_contents($root . '/app/Middleware/CloudApi.php');
$invoiceService = file_get_contents($root . '/app/Services/Cloud/CloudInvoiceService.php');
$invoicePageService = file_get_contents($root . '/app/Services/Cloud/CloudInvoicePageService.php');
$invoiceDetailPageService = file_get_contents(
$root . '/app/Services/Cloud/CloudInvoiceDetailPageService.php'
);
$invoiceDetailTemplate = file_get_contents(
$root . '/resources/views/venix/cloud/pages/invoice-detail.tpl'
);
$cloudShell = file_get_contents($root . '/resources/views/venix/cloud/page.tpl');
$invoiceDetailModule = file_get_contents($root . '/public/cloud/invoice-detail.js');
$invoiceDetailRuntime = file_get_contents(
$root . '/public/cloud/invoice-detail-runtime.js'
);
$legacyRuntime = file_get_contents($root . '/public/cloud/runtime.js');
$jobService = file_get_contents($root . '/app/Services/Cloud/CloudJobService.php');
$invoiceModel = file_get_contents($root . '/app/Models/CloudInvoice.php');
$invoiceEmail = file_get_contents($root . '/resources/email/cloud/invoice.tpl');
$assert(str_contains($pageRoutes,
"'/cloud/invoices/{id:[0-9]+}', 'App\\Controllers\\CloudPageController:invoiceDetail'"),
'The authenticated invoice-detail page route is missing.');
$assert(str_contains($apiRoutes,
"'/invoices/{id:[0-9]+}', 'App\\Controllers\\CloudApiController:invoice'"),
'The numeric invoice-detail API route is missing.');
$assert(str_contains($apiRoutes, "'/invoices/{id:[0-9]+}/status'")
&& str_contains($apiRoutes, 'CloudApiController:invoiceStatus'),
'The lightweight invoice-status route is missing.');
$pageMethod = $section($pageController, 'public function invoiceDetail(',
'public function reinstall(');
$assert(str_contains($pageMethod, 'CloudAccess::actor(false)')
&& str_contains($pageMethod, "getAttribute('auth_user')")
&& str_contains($pageMethod, 'CloudInvoiceDetailPageService::forUser(')
&& str_contains($pageMethod, "'cloud_invoice_detail_view'")
&& str_contains($pageMethod, "'cloud_invoice_detail_bootstrap_json'")
&& str_contains($pageMethod, '$this->safeJson($payload)')
&& str_contains($pageMethod, "'invoice-detail'")
&& str_contains($pageMethod, "'/user/cloud/invoices'")
&& str_contains($pageController, "assign('cloud_invoice_id', \$invoiceId)"),
'The detail page must render an owner-scoped payload and safe bootstrap on first paint.');
$assert(str_contains($invoiceDetailPageService,
"CloudInvoice::where('id', \$invoiceId)")
&& str_contains($invoiceDetailPageService,
"->where('user_id', \$userId)")
&& str_contains($invoiceDetailPageService,
'(int) $user->id !== $userId')
&& str_contains($invoiceDetailPageService,
'CloudInvoiceService::display($invoice)')
&& str_contains($invoiceDetailPageService,
"CloudInvoicePaymentService::methods(\$user)")
&& str_contains($invoiceDetailPageService,
"'balance_payment_allowed' =>")
&& str_contains($invoiceDetailPageService,
"'balance' => (string) \$user->money"),
'The shared invoice-detail service is not strictly owner scoped or complete.');
$assert(str_contains($pageController, 'JSON_HEX_TAG')
&& str_contains($pageController, 'JSON_HEX_AMP')
&& str_contains($pageController, 'JSON_HEX_APOS')
&& str_contains($pageController, 'JSON_HEX_QUOT')
&& str_contains($pageController,
"withHeader('Cache-Control', 'private, no-store')"),
'Invoice-detail HTML must embed escaped JSON and prohibit shared caching.');
$assert(str_contains($invoiceDetailTemplate, 'id="invoice-detail-bootstrap"')
&& str_contains($invoiceDetailTemplate, '$cloud_invoice_detail_bootstrap_json nofilter')
&& str_contains($invoiceDetailTemplate, '$cloud_invoice_detail_view.amount_display')
&& str_contains($invoiceDetailTemplate, '$cloud_invoice_detail_view.status_label')
&& str_contains($invoiceDetailTemplate, '{foreach $cloud_invoice_detail_view.facts as $fact}')
&& str_contains($invoiceDetailTemplate,
'{foreach $cloud_invoice_detail_view.specification as $fact}')
&& !str_contains($invoiceDetailTemplate, '正在读取账单信息')
&& !str_contains($invoiceDetailTemplate, '>读取中<'),
'Invoice-detail HTML must contain meaningful first-paint content, not a client-only shell.');
$listMethod = $section($apiController, 'public function invoices(',
'private function createProvisionInvoice(');
$assert(str_contains($listMethod, '$perPage = 10;')
&& str_contains($listMethod, "\$query['page'] ?? '1'")
&& str_contains($listMethod, 'CloudInvoicePageService::forUser(')
&& str_contains($listMethod, "\$payload['balance']"),
'The invoice list is not using its fixed ten-row server-side pagination contract.');
$assert(!str_contains($listMethod, 'CloudInvoiceService::display(')
&& !str_contains($listMethod, 'CloudInvoicePaymentService::methods(')
&& !str_contains($listMethod, "'payment_methods' =>"),
'The list still expands full invoice details or exposes detail-only payment methods.');
$assert(str_contains($invoicePageService, "CloudInvoice::where('user_id', \$userId)")
&& str_contains($invoicePageService, 'CloudInvoiceService::listSummaries($records)')
&& str_contains($invoicePageService, "'total_pages' => \$totalPages"),
'The shared invoice pagination service is not owner scoped or complete.');
$summaryMethod = $section($invoiceService, 'public static function listSummaries(',
'private static function listKey(');
$assert(substr_count($summaryMethod, '::whereIn(') === 3
&& str_contains($summaryMethod, "->get(['id', 'user_id', 'status'])")
&& str_contains($summaryMethod,
"->get(['id', 'order_id', 'user_id', 'phase', 'outcome'])")
&& str_contains($summaryMethod,
'self::publicStatus($invoice, $purpose, $instance, $now)'),
'Invoice list associations are not loaded with fixed-size batch queries.');
foreach (['id', 'title', 'type_label', 'purpose', 'amount', 'status', 'created_at',
'order_status', 'fulfillment_status', 'job_status'] as $field) {
$assert(str_contains($summaryMethod, "'{$field}' =>"),
'Invoice list summary is missing field: ' . $field);
}
foreach (['payment_methods', 'payment_reference', 'paid_via', 'specification',
'traffic_quota_bytes', 'payment_deadline_at'] as $detailOnlyField) {
$assert(!str_contains($summaryMethod, "'{$detailOnlyField}' =>"),
'Invoice list summary leaked detail-only field: ' . $detailOnlyField);
}
$apiMethod = $section($apiController, 'public function invoice(',
'public function invoiceStatus(');
$assert(str_contains($apiMethod, 'CloudInvoiceDetailPageService::forUser(')
&& str_contains($apiMethod, "(int) \$actor['user_id']")
&& str_contains($apiMethod, '(bool) $actor[\'is_admin\']'),
'The invoice-detail API must use the same owner-scoped payload as HTML.');
$assert(preg_match('/if\s*\([^)]*\$actor\[[\'\"]is_admin[\'\"]\]/', $apiMethod) !== 1,
'Administrator scope must not bypass invoice ownership in the user detail API.');
$statusApiMethod = $section($apiController, 'public function invoiceStatus(',
'public function payInvoice(');
$assert(str_contains($statusApiMethod, 'CloudInvoiceDetailPageService::statusForUser(')
&& str_contains($statusApiMethod, "(int) \$actor['user_id']")
&& !str_contains($statusApiMethod, 'CloudInvoicePaymentService::methods('),
'Invoice polling must use an owner-scoped lightweight response.');
$assert(!str_contains($invoiceDetailRuntime, '/api/v1/jobs/')
&& substr_count($invoiceDetailRuntime,
'/api/v1/invoices/${encodeURIComponent(invoice.id)}/status') === 1
&& str_contains($invoiceDetailRuntime, "actionButton('刷新账单状态'")
&& str_contains($invoiceDetailRuntime,
'const nextInvoice = mergeInvoiceStatus(state.selectedInvoice, update);'),
'Manual creation-progress refresh must use one invoice-scoped lightweight request.');
$manualProgress = $section($invoiceDetailRuntime,
'function appendProvisionInvoiceActions(', ' if (data.instanceId) {');
$manualProgressCatch = $section($manualProgress,
'} catch (error) {', ' }');
$assert(str_contains($manualProgress, 'const readSequence = ++state.readSequence;')
&& str_contains($manualProgress, 'try {')
&& strpos($manualProgress, 'const readSequence = ++state.readSequence;')
< strpos($manualProgress, 'try {')
&& str_contains($manualProgressCatch,
'if (readSequence < state.appliedReadSequence) return;')
&& !str_contains($manualProgressCatch, 'state.invoiceJobProgress.set('),
'Manual creation-progress errors must ignore stale reads and remain transient.');
$assert(substr_count($invoiceDetailPageService, '->sharedLock()') === 2
&& str_contains($invoiceDetailPageService, 'public static function statusForUser(')
&& str_contains($invoiceDetailPageService,
'return CloudInvoiceService::status($invoice);'),
'Full and lightweight invoice reads must use a consistent owner-scoped snapshot.');
$statusService = $section($invoiceService, 'public static function status(',
'public static function display(');
$assert(str_contains($statusService, "'fulfillment' =>")
&& str_contains($statusService, "'job_status' =>")
&& !str_contains($statusService, 'CloudInvoicePaymentService')
&& !str_contains($statusService, 'spec_json'),
'The invoice status service performs detail-only work.');
$assert(str_contains($apiMiddleware, 'CloudAccess::actor(!$databaseOnly)')
&& str_contains($apiMiddleware, "#^/api/v1/invoices(?:/|$)#D"),
'Invoice-only API calls must authenticate without a cloud_sessions lookup.');
$pollMethod = $section($invoiceDetailRuntime, 'async function pollInvoiceStatus(',
'function scheduleInvoicePoll(');
$assert(str_contains($pollMethod,
'api(`/api/v1/invoices/${encodeURIComponent(state.pollInvoiceId)}/status`')
&& substr_count($pollMethod, 'api(') === 1
&& str_contains($pollMethod, 'entersProvisioningAfterPayment(')
&& str_contains($pollMethod, 'resetProvisioningPollWindow();')
&& !str_contains($pollMethod, 'refreshInvoiceDetail('),
'Each invoice poll must issue one lightweight request and preserve the provisioning window.');
$needsPolling = $section($invoiceDetailRuntime, 'function invoiceNeedsPolling(',
'function stopInvoicePoll(');
$provisionFinished = $section($invoiceDetailRuntime, 'function provisionFinished(',
'function invoiceFact(');
$assert(str_contains($needsPolling, 'state.onlinePaymentPending')
&& str_contains($needsPolling, '!onlinePaymentHasExpired()')
&& str_contains($needsPolling, 'invoiceCanPay(invoice)')
&& str_contains($needsPolling, 'return false;')
&& !str_contains($needsPolling, 'provisionFinished(invoice)')
&& str_contains($provisionFinished,
"['succeeded', 'failed', 'expired', 'refunded', 'cancelled'].includes(status)")
&& !str_contains($provisionFinished, "'active'")
&& !str_contains($provisionFinished, "'uncertain'")
&& !str_contains($provisionFinished, "'needs_attention'"),
'Invoice polling must be bounded to active provider payment while task receipts expose provisioning outcome.');
$paymentExpiry = $section($invoiceDetailRuntime,
'function onlinePaymentFallbackExpiresAt(', 'function invoiceNeedsPolling(');
$onlinePaymentRender = $section($invoiceDetailRuntime,
'function renderOnlinePayment(', 'async function payInvoiceBalance(');
$detailHydration = $section($invoiceDetailRuntime,
'function hydrateInvoiceDetail(', 'async function refreshInvoiceDetail(');
$assert(str_contains($invoiceDetailRuntime, 'function hasPendingInvoicePaymentKey(')
&& str_contains($invoiceDetailRuntime, 'hasPendingInvoicePaymentKey(payload.invoice.id)')
&& str_contains($invoiceDetailRuntime, 'resumeInvoicePolling();')
&& str_contains($paymentExpiry, 'STATUS_POLL_MAX_LIFETIME_MS')
&& str_contains($paymentExpiry, 'invoicePaymentDeadlineTimestamp(invoice)')
&& str_contains($paymentExpiry, 'function onlinePaymentHasExpired(')
&& str_contains($paymentExpiry, 'function expireOnlinePaymentInstructions(')
&& str_contains($paymentExpiry, 'clearOnlinePaymentState(true);')
&& str_contains($paymentExpiry, "makeElement('strong', '', '支付订单已过期')")
&& str_contains($paymentExpiry, 'void refreshInvoiceDetail(invoiceId);')
&& str_contains($onlinePaymentRender, 'paymentExpiresAt === null')
&& str_contains($onlinePaymentRender,
'onlinePaymentFallbackExpiresAt(state.selectedInvoice)')
&& str_contains($onlinePaymentRender, 'scheduleOnlinePaymentExpiry(generation);')
&& str_contains($detailHydration,
'if (onlinePaymentHasExpired()) expireOnlinePaymentInstructions();')
&& str_contains($detailHydration, 'state.onlinePaymentExpiresAt <= 0')
&& !str_contains($detailHydration, 'state.onlinePaymentExpiresAt <= Date.now()')
&& str_contains($invoiceDetailRuntime, 'STATUS_POLL_SLOW_INTERVAL_MS')
&& str_contains($invoiceDetailRuntime, 'Date.now() < state.pollUntil'),
'Provider payments must recover through a bounded fallback expiry and disable stale instructions.');
$assert(str_contains($invoiceDetailRuntime,
'function entersProvisioningAfterPayment(')
&& substr_count($invoiceDetailRuntime,
'entersProvisioningAfterPayment(') === 3
&& substr_count($invoiceDetailRuntime,
'resetProvisioningPollWindow();') === 3
&& str_contains($invoiceDetailRuntime,
'state.pollUntil = Math.max(state.pollUntil, state.onlinePaymentExpiresAt);'),
'Provider and balance payment completion must preserve the correct provisioning poll window.');
$assert(!str_contains($invoiceDetailModule, '/cloud/runtime.js')
&& str_contains($invoiceDetailModule, '/cloud/invoice-detail-runtime.js')
&& str_contains($invoiceDetailModule, 'readInvoiceDetailBootstrap()')
&& str_contains($invoiceDetailModule, 'hydrateInvoiceDetail(bootstrap, invoiceId)')
&& str_contains($invoiceDetailModule,
'if (event.persisted) void refreshInvoiceDetail(invoiceId)')
&& !str_contains($invoiceDetailModule, '/api/v1/invoices/')
&& !str_contains($invoiceDetailModule, 'initializeSession')
&& !str_contains($invoiceDetailModule, 'setInterval(')
&& str_contains($invoiceDetailModule, "state.view = 'invoice-detail'"),
'Invoice detail must hydrate its SSR payload without the full runtime or an initial detail GET.');
$assert(str_contains($invoiceDetailRuntime, 'readSequence: 0')
&& str_contains($invoiceDetailRuntime, 'appliedReadSequence: 0')
&& substr_count($invoiceDetailRuntime,
'const readSequence = ++state.readSequence;') >= 2
&& str_contains($invoiceDetailRuntime,
'if (readSequence < state.appliedReadSequence) return state.selectedInvoice;')
&& str_contains($invoiceDetailRuntime,
'readSequence >= state.appliedReadSequence'),
'Invoice detail must prevent an older concurrent response from replacing newer state.');
$schedulePoll = $section($invoiceDetailRuntime, 'function scheduleInvoicePoll(',
'function resumeInvoicePolling(');
$refreshDetail = $section($invoiceDetailRuntime, 'async function refreshInvoiceDetail(',
'let cleanupBound = false;');
$assert(str_contains($schedulePoll, 'state.refreshPromise')
&& str_contains($refreshDetail, 'stopInvoicePoll();')
&& str_contains($refreshDetail, 'if (!controller.signal.aborted) resumeInvoicePolling();')
&& strpos($refreshDetail, 'stopInvoicePoll();')
< strpos($refreshDetail, 'const readSequence = ++state.readSequence;'),
'A full detail refresh must pause sparse status polling and resume it afterwards.');
$balancePayment = $section($invoiceDetailRuntime, 'async function payInvoiceBalance(',
'async function createInvoicePayment(');
$balanceBusyGuard = strpos($balancePayment, 'if (state.mutationBusy) return;');
$balanceBusySet = strpos($balancePayment, 'state.mutationBusy = true;');
$balanceButtonsDisabled = strpos($balancePayment,
"container.querySelectorAll('button').forEach(button => { button.disabled = true; });");
$balanceRequest = strpos($balancePayment,
'api(`/api/v1/invoices/${encodeURIComponent(invoice.id)}/pay-balance`');
$assert(str_contains($balancePayment,
'state.appliedReadSequence = ++state.readSequence;')
&& strpos($balancePayment,
'state.appliedReadSequence = ++state.readSequence;')
< strpos($balancePayment, 'renderInvoiceDetail(paid,'),
'A successful balance payment must invalidate every older in-flight read.');
$assert(str_contains($balancePayment,
"const startsProvisioning = invoicePurpose(paid) === 'provision';")
&& str_contains($balancePayment,
'if (startsProvisioning) resetProvisioningPollWindow();')
&& strpos($balancePayment, 'resetProvisioningPollWindow();')
< strpos($balancePayment, 'renderInvoiceDetail(paid,'),
'Balance payment must start a fresh provisioning poll window before rendering paid state.');
$assert(str_contains($balancePayment,
'if ([403, 409].includes(Number(error.status || 0)))')
&& str_contains($balancePayment, 'await refreshInvoiceDetail(invoice.id);'),
'A deterministic balance-payment rejection must refresh server payable state.');
$assert(!str_contains($balancePayment, 'confirm(')
&& $balanceBusyGuard !== false
&& $balanceBusySet !== false
&& $balanceButtonsDisabled !== false
&& $balanceRequest !== false
&& $balanceBusyGuard < $balanceBusySet
&& $balanceBusySet < $balanceButtonsDisabled
&& $balanceButtonsDisabled < $balanceRequest
&& str_contains($balancePayment, 'state.mutationBusy = false;'),
'Balance payment must execute immediately while retaining duplicate-submit protection and recovery.');
$providerPayment = $section($invoiceDetailRuntime,
'async function createInvoicePayment(', 'function renderInvoicePaymentMethods(');
$providerBusyGuard = strpos($providerPayment, 'if (state.mutationBusy) return;');
$providerBusySet = strpos($providerPayment, 'state.mutationBusy = true;');
$providerButtonsDisabled = strpos($providerPayment,
"container.querySelectorAll('button').forEach(button => { button.disabled = true; });");
$providerIdempotency = strpos($providerPayment,
'pendingInvoicePaymentKey(invoice.id, method.id)');
$providerRequest = strpos($providerPayment,
'api(`/api/v1/invoices/${encodeURIComponent(invoice.id)}/payments`');
$assert(str_contains($providerPayment,
"const creationStillInProgress = String(error.message).includes('正在创建');")
&& str_contains($providerPayment,
'if ([403, 409].includes(status) && !creationStillInProgress)')
&& str_contains($providerPayment, 'await refreshInvoiceDetail(invoice.id);'),
'A deterministic provider-payment rejection must refresh server payable state.');
$assert(!str_contains($providerPayment, 'confirm(')
&& $providerBusyGuard !== false
&& $providerBusySet !== false
&& $providerButtonsDisabled !== false
&& $providerIdempotency !== false
&& $providerRequest !== false
&& $providerBusyGuard < $providerBusySet
&& $providerBusySet < $providerButtonsDisabled
&& $providerButtonsDisabled < $providerIdempotency
&& $providerIdempotency < $providerRequest
&& str_contains($providerPayment, 'state.mutationBusy = false;'),
'Provider payment must execute immediately while retaining idempotency and duplicate-submit protection.');
$paymentChoices = $section($invoiceDetailRuntime,
'function renderInvoicePaymentMethods(', 'function invoiceProgressText(');
$assert(str_contains($invoiceDetailRuntime, 'balancePaymentAllowed: false')
&& str_contains($invoiceDetailRuntime,
'state.balancePaymentAllowed = payload?.balance_payment_allowed === true')
&& str_contains($paymentChoices, 'if (state.balancePaymentAllowed)')
&& str_contains($paymentChoices, 'if (!choices.length)')
&& str_contains($paymentChoices,
'state.selectedInvoicePaymentMethod = String(choices[0].id);'),
'Restricted accounts must not be offered a balance-payment control.');
$assert(!str_contains($invoiceDetailRuntime, "from '/cloud/runtime.js'")
&& !str_contains($invoiceDetailRuntime, 'from "/cloud/runtime.js"')
&& !str_contains($invoiceDetailRuntime, "import('/cloud/runtime.js')")
&& !str_contains($invoiceDetailRuntime, 'import("/cloud/runtime.js")'),
'The dedicated invoice runtime must not import the all-feature VM runtime.');
$assert(!str_contains($legacyRuntime, 'function loadInvoiceDetail(')
&& !str_contains($legacyRuntime, 'function renderInvoiceDetail(')
&& !str_contains($legacyRuntime, 'INVOICE_PAYMENT_STORAGE_PREFIX'),
'The all-feature VM runtime must not retain a second invoice-detail implementation.');
$assert(!str_contains($cloudShell, '/theme/venix/js/qrcode.min.js')
&& str_contains($invoiceDetailRuntime, "document.createElement('script')")
&& str_contains($invoiceDetailRuntime, '/theme/venix/js/qrcode.min.js')
&& str_contains($invoiceDetailRuntime, 'async function appendPaymentQr(')
&& str_contains($invoiceDetailRuntime, 'paymentRenderGeneration: 0')
&& str_contains($invoiceDetailRuntime,
'generation !== state.paymentRenderGeneration')
&& str_contains($invoiceDetailRuntime,
"'cloud-payment-qr cloud-payment-qr-loading'")
&& str_contains($invoiceDetailRuntime, 'container.append(qr);')
&& str_contains($invoiceDetailRuntime,
'void appendPaymentQr(box, qrValue, generation)'),
'The QR library must be loaded only after an online payment order is created.');
$cleanup = $section($invoiceDetailRuntime, 'function bindInvoiceDetailCleanup(',
'export {');
$assert(!str_contains($cleanup, 'toastTimer')
&& str_contains($cleanup, "const element = byId('toast');")
&& str_contains($cleanup, 'if (element) element.hidden = true;'),
'BFCache cleanup must hide the shared toast region without retaining obsolete local timer state.');
$assert(str_contains($invoiceDetailTemplate,
'选择支付方式后,点击“立即支付”将直接发起支付,请勿重复点击。')
&& str_contains($invoiceDetailTemplate, '>立即支付</button>')
&& !str_contains($invoiceDetailTemplate, '再确认支付本账单')
&& !str_contains($invoiceDetailTemplate, '>确认支付</button>'),
'Invoice payment copy must describe immediate execution without stale confirmation text.');
$createPayment = $section($invoiceDetailRuntime, 'async function createInvoicePayment(',
'function renderInvoicePaymentMethods(');
$paymentRequest = strpos($createPayment,
'api(`/api/v1/invoices/${encodeURIComponent(invoice.id)}/payments`');
$paymentObserve = strpos($createPayment, 'observeTask(result, {');
$paymentTerminal = strpos($createPayment,
"if (task.status === 'succeeded' && task?.result?.payment)");
$paymentRender = strpos($createPayment,
'renderOnlinePayment(paymentResult, task.result.payment)');
$assert($paymentRequest !== false && $paymentObserve !== false
&& $paymentTerminal !== false && $paymentRender !== false
&& $paymentRequest < $paymentObserve
&& $paymentObserve < $paymentTerminal
&& $paymentTerminal < $paymentRender,
'QR/payment instructions were rendered before the terminal successful task receipt.');
$displayMethod = $section($invoiceService, 'public static function display(',
'public static function payBalance(');
$assert(str_contains($invoiceService, 'private static function publicState(')
&& str_contains($invoiceService, 'private static function publicStatus(')
&& substr_count($invoiceService,
'self::publicStatus($invoice, $purpose, $instance, $now)') === 2
&& substr_count($invoiceService,
'self::publicState($invoice, $purpose, $order, $instance, $now)') === 2,
'Invoice list, full detail and lightweight status must share one public-state rule.');
$assert(str_contains($statusService,
"->where('user_id', \$invoice->user_id)")
&& str_contains($statusService, '$instanceId = $linkedInstance?->id;'),
'Polling must validate the linked instance owner before exposing its id.');
$assert(str_contains($displayMethod, "'recharge' => '余额充值'")
&& str_contains($displayMethod, "'provision' => '实例开通'")
&& str_contains($displayMethod, "'renewal' => '实例续费'")
&& str_contains($displayMethod, "'title' => \$title")
&& str_contains($displayMethod, "'type_label' => \$title"),
'Invoice purpose labels are incomplete.');
$assert(!str_contains($displayMethod, "'invoice_no' =>"),
'The internal invoice number is still exposed to users.');
$assert(!str_contains($displayMethod, "'payment_reference' =>")
&& !str_contains($invoiceDetailPageService, "'invoice_no' =>")
&& !str_contains($invoiceDetailPageService, "'payment_reference' =>")
&& !str_contains($invoiceDetailTemplate, 'invoice_no')
&& !str_contains($invoiceDetailTemplate, 'payment_reference'),
'Invoice-detail HTML/bootstrap sources expose internal payment identifiers.');
$assert(substr_count($displayMethod, "->where('user_id', \$invoice->user_id)") >= 3,
'Invoice associations are not constrained to the invoice owner.');
$assert(str_contains($invoiceModel, "protected \$hidden = ['invoice_no', 'payment_reference']"),
'Sensitive invoice internals are not protected from accidental model serialization.');
foreach (['created_at', 'amount', 'status', 'plan_name', 'cpu_cores', 'memory_mib',
'disk_gib', 'bandwidth_mbps', 'validity_days', 'traffic_quota_bytes',
'order_id', 'task_id', 'fulfillment'] as $field) {
$assert(str_contains($displayMethod, "'{$field}' =>"),
'Invoice detail is missing field: ' . $field);
}
$jobDisplay = $section($jobService, 'public static function display(',
'public static function tasks(');
$assert(str_contains($jobDisplay, "'updated_at' =>")
&& str_contains($jobDisplay, "'completed' => \$completed")
&& str_contains($jobDisplay, "'status_url' => '/api/v1/tasks/'")
&& !str_contains($jobDisplay, "'attempts' =>")
&& str_contains($jobDisplay, ': self::displayResult(')
&& str_contains($jobService, 'return CloudOperationErrorCatalog::result('),
'Provisioning progress lacks a bounded terminal receipt or leaks retry counters.');
$assert(str_contains($invoiceEmail, '#{$invoice_id|escape:"html"}')
&& str_contains($invoiceEmail, '&#36;{$amount|escape:"html"}')
&& !str_contains($invoiceEmail, 'invoice_no')
&& str_contains($invoiceService,
"'invoice_url' => \$base . '/user/cloud/invoices/' . (int) \$invoice->id"),
'Renewal email must use the public numeric id, USD and its detail-page link.');
echo "Cloud invoice detail routing, ownership and public fields passed.\n";