'https://ladill.com/api/billing', 'billing.api_key' => 'test-key', 'billing.force_ip' => '', ]); Http::fake([ 'https://ladill.com/api/billing/debit' => Http::response([ 'transaction_id' => 1, 'reference' => 'R1', 'type' => 'debit', 'amount_minor' => 500, 'balance_after_minor' => 1200, 'service' => 'qr', ], 201), 'https://ladill.com/api/billing/balance*' => Http::response([ 'balance_minor' => 9999, 'currency' => 'GHS', ]), ]); Cache::flush(); $client = app(BillingClient::class); $result = $client->debit('user-1', 500, 'qr', 'qr_create', 'REF-1', 9, 'test'); $this->assertIsArray($result); $this->assertSame(1200, $result['balance_after_minor']); // Should use debit response cache, not hit balance endpoint. $this->assertSame(1200, $client->balanceMinor('user-1')); Http::assertSentCount(1); } public function test_can_afford_uses_balance_not_extra_endpoint(): void { config([ 'billing.api_url' => 'https://ladill.com/api/billing', 'billing.api_key' => 'test-key', 'billing.force_ip' => '', ]); Http::fake([ 'https://ladill.com/api/billing/balance*' => Http::response([ 'balance_minor' => 500, 'currency' => 'GHS', ]), ]); Cache::flush(); $client = app(BillingClient::class); $this->assertTrue($client->canAfford('user-1', 500)); $this->assertFalse($client->canAfford('user-1', 501)); Http::assertSentCount(1); } }