64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\Paddle\PaddleTransactionService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class TenantBillingController extends Controller
|
|
{
|
|
public function __construct(private readonly PaddleTransactionService $paddleTransactions) {}
|
|
|
|
public function transactions(Request $request): JsonResponse
|
|
{
|
|
$tenant = $request->attributes->get('tenant');
|
|
|
|
if (! $tenant) {
|
|
return response()->json([
|
|
'data' => [],
|
|
'message' => 'Tenant not found.',
|
|
], 404);
|
|
}
|
|
|
|
if (! $tenant->paddle_customer_id) {
|
|
return response()->json([
|
|
'data' => [],
|
|
'message' => 'Tenant has no Paddle customer identifier.',
|
|
]);
|
|
}
|
|
|
|
$cursor = $request->query('cursor');
|
|
$perPage = (int) $request->query('per_page', 25);
|
|
|
|
$query = [
|
|
'per_page' => max(1, min($perPage, 100)),
|
|
];
|
|
|
|
if ($cursor) {
|
|
$query['after'] = $cursor;
|
|
}
|
|
|
|
try {
|
|
$result = $this->paddleTransactions->listForCustomer($tenant->paddle_customer_id, $query);
|
|
} catch (\Throwable $exception) {
|
|
Log::warning('Failed to load Paddle transactions', [
|
|
'tenant_id' => $tenant->id,
|
|
'error' => $exception->getMessage(),
|
|
]);
|
|
|
|
return response()->json([
|
|
'data' => [],
|
|
'message' => 'Failed to load Paddle transactions.',
|
|
], 502);
|
|
}
|
|
|
|
return response()->json([
|
|
'data' => $result['data'],
|
|
'meta' => $result['meta'],
|
|
]);
|
|
}
|
|
}
|