>, meta: array} */ public function listForCustomer(string $customerId, array $query = []): array { $payload = array_filter(array_merge([ 'customer_id' => $customerId, 'order_by' => '-created_at', ], $query), static fn ($value) => $value !== null && $value !== ''); $response = $this->client->get('/transactions', $payload); $transactions = Arr::get($response, 'data', []); $meta = Arr::get($response, 'meta.pagination', []); if (! is_array($transactions)) { $transactions = []; } return [ 'data' => array_map([$this, 'mapTransaction'], $transactions), 'meta' => $this->mapPagination($meta), ]; } /** * @param array $transaction * @return array */ protected function mapTransaction(array $transaction): array { $totals = Arr::get($transaction, 'totals', []); return [ 'id' => $transaction['id'] ?? null, 'status' => $transaction['status'] ?? null, 'amount' => $this->resolveAmount($transaction, $totals), 'currency' => $transaction['currency_code'] ?? Arr::get($transaction, 'currency') ?? 'EUR', 'origin' => $transaction['origin'] ?? null, 'checkout_id' => $transaction['checkout_id'] ?? Arr::get($transaction, 'details.checkout_id'), 'created_at' => $transaction['created_at'] ?? null, 'updated_at' => $transaction['updated_at'] ?? null, 'receipt_url' => Arr::get($transaction, 'invoice_url') ?? Arr::get($transaction, 'receipt_url'), 'tax' => Arr::get($totals, 'tax_total') ?? null, 'grand_total' => Arr::get($totals, 'grand_total') ?? null, ]; } /** * @param array $transaction * @param array|null $totals */ protected function resolveAmount(array $transaction, $totals): ?float { $amount = Arr::get($totals ?? [], 'subtotal') ?? Arr::get($totals ?? [], 'grand_total'); if ($amount !== null) { return (float) $amount; } $raw = $transaction['amount'] ?? null; if ($raw === null) { return null; } return (float) $raw; } /** * @param array $pagination * @return array */ protected function mapPagination(array $pagination): array { return [ 'next' => $pagination['next'] ?? null, 'previous' => $pagination['previous'] ?? null, 'has_more' => (bool) ($pagination['has_more'] ?? false), ]; } }