[
'id' => '17',
'purpose' => 'renewal',
'title' => '实例续费',
'created_at' => 2_000_000_000,
'amount' => '12.51',
'status' => 'open',
'renews_expires_at' => 2_000_100_000,
'payment_deadline_at' => 2_000_359_200,
'payable' => true,
'validity_days' => 30,
'traffic_quota_bytes' => 0,
'items' => [
[
'id' => '31',
'code' => 'instance',
'label' => '实例套餐续费',
'amount' => '10.00',
'currency' => 'USD',
],
[
'id' => '32',
'code' => 'automatic_backup',
'label' => '
自动备份',
'amount' => '2.50',
'currency' => 'USD',
],
],
],
'balance_payment_allowed' => false,
'payment_methods' => [],
];
$view = CloudInvoicePresentation::detail($payload);
$assert(($view['show_line_items'] ?? false) === true,
'Invoice first paint does not expose its frozen line items.');
$assert(($view['created_at'] ?? null) === 2_000_000_000
&& ($view['facts'][1]['timestamp'] ?? null) === 2_000_000_000
&& ($view['facts'][2]['timestamp'] ?? null) === 2_000_100_000,
'Invoice presentation did not preserve canonical timestamps for browser-local display.');
$assert(($view['line_items'] ?? null) === [
[
'label' => '实例套餐续费',
'label_key' => 'billing.line_items.renewal_plan',
'amount_display' => '$10.00',
],
[
'label' => '
自动备份',
'label_key' => 'billing.line_items.backup_renewal',
'amount_display' => '$2.50',
],
], 'Invoice line-item projection changed labels or frozen amounts.');
$assert(($view['amount_display'] ?? null) === '$12.51',
'Invoice presentation recomputed the authoritative total from line items.');
$resumePayload = $payload;
$resumePayload['invoice']['payable'] = true;
$resumePayload['balance_payment_allowed'] = true;
$resumePayload['balance'] = '20.00';
$resumePayload['payment_methods'] = [[
'id' => 'stripe_card',
'name' => 'Stripe · 银行卡',
]];
$resumePayload['active_payment'] = [
'status' => 'review',
'task_id' => '91',
'payment' => null,
'can_submit' => true,
];
$resumeView = CloudInvoicePresentation::detail($resumePayload);
$assert(($resumeView['show_payment'] ?? false) === true
&& ($resumeView['payment_title_key'] ?? null)
=== 'billing.payment.select_title'
&& ($resumeView['active_payment_key'] ?? null)
=== 'billing.payment.active.review'
&& count($resumeView['payment_methods'] ?? []) === 2,
'Invoice first paint did not allow switching from an unfinished payment.');
$gracePayload = $payload;
$gracePayload['invoice']['status'] = 'overdue';
$gracePayload['invoice']['display_status'] = 'renewal_grace';
$gracePayload['invoice']['payable'] = true;
$graceView = CloudInvoicePresentation::detail($gracePayload);
$assert(($graceView['status_key'] ?? null)
=== 'billing.status.financial.renewal_grace'
&& ($graceView['status_class'] ?? null) === 'warning',
'Payable renewal grace was presented as a failed overdue invoice.');
$ipChangePayload = [
'invoice' => [
'id' => '81',
'purpose' => 'ip_change',
'title' => '更换公网 IPv4',
'created_at' => 2_000_000_000,
'amount' => '5.00',
'status' => 'paid',
'paid_at' => 2_000_000_000,
'paid_via' => 'balance',
'instance_id' => '41',
'instance_name' => 'vm-audit',
'task_id' => '82',
'job_status' => 'review',
'fulfillment_status' => 'review',
'error' => '操作效果待人工核对,请勿重复提交。',
'items' => [],
],
'balance_payment_allowed' => false,
'payment_methods' => [],
];
$ipChangeView = CloudInvoicePresentation::detail($ipChangePayload);
$ipChangeRow = CloudInvoicePresentation::summaries([
$ipChangePayload['invoice'],
])[0];
$assert(($ipChangeView['show_fulfillment'] ?? false) === true
&& ($ipChangeView['title_key'] ?? null) === 'billing.purpose.ip_change'
&& ($ipChangeView['fulfillment_title_key'] ?? null)
=== 'billing.fulfillment.title.ip_change'
&& ($ipChangeView['fulfillment_key'] ?? null)
=== 'billing.status.fulfillment.review'
&& ($ipChangeView['fulfillment_class'] ?? null) === 'warning'
&& ($ipChangeView['instance_id'] ?? null) === '41'
&& ($ipChangeRow['show_fulfillment'] ?? false) === true
&& ($ipChangeRow['fulfillment_key'] ?? null)
=== 'billing.status.fulfillment.review'
&& ($ipChangeRow['context_segments'][0]['key'] ?? null)
=== 'billing.context.target_instance'
&& ($ipChangeRow['context_segments'][0]['parameters']['name'] ?? null)
=== 'vm-audit',
'IP-change invoice did not preserve its target and review-only task state.');
$detailRuntime = file_get_contents(
dirname(__DIR__) . '/public/cloud/invoice-detail-runtime.js'
);
$listRuntime = file_get_contents(dirname(__DIR__) . '/public/cloud/invoices.js');
$adminRuntime = file_get_contents(
dirname(__DIR__) . '/public/cloud/admin-billing.js'
);
$adminRows = file_get_contents(
dirname(__DIR__) . '/resources/views/venix/admin/billing_rows.tpl'
);
$pageController = file_get_contents(
dirname(__DIR__) . '/app/Controllers/CloudPageController.php'
);
$invoiceService = file_get_contents(
dirname(__DIR__) . '/app/Services/Cloud/CloudInvoiceService.php'
);
$assert(is_string($detailRuntime) && is_string($listRuntime)
&& str_contains($detailRuntime, 'payload.presentation')
&& str_contains($detailRuntime, 'result?.presentation_patch')
&& str_contains($detailRuntime, 'presentation?.status_key')
&& str_contains($detailRuntime, 'presentation?.status_class')
&& str_contains($detailRuntime, 'presentation?.fulfillment_key')
&& str_contains($detailRuntime, 'presentation?.polling_required')
&& str_contains($detailRuntime, 'function renderInvoiceDetail(presentation)')
&& str_contains($detailRuntime, 'i18n.date(date)')
&& !str_contains($detailRuntime,
'function renderInvoiceDetail(invoice, presentation)')
&& !str_contains($detailRuntime, 'function invoiceTitle(')
&& !str_contains($detailRuntime, 'function invoiceStatusInfo(')
&& !str_contains($detailRuntime, 'function paymentLabel(')
&& !str_contains($detailRuntime, 'function provisionStatusInfo(')
&& !str_contains($detailRuntime, 'function upgradeStatusInfo(')
&& !str_contains($detailRuntime, 'function ipChangeStatusInfo(')
&& !str_contains($detailRuntime,
"renewal_grace: ['已到期,宽限期内可续费', 'warning']")
&& str_contains($listRuntime, 'invoice?.status_key')
&& str_contains($listRuntime, 'invoice?.status_class')
&& str_contains($listRuntime, 'invoice?.fulfillment_key')
&& str_contains($listRuntime, 'invoice?.polling_required === true')
&& str_contains($listRuntime, 'invoice?.context_segments')
&& str_contains($listRuntime, 'i18n.date(date)')
&& str_contains($listRuntime, 'payload?.balance_display')
&& !str_contains($listRuntime, 'function formatUsd(')
&& !str_contains($listRuntime, 'function invoiceStatusInfo(')
&& !str_contains($listRuntime, 'function fulfillmentStatusInfo(')
&& !str_contains($listRuntime,
"renewal_grace: ['已到期,宽限期内可续费', 'warning']")
&& !preg_match('/[\\x{4e00}-\\x{9fff}]/u', $detailRuntime)
&& !preg_match('/[\\x{4e00}-\\x{9fff}]/u', $listRuntime)
&& !str_contains($detailRuntime, 'payload?.detail')
&& !str_contains($detailRuntime, 'task.error'),
'Invoice list client must consume the server presentation without rebuilding it.');
$assert(is_string($adminRuntime) && is_string($adminRows)
&& is_string($pageController) && is_string($invoiceService)
&& !preg_match('/function\s+(?:formatUsd|formatDate|purposeLabel|providerLabel|statusInfo)\s*\(/',
$adminRuntime)
&& !str_contains($adminRows, "['open'=>'待支付'")
&& !str_contains($adminRows, "'paytaro'=>'Paytaro'")
&& !str_contains($pageController, 'private function invoiceListRow(')
&& !str_contains($pageController, 'private function invoiceDetailView(')
&& !str_contains($pageController, 'private function invoiceStatus(')
&& !str_contains($pageController, 'private function invoiceFulfillmentStatus(')
&& !str_contains($pageController, 'private function formatUsd(')
&& substr_count($invoiceService,
'CloudBillingPresentationCatalog::knownPurposeLabel(') === 2,
'Billing presentation drifted back into a browser, template, controller, or read model.');
echo "Cloud invoice SSR presentation checks passed.\n";