feat(billing): renewals, coupons, VAT numbering, billing cycles and invoice payment tracking
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
ea9a53f742
commit
25f23d541e
@@ -30,6 +30,7 @@ class RenewServiceTest extends TestCase
|
||||
$this->customer = Customer::factory()->create(['total' => 100_000]);
|
||||
$product = Product::factory()->create(['product_type' => 'hosting', 'is_active' => true]);
|
||||
ProductPricings::create(['product_id' => $product->id, 'billing_cycle' => 'monthly', 'price' => 15_000, 'is_active' => true]);
|
||||
ProductPricings::create(['product_id' => $product->id, 'billing_cycle' => 'quarterly', 'price' => 40_000, 'is_active' => true]);
|
||||
|
||||
$this->order = Order::create([
|
||||
'order_num' => 'ORD-RENEW-TEST',
|
||||
@@ -75,11 +76,11 @@ class RenewServiceTest extends TestCase
|
||||
$invoice = Invoice::where('invoice_type', 2)->sole();
|
||||
$this->assertSame($this->order->id, (int) $invoice->order_id);
|
||||
$this->assertSame(InvoiceStatus::PAID->value, (int) $invoice->status);
|
||||
$this->assertSame(45_000, (int) $invoice->total);
|
||||
$this->assertSame(55_000, (int) $this->customer->fresh()->total);
|
||||
$this->assertSame(40_000, (int) $invoice->total);
|
||||
$this->assertSame(60_000, (int) $this->customer->fresh()->total);
|
||||
$this->assertSame(1, Order::count());
|
||||
$this->assertTrue($this->service->fresh()->expires_at->isSameDay($expiresAt->addMonths(3)));
|
||||
$this->assertDatabaseHas('transactions', ['customer_id' => $this->customer->id, 'amount' => 45_000]);
|
||||
$this->assertDatabaseHas('transactions', ['customer_id' => $this->customer->id, 'amount' => 40_000]);
|
||||
}
|
||||
|
||||
public function test_insufficient_balance_keeps_unpaid_invoice_and_does_not_extend(): void
|
||||
@@ -93,12 +94,18 @@ class RenewServiceTest extends TestCase
|
||||
$this->assertTrue($this->service->fresh()->expires_at->equalTo($expiresAt));
|
||||
|
||||
$this->customer->update(['total' => 100_000]);
|
||||
$this->renew(2)->assertOk();
|
||||
$this->renew(3)->assertOk();
|
||||
|
||||
$invoice = Invoice::where('invoice_type', 2)->sole();
|
||||
$this->assertSame(InvoiceStatus::PAID->value, (int) $invoice->status);
|
||||
$this->assertSame(30_000, (int) $invoice->total);
|
||||
$this->assertSame(40_000, (int) $invoice->total);
|
||||
$this->assertSame(1, $invoice->invoiceItems()->count());
|
||||
$this->assertSame(70_000, (int) $this->customer->fresh()->total);
|
||||
$this->assertSame(60_000, (int) $this->customer->fresh()->total);
|
||||
}
|
||||
|
||||
public function test_months_without_a_priced_cycle_are_rejected(): void
|
||||
{
|
||||
$this->renew(2)->assertStatus(422);
|
||||
$this->assertSame(0, Invoice::where('invoice_type', 2)->count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user