create(['total' => 500_000]); $product = Product::factory()->create(['product_type' => 'hosting', 'service_plan_id' => null]); $order = Order::create([ 'order_num' => 'ORD-' . uniqid(), 'customer_id' => $customer->id, 'sub_total' => 200_000, 'total' => 200_000, 'status' => OrderStatus::PENDING->value, ]); $item = OrderItem::create([ 'order_id' => $order->id, 'product_id' => $product->id, 'billing_cycle' => 'monthly', 'months' => 1, 'server_name' => 'khach-hang.test', 'quantity' => 1, 'price' => 200_000, ]); $invoice = Invoice::create([ 'invoice_number' => 'INV-' . uniqid(), 'customer_id' => $customer->id, 'order_id' => $order->id, 'invoice_type' => 1, 'sub_total' => 200_000, 'tax' => 0, 'total' => 200_000, 'status' => InvoiceStatus::UNPAID->value, ]); $service = Service::create([ 'customer_id' => $customer->id, 'product_id' => $product->id, 'order_item_id' => $item->id, 'invoice_id' => $invoice->id, 'server_name' => 'khach-hang.test', 'status' => 'pending', 'started_at' => now(), 'expires_at' => now()->addMonth(), ]); app(InvoicePaymentService::class)->payWithBalance($invoice, $customer, 'balance'); $this->assertSame(300_000, (int) $customer->fresh()->total); dispatch_sync(new ProvisionHostingAccountJob($item->fresh())); $this->assertSame('failed', $service->fresh()->status); $this->assertSame(500_000, (int) $customer->fresh()->total); $this->assertSame(InvoiceStatus::REFUNDED->value, (int) $invoice->fresh()->status); $this->assertSame(OrderStatus::CANCELLED->value, $order->fresh()->status); Bus::assertDispatched(VMCreationFailedJob::class); } }