- 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>
107 lines
4.3 KiB
PHP
107 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Payment;
|
|
|
|
use App\Enums\TransactionStatus;
|
|
use App\Http\Controllers\Api\Admin\Transaction\AdminTransactionController;
|
|
use App\Models\Customer;
|
|
use App\Models\Transaction;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Tests\TestCase;
|
|
|
|
class AdminTransactionApproveTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_approving_the_same_manual_deposit_twice_credits_the_customer_only_once(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$customer = Customer::factory()->create(['total' => 0, 'credit' => 0, 'total_pending' => 100_000]);
|
|
$transaction = Transaction::create([
|
|
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
|
'public_code' => 'DEP-TEST-0001',
|
|
'trans' => 'DEP-TEST-0001',
|
|
'amount' => 100_000,
|
|
'customer_id' => $customer->id,
|
|
'type' => 'manual',
|
|
'status' => TransactionStatus::PENDING->value,
|
|
'proof_image' => 'deposit-proofs/test.jpg',
|
|
]);
|
|
|
|
$controller = app(AdminTransactionController::class);
|
|
|
|
$first = $controller->approve(new Request(), $transaction->uuid);
|
|
$second = $controller->approve(new Request(), $transaction->uuid);
|
|
|
|
$this->assertSame(200, $first->getStatusCode());
|
|
// Second call finds the transaction no longer PENDING → treated as not-approvable.
|
|
$this->assertSame(404, $second->getStatusCode());
|
|
|
|
$this->assertSame(100_000, (int) $customer->fresh()->total);
|
|
}
|
|
|
|
/**
|
|
* Khách khai 5tr nhưng sao kê chỉ về 4tr: số dư phải cộng theo số THỰC NHẬN, phần chênh
|
|
* được ghi lại để kế toán đối chiếu. Trước đây luôn cộng theo số khách khai.
|
|
*/
|
|
public function test_approving_credits_the_received_amount_not_the_declared_one(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$customer = Customer::factory()->create(['total' => 0, 'credit' => 0, 'total_pending' => 5_000_000]);
|
|
$transaction = Transaction::create([
|
|
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
|
'public_code' => 'DEP-TEST-0002',
|
|
'trans' => 'DEP-TEST-0002',
|
|
'amount' => 5_000_000,
|
|
'customer_id' => $customer->id,
|
|
'type' => 'manual',
|
|
'status' => TransactionStatus::PENDING->value,
|
|
'proof_image' => 'deposit-proofs/test.jpg',
|
|
]);
|
|
|
|
$request = Request::create('/', 'POST', ['received_amount' => 4_000_000]);
|
|
|
|
$response = app(AdminTransactionController::class)->approve($request, $transaction->uuid);
|
|
|
|
$this->assertSame(200, $response->getStatusCode());
|
|
$this->assertSame(4_000_000, (int) $customer->fresh()->total);
|
|
$this->assertSame(40_000, (int) $customer->fresh()->credit);
|
|
$this->assertSame(0, (int) $customer->fresh()->total_pending);
|
|
|
|
$transaction->refresh();
|
|
$this->assertSame(5_000_000, (int) $transaction->amount);
|
|
$this->assertSame(4_000_000, (int) $transaction->received_amount);
|
|
$this->assertStringContainsString('Lệch ' . number_format(1_000_000), (string) $transaction->note);
|
|
}
|
|
|
|
/** Bỏ trống received_amount = tin số khách khai, giữ nguyên hành vi cũ. */
|
|
public function test_approving_without_received_amount_credits_the_declared_amount(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$customer = Customer::factory()->create(['total' => 0, 'credit' => 0, 'total_pending' => 300_000]);
|
|
$transaction = Transaction::create([
|
|
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
|
'public_code' => 'DEP-TEST-0003',
|
|
'trans' => 'DEP-TEST-0003',
|
|
'amount' => 300_000,
|
|
'customer_id' => $customer->id,
|
|
'type' => 'manual',
|
|
'status' => TransactionStatus::PENDING->value,
|
|
'proof_image' => 'deposit-proofs/test.jpg',
|
|
]);
|
|
|
|
app(AdminTransactionController::class)->approve(new Request(), $transaction->uuid);
|
|
|
|
$this->assertSame(300_000, (int) $customer->fresh()->total);
|
|
$this->assertSame(300_000, (int) $transaction->fresh()->received_amount);
|
|
$this->assertStringNotContainsString('Lệch', (string) $transaction->fresh()->note);
|
|
}
|
|
}
|