create(); $product = HostingProduct::create([ 'name' => 'Cloud VPS', 'slug' => 'vps-fulfillment', 'category' => HostingProduct::CATEGORY_VPS, 'type' => HostingProduct::TYPE_VPS, 'contabo_product_id' => 'V91', 'price_monthly' => 50, 'currency' => 'GHS', 'disk_gb' => 75, 'is_active' => true, 'is_visible' => true, ]); $order = CustomerHostingOrder::create([ 'user_id' => $user->id, 'hosting_product_id' => $product->id, 'domain_name' => 'vps-server', 'billing_cycle' => CustomerHostingOrder::CYCLE_MONTHLY, 'amount_paid' => 50, 'currency' => 'GHS', 'status' => CustomerHostingOrder::STATUS_PENDING_APPROVAL, ]); $result = app(HostingOrderFulfillmentService::class)->attemptAutoFulfillment($order); $this->assertTrue($result['fulfilled']); $order->refresh(); $this->assertSame(CustomerHostingOrder::STATUS_APPROVED, $order->status); Bus::assertDispatched(ProvisionHostingOrderJob::class); } public function test_customer_facing_status_hides_approval_wording(): void { $this->assertSame('Pending', CustomerHostingOrder::customerFacingStatusLabelFor( CustomerHostingOrder::STATUS_PENDING_APPROVAL )); $this->assertSame('Pending', CustomerHostingOrder::customerFacingStatusLabelFor( CustomerHostingOrder::STATUS_APPROVED )); } public function test_contabo_402_is_treated_as_payment_required(): void { $exception = ContaboApiException::fromResponse(402, json_encode([ 'message' => 'Request refused as it requires additional payed service.', ], JSON_THROW_ON_ERROR)); $this->assertTrue($exception->isPaymentRequired()); } public function test_order_returns_to_pending_approval_on_contabo_payment_failure(): void { $user = User::factory()->create(); $product = HostingProduct::create([ 'name' => 'Cloud VPS', 'slug' => 'vps-hold', 'category' => HostingProduct::CATEGORY_VPS, 'type' => HostingProduct::TYPE_VPS, 'contabo_product_id' => 'V91', 'price_monthly' => 50, 'currency' => 'GHS', 'disk_gb' => 75, 'is_active' => true, 'is_visible' => true, ]); $order = CustomerHostingOrder::create([ 'user_id' => $user->id, 'hosting_product_id' => $product->id, 'domain_name' => 'vps-hold', 'billing_cycle' => CustomerHostingOrder::CYCLE_MONTHLY, 'amount_paid' => 50, 'currency' => 'GHS', 'status' => CustomerHostingOrder::STATUS_PROVISIONING, ]); $order->holdForAdminProvisioning('Request refused as it requires additional payed service.', 402); $order->refresh(); $this->assertSame(CustomerHostingOrder::STATUS_PENDING_APPROVAL, $order->status); $this->assertSame(402, $order->meta['provisioning_hold']['http_status'] ?? null); $this->assertSame('Pending', $order->customerFacingStatusLabel()); } }