feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk
- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch - Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay - Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng - Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10af41c5cf
commit
c5115b52dd
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\Admin\Customer;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Models\DomainPricing;
|
||||
use App\Models\Product;
|
||||
use App\Models\Service;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateDomainServicePricingTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $admin;
|
||||
|
||||
private Customer $customer;
|
||||
|
||||
private Product $product;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
|
||||
$this->admin = User::factory()->create();
|
||||
$this->admin->assignRole('Full Administrator');
|
||||
$this->customer = Customer::factory()->create();
|
||||
$this->product = Product::factory()->create(['product_type' => 'domain']);
|
||||
|
||||
DomainPricing::query()->delete();
|
||||
DomainPricing::create(['type' => 'domain', 'tld' => '.vn', 'setup_fee' => '100000', 'first_year' => 400_000, 'recurring_fee' => '350000', 'is_active' => true]);
|
||||
DomainPricing::create(['type' => 'domain', 'tld' => '.com.vn', 'setup_fee' => 'Miễn phí', 'first_year' => 300_000, 'recurring_fee' => '300000', 'is_active' => true]);
|
||||
}
|
||||
|
||||
private function createService(array $data)
|
||||
{
|
||||
return $this->actingAs($this->admin, 'admin')->postJson(
|
||||
"/api/v1/administrator/customers/{$this->customer->uuid}/services",
|
||||
['product_id' => $this->product->id, 'payment_method' => 'transfer', 'billing_cycle' => 'biennially', ...$data],
|
||||
);
|
||||
}
|
||||
|
||||
public function test_domain_service_uses_domain_pricing_for_matched_tld(): void
|
||||
{
|
||||
$this->createService(['server_name' => 'Example.COM.vn'])->assertCreated();
|
||||
$this->createService(['server_name' => 'example.vn'])->assertCreated();
|
||||
|
||||
$this->assertDatabaseHas('order_items', ['domain_name' => 'Example.COM.vn', 'price' => 600_000]);
|
||||
$this->assertDatabaseHas('order_items', ['domain_name' => 'example.vn', 'price' => 850_000]);
|
||||
}
|
||||
|
||||
public function test_domain_without_pricing_requires_amount(): void
|
||||
{
|
||||
$this->createService(['server_name' => 'example.xyz'])->assertStatus(422);
|
||||
$this->assertSame(0, Service::count());
|
||||
|
||||
$this->createService(['server_name' => 'example.xyz', 'amount_paid' => 250_000])->assertCreated();
|
||||
$this->assertDatabaseHas('order_items', ['domain_name' => 'example.xyz', 'price' => 250_000]);
|
||||
}
|
||||
|
||||
public function test_saving_price_on_service_without_order_creates_unpaid_order_and_invoice(): void
|
||||
{
|
||||
$service = Service::create([
|
||||
'customer_id' => $this->customer->id,
|
||||
'product_id' => $this->product->id,
|
||||
'server_name' => 'example.vn',
|
||||
'status' => 'active',
|
||||
]);
|
||||
$url = "/api/v1/administrator/customers/{$this->customer->uuid}/services/{$service->id}";
|
||||
|
||||
$this->actingAs($this->admin, 'admin')->putJson($url, ['price' => 500_000, 'billing_cycle' => 'annually'])->assertOk();
|
||||
|
||||
$service->refresh();
|
||||
$this->assertSame(500_000, (int) $service->orderItem->price);
|
||||
$this->assertSame(1, (int) $service->invoice->status);
|
||||
$this->assertSame(500_000, (int) $service->invoice->total);
|
||||
|
||||
$this->actingAs($this->admin, 'admin')->putJson($url, ['price' => 450_000])->assertOk();
|
||||
|
||||
$this->assertSame(450_000, (int) $service->invoice->fresh()->total);
|
||||
$this->assertSame(450_000, (int) $service->invoice->invoiceItems()->value('total_price'));
|
||||
$this->assertDatabaseCount('invoices', 1);
|
||||
}
|
||||
|
||||
public function test_domain_quote_endpoint(): void
|
||||
{
|
||||
$url = '/api/v1/administrator/services/domain-quote';
|
||||
|
||||
$this->actingAs($this->admin, 'admin')->getJson("{$url}?domain=abc.vn&billing_cycle=triennially")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.tld', '.vn')
|
||||
->assertJsonPath('data.years', 3)
|
||||
->assertJsonPath('data.price', 1_200_000);
|
||||
|
||||
$this->actingAs($this->admin, 'admin')->getJson("{$url}?domain=abc.xyz")
|
||||
->assertOk()
|
||||
->assertJsonPath('data', null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user