From 59508282b3295ca0258024bdb85c65164249c959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Fri, 13 Mar 2026 16:41:58 +0000 Subject: [PATCH] Add feature guard for refund status safety valves tolerance config --- ...derMarkRefundStatusToleranceConfigTest.php | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderMarkRefundStatusToleranceConfigTest.php diff --git a/tests/Feature/AdminPlatformOrderMarkRefundStatusToleranceConfigTest.php b/tests/Feature/AdminPlatformOrderMarkRefundStatusToleranceConfigTest.php new file mode 100644 index 0000000..f613b93 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderMarkRefundStatusToleranceConfigTest.php @@ -0,0 +1,125 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_mark_refunded_respects_configured_tolerance(): void + { + $this->loginAsPlatformAdmin(); + + // 设置较大的容差(用于验证“refund_total + tol >= paid”口径) + config(['saasshop.amounts.tolerance' => 0.50]); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'refund_tol_plan_01', + 'name' => '退款容差配置测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 已付 10.00;退款总额 9.60;在 tol=0.50 下应允许标记为 refunded + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_TOL_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 9.60, + ], + ], + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/mark-refunded') + ->assertRedirect(); + + $order->refresh(); + $this->assertSame('refunded', $order->payment_status); + $this->assertNotNull($order->refunded_at); + } + + public function test_mark_partially_refunded_is_blocked_when_refund_total_reaches_paid_with_tolerance(): void + { + $this->loginAsPlatformAdmin(); + + config(['saasshop.amounts.tolerance' => 0.50]); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'refund_tol_plan_02', + 'name' => '退款容差配置测试套餐2', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_TOL_0002', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 9.60, + ], + ], + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/mark-partially-refunded') + ->assertRedirect(); + + $order->refresh(); + $this->assertSame('paid', $order->payment_status); + } +}