'17',
'purpose' => 'renewal',
'title' => '实例续费',
'currency' => 'USD',
'created_at' => 2_000_000_000,
'amount' => '12.51',
'status' => 'overdue',
'display_status' => 'renewal_grace',
'renews_expires_at' => 2_000_100_000,
'payment_deadline_at' => 2_000_359_200,
'deletion_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',
],
],
];
$rows = CloudInvoicePresentation::summaries([$renewal]);
$assert(count($rows) === 1
&& $rows[0]['status_label'] === '已到期,宽限期内可续费'
&& $rows[0]['status_class'] === 'warning'
&& $rows[0]['amount_display'] === '$12.51'
&& $rows[0]['polling_required'] === true
&& str_contains($rows[0]['context_display'], '最晚支付'),
'Renewal grace summary did not preserve its canonical status and deadline.');
$wrongLegacyTitle = $renewal;
$wrongLegacyTitle['title'] = '旧调用方错误标题';
$assert(CloudInvoicePresentation::summaries([$wrongLegacyTitle])[0]['title']
=== '实例续费',
'Known invoice title was still controlled by a legacy caller mapping.');
$detail = CloudInvoicePresentation::detail([
'invoice' => $renewal,
'balance_payment_allowed' => false,
'payment_methods' => [],
]);
$assert($detail['show_line_items'] === true
&& $detail['line_items'] === [
['label' => '实例套餐续费', 'amount_display' => '$10.00'],
[
'label' => '
自动备份',
'amount_display' => '$2.50',
],
]
&& $detail['amount_display'] === '$12.51',
'Detail projection changed frozen line-item labels or authoritative total.');
$switchable = CloudInvoicePresentation::detail([
'invoice' => $renewal,
'balance_payment_allowed' => true,
'balance' => '20.00',
'payment_methods' => [[
'id' => 'stripe_card',
'name' => 'Stripe · 银行卡',
]],
'active_payment' => [
'status' => 'review',
'task_id' => '91',
'payment' => null,
'can_submit' => true,
],
]);
$assert($switchable['show_payment'] === true
&& $switchable['payment_title'] === '选择支付方式'
&& str_contains($switchable['active_payment_message'], '可选择其他支付方式')
&& count($switchable['payment_methods']) === 2
&& $switchable['payment_methods'][0]['id'] === 'balance'
&& $switchable['payment_methods'][0]['selected'] === true,
'Unfinished payment did not remain switchable through the public module.');
$ipChange = [
'id' => '81',
'purpose' => 'ip_change',
'title' => '更换公网 IP',
'currency' => 'USD',
'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' => [],
];
$ipView = CloudInvoicePresentation::detail(['invoice' => $ipChange]);
$ipRow = CloudInvoicePresentation::summaries([$ipChange])[0];
$assert($ipView['show_fulfillment'] === true
&& $ipView['fulfillment_title'] === '公网 IP 更换进度'
&& $ipView['fulfillment_label'] === '待人工核对'
&& $ipView['fulfillment_class'] === 'warning'
&& $ipView['instance_id'] === '41'
&& $ipRow['show_fulfillment'] === true
&& $ipRow['fulfillment_label'] === '待人工核对'
&& $ipRow['context_display'] === '目标实例 vm-audit',
'IP-change presentation lost its target or review-only fulfillment state.');
$unknown = CloudInvoicePresentation::summaries([[
'id' => '99',
'purpose' => 'custom',
'currency' => 'XTS',
'amount' => '7.25',
'status' => 'provider_unknown',
'created_at' => 0,
]])[0];
$assert($unknown['title'] === '账单'
&& $unknown['status_label'] === 'provider_unknown'
&& $unknown['status_class'] === 'other'
&& $unknown['amount_display'] === '7.25 XTS'
&& $unknown['created_display'] === '时间未记录',
'Unknown status or currency did not degrade to a safe display.');
$patch = CloudInvoicePresentation::statusPatch([
'invoice' => $ipChange + [
'display_status' => 'paid',
'job_completed' => false,
'job_attempts' => 2,
'job_updated_at' => 2_000_000_001,
],
'active_payment' => [
'status' => 'pending',
'payment' => ['payment_id' => 'pay-1'],
'can_submit' => true,
],
]);
$assert($patch['status'] === ['label' => '已支付', 'class' => 'running']
&& $patch['payment']['message']
=== '已有待支付订单;可继续原订单或选择其他支付方式。'
&& $patch['fulfillment']['fulfillment_label'] === '待人工核对'
&& $patch['polling']['task_id'] === '82'
&& $patch['polling']['job_attempts'] === 2
&& !array_key_exists('amount', $patch['invoice']),
'Sparse status projection did not isolate mutable payment and polling fields.');
$source = file_get_contents(
dirname(__DIR__) . '/app/Services/Cloud/CloudInvoicePresentation.php'
);
$controllerSource = file_get_contents(
dirname(__DIR__) . '/app/Controllers/CloudPageController.php'
);
$pageServiceSource = file_get_contents(
dirname(__DIR__) . '/app/Services/Cloud/CloudInvoicePageService.php'
);
$assert(is_string($source)
&& !str_contains($source, 'App\\Models')
&& !preg_match('/\\btime\\s*\\(/', $source)
&& !str_contains($source, 'CloudInvoicePaymentService')
&& !str_contains($source, 'CloudInvoiceService::'),
'Presentation module acquired an ORM, clock, payment-provider or domain-service dependency.');
$assert(is_string($controllerSource) && is_string($pageServiceSource)
&& str_contains($pageServiceSource,
'CloudInvoicePresentation::summaries(')
&& str_contains($controllerSource, "\$rows = \$payload['invoices'];")
&& str_contains($controllerSource,
'CloudInvoicePresentation::detail($payload)'),
'Invoice SSR adapters do not consume the unified presentation module.');
echo "Cloud invoice presentation module checks passed.\n";