From 7a89d106b1e733bbbb14ed1102a396907a27fd9c Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Thu, 12 Nov 2026 22:05:40 +0100 Subject: [PATCH] Add the Billing API package Adds Joomla\Github\Package\Billing ($github->billing) with the Budgets sub-package (organisation budgets) and the Usage sub-package (usage, usage summary, premium request and AI credit reports for organisations and users), with tests and docs/billing.md. Co-Authored-By: Claude Opus 5.5 --- Tests/Package/Billing/BudgetsTest.php | 215 +++++++++++++++++ Tests/Package/Billing/UsageTest.php | 320 ++++++++++++++++++++++++++ Tests/Package/BillingTest.php | 61 +++++ docs/billing.md | 42 ++++ src/Package/Billing.php | 26 +++ src/Package/Billing/Budgets.php | 130 +++++++++++ src/Package/Billing/Usage.php | 222 ++++++++++++++++++ 7 files changed, 1016 insertions(+) create mode 100644 Tests/Package/Billing/BudgetsTest.php create mode 100644 Tests/Package/Billing/UsageTest.php create mode 100644 Tests/Package/BillingTest.php create mode 100644 docs/billing.md create mode 100644 src/Package/Billing.php create mode 100644 src/Package/Billing/Budgets.php create mode 100644 src/Package/Billing/Usage.php diff --git a/Tests/Package/Billing/BudgetsTest.php b/Tests/Package/Billing/BudgetsTest.php new file mode 100644 index 00000000..63b56d54 --- /dev/null +++ b/Tests/Package/Billing/BudgetsTest.php @@ -0,0 +1,215 @@ +object = new Budgets($this->options, $this->client); + } + + /** + * Tests the getListForOrg method. + * + * @return void + */ + public function testGetListForOrg(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/budgets?page=2&per_page=10&scope=organization', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getListForOrg('joomla', ['scope' => 'organization'], 2, 10) + ); + } + + /** + * Tests the getListForOrg method. + * + * @return void + */ + public function testGetListForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/budgets?page=2&per_page=10&scope=organization', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getListForOrg('joomla', ['scope' => 'organization'], 2, 10); + } + + /** + * Tests the createForOrg method. + * + * @return void + */ + public function testCreateForOrg(): void + { + $this->client->expects($this->once()) + ->method('post') + ->with('/organizations/joomla/settings/billing/budgets', json_encode(['budget_amount' => 'value']), [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->createForOrg('joomla', ['budget_amount' => 'value']) + ); + } + + /** + * Tests the createForOrg method. + * + * @return void + */ + public function testCreateForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('post') + ->with('/organizations/joomla/settings/billing/budgets', json_encode(['budget_amount' => 'value']), [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->createForOrg('joomla', ['budget_amount' => 'value']); + } + + /** + * Tests the getForOrg method. + * + * @return void + */ + public function testGetForOrg(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/budgets/abc123', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getForOrg('joomla', 'abc123') + ); + } + + /** + * Tests the getForOrg method. + * + * @return void + */ + public function testGetForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/budgets/abc123', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getForOrg('joomla', 'abc123'); + } + + /** + * Tests the editForOrg method. + * + * @return void + */ + public function testEditForOrg(): void + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/organizations/joomla/settings/billing/budgets/abc123', json_encode(['budget_amount' => 'value']), [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->editForOrg('joomla', 'abc123', ['budget_amount' => 'value']) + ); + } + + /** + * Tests the editForOrg method. + * + * @return void + */ + public function testEditForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/organizations/joomla/settings/billing/budgets/abc123', json_encode(['budget_amount' => 'value']), [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->editForOrg('joomla', 'abc123', ['budget_amount' => 'value']); + } + + /** + * Tests the deleteForOrg method. + * + * @return void + */ + public function testDeleteForOrg(): void + { + $this->client->expects($this->once()) + ->method('delete') + ->with('/organizations/joomla/settings/billing/budgets/abc123', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->deleteForOrg('joomla', 'abc123') + ); + } + + /** + * Tests the deleteForOrg method. + * + * @return void + */ + public function testDeleteForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('delete') + ->with('/organizations/joomla/settings/billing/budgets/abc123', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->deleteForOrg('joomla', 'abc123'); + } +} diff --git a/Tests/Package/Billing/UsageTest.php b/Tests/Package/Billing/UsageTest.php new file mode 100644 index 00000000..88b4d336 --- /dev/null +++ b/Tests/Package/Billing/UsageTest.php @@ -0,0 +1,320 @@ +object = new Usage($this->options, $this->client); + } + + /** + * Tests the getAiCreditReportForOrg method. + * + * @return void + */ + public function testGetAiCreditReportForOrg(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/ai_credit/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getAiCreditReportForOrg('joomla', ['year' => 2026]) + ); + } + + /** + * Tests the getAiCreditReportForOrg method. + * + * @return void + */ + public function testGetAiCreditReportForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/ai_credit/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getAiCreditReportForOrg('joomla', ['year' => 2026]); + } + + /** + * Tests the getPremiumRequestReportForOrg method. + * + * @return void + */ + public function testGetPremiumRequestReportForOrg(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/premium_request/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getPremiumRequestReportForOrg('joomla', ['year' => 2026]) + ); + } + + /** + * Tests the getPremiumRequestReportForOrg method. + * + * @return void + */ + public function testGetPremiumRequestReportForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/premium_request/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getPremiumRequestReportForOrg('joomla', ['year' => 2026]); + } + + /** + * Tests the getReportForOrg method. + * + * @return void + */ + public function testGetReportForOrg(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getReportForOrg('joomla', ['year' => 2026]) + ); + } + + /** + * Tests the getReportForOrg method. + * + * @return void + */ + public function testGetReportForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getReportForOrg('joomla', ['year' => 2026]); + } + + /** + * Tests the getSummaryForOrg method. + * + * @return void + */ + public function testGetSummaryForOrg(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/usage/summary?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getSummaryForOrg('joomla', ['year' => 2026]) + ); + } + + /** + * Tests the getSummaryForOrg method. + * + * @return void + */ + public function testGetSummaryForOrgFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/organizations/joomla/settings/billing/usage/summary?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getSummaryForOrg('joomla', ['year' => 2026]); + } + + /** + * Tests the getAiCreditReportForUser method. + * + * @return void + */ + public function testGetAiCreditReportForUser(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/ai_credit/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getAiCreditReportForUser('octocat', ['year' => 2026]) + ); + } + + /** + * Tests the getAiCreditReportForUser method. + * + * @return void + */ + public function testGetAiCreditReportForUserFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/ai_credit/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getAiCreditReportForUser('octocat', ['year' => 2026]); + } + + /** + * Tests the getPremiumRequestReportForUser method. + * + * @return void + */ + public function testGetPremiumRequestReportForUser(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/premium_request/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getPremiumRequestReportForUser('octocat', ['year' => 2026]) + ); + } + + /** + * Tests the getPremiumRequestReportForUser method. + * + * @return void + */ + public function testGetPremiumRequestReportForUserFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/premium_request/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getPremiumRequestReportForUser('octocat', ['year' => 2026]); + } + + /** + * Tests the getReportForUser method. + * + * @return void + */ + public function testGetReportForUser(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getReportForUser('octocat', ['year' => 2026]) + ); + } + + /** + * Tests the getReportForUser method. + * + * @return void + */ + public function testGetReportForUserFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/usage?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getReportForUser('octocat', ['year' => 2026]); + } + + /** + * Tests the getSummaryForUser method. + * + * @return void + */ + public function testGetSummaryForUser(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/usage/summary?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->sampleString, 200)); + + $this->assertEquals( + json_decode($this->sampleString), + $this->object->getSummaryForUser('octocat', ['year' => 2026]) + ); + } + + /** + * Tests the getSummaryForUser method. + * + * @return void + */ + public function testGetSummaryForUserFailure(): void + { + $this->expectException(UnexpectedResponseException::class); + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/octocat/settings/billing/usage/summary?year=2026', [], 0) + ->willReturn($this->getResponseObject($this->errorString, 500)); + + $this->object->getSummaryForUser('octocat', ['year' => 2026]); + } +} diff --git a/Tests/Package/BillingTest.php b/Tests/Package/BillingTest.php new file mode 100644 index 00000000..ce716c31 --- /dev/null +++ b/Tests/Package/BillingTest.php @@ -0,0 +1,61 @@ +object = new Billing($this->options, $this->client); + } + + /** + * Tests that the budgets sub-package is resolved. + * + * @return void + */ + public function testGetBudgets(): void + { + $this->assertInstanceOf(Budgets::class, $this->object->budgets); + } + + /** + * Tests that the usage sub-package is resolved. + * + * @return void + */ + public function testGetUsage(): void + { + $this->assertInstanceOf(Usage::class, $this->object->usage); + } +} diff --git a/docs/billing.md b/docs/billing.md new file mode 100644 index 00000000..917311eb --- /dev/null +++ b/docs/billing.md @@ -0,0 +1,42 @@ +# Billing + +The Billing package covers the GitHub billing REST API for organisations and users: budgets and the usage, premium request and AI credit usage reports. It has two sub-packages, `$github->billing->budgets` and `$github->billing->usage`, for example `$github->billing->usage->getReportForOrg('joomla', ['year' => 2026])`. Methods for organisations end in `ForOrg`, methods for users in `ForUser`. + +```php +$github = new Joomla\Github\Github($options); + +// Usage summary of an organisation for January 2026. +$summary = $github->billing->usage->getSummaryForOrg('joomla', ['year' => 2026, 'month' => 1]); + +// List the budgets of an organisation. +$budgets = $github->billing->budgets->getListForOrg('joomla'); +``` + +## Budgets + +`$github->billing->budgets` - https://docs.github.com/rest/billing/budgets + +| Method | Endpoint | +| --- | --- | +| `getListForOrg($org, $filters, $page, $limit)` | `GET /organizations/{org}/settings/billing/budgets` | +| `createForOrg($org, $options)` | `POST /organizations/{org}/settings/billing/budgets` | +| `getForOrg($org, $budgetId)` | `GET /organizations/{org}/settings/billing/budgets/{budget_id}` | +| `editForOrg($org, $budgetId, $options)` | `PATCH /organizations/{org}/settings/billing/budgets/{budget_id}` | +| `deleteForOrg($org, $budgetId)` | `DELETE /organizations/{org}/settings/billing/budgets/{budget_id}` | + +## Usage + +`$github->billing->usage` - https://docs.github.com/rest/billing/usage + +| Method | Endpoint | +| --- | --- | +| `getAiCreditReportForOrg($org, $filters)` | `GET /organizations/{org}/settings/billing/ai_credit/usage` | +| `getPremiumRequestReportForOrg($org, $filters)` | `GET /organizations/{org}/settings/billing/premium_request/usage` | +| `getReportForOrg($org, $filters)` | `GET /organizations/{org}/settings/billing/usage` | +| `getSummaryForOrg($org, $filters)` | `GET /organizations/{org}/settings/billing/usage/summary` | +| `getAiCreditReportForUser($username, $filters)` | `GET /users/{username}/settings/billing/ai_credit/usage` | +| `getPremiumRequestReportForUser($username, $filters)` | `GET /users/{username}/settings/billing/premium_request/usage` | +| `getReportForUser($username, $filters)` | `GET /users/{username}/settings/billing/usage` | +| `getSummaryForUser($username, $filters)` | `GET /users/{username}/settings/billing/usage/summary` | + +Enterprise billing endpoints (`/enterprises/...`) are not included. diff --git a/src/Package/Billing.php b/src/Package/Billing.php new file mode 100644 index 00000000..2c0b9837 --- /dev/null +++ b/src/Package/Billing.php @@ -0,0 +1,26 @@ +fetchUrl($path, $page, $limit); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Create a budget for an organisation. + * + * @param string $org The organisation name. + * @param array $options Optional body fields: `budget_amount`, `prevent_further_usage`, `budget_alerting`, `budget_scope`, `budget_entity_name`, `budget_type`, `budget_product_sku`, `user`, `expires_at`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/budgets#create-a-budget-for-an-organization + * @since __DEPLOY_VERSION__ + */ + public function createForOrg(string $org, array $options = []) + { + // Build the request path. + $path = '/organizations/' . $org . '/settings/billing/budgets'; + + $data = (object) $options; + + return $this->processResponse($this->client->post($this->fetchUrl($path), json_encode($data))); + } + + /** + * Get a budget by ID for an organisation. + * + * @param string $org The organisation name. + * @param string $budgetId The ID of the budget. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/budgets#get-a-budget-by-id-for-an-organization + * @since __DEPLOY_VERSION__ + */ + public function getForOrg(string $org, string $budgetId) + { + // Build the request path. + $path = '/organizations/' . $org . '/settings/billing/budgets/' . $budgetId; + + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Update a budget for an organisation. + * + * @param string $org The organisation name. + * @param string $budgetId The ID of the budget. + * @param array $options Optional body fields: `budget_amount`, `prevent_further_usage`, `budget_alerting`, `expires_at`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/budgets#update-a-budget-for-an-organization + * @since __DEPLOY_VERSION__ + */ + public function editForOrg(string $org, string $budgetId, array $options = []) + { + // Build the request path. + $path = '/organizations/' . $org . '/settings/billing/budgets/' . $budgetId; + + $data = (object) $options; + + return $this->processResponse($this->client->patch($this->fetchUrl($path), json_encode($data))); + } + + /** + * Delete a budget for an organisation. + * + * @param string $org The organisation name. + * @param string $budgetId The ID of the budget. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/budgets#delete-a-budget-for-an-organization + * @since __DEPLOY_VERSION__ + */ + public function deleteForOrg(string $org, string $budgetId) + { + // Build the request path. + $path = '/organizations/' . $org . '/settings/billing/budgets/' . $budgetId; + + return $this->processResponse($this->client->delete($this->fetchUrl($path))); + } +} diff --git a/src/Package/Billing/Usage.php b/src/Package/Billing/Usage.php new file mode 100644 index 00000000..df482ee2 --- /dev/null +++ b/src/Package/Billing/Usage.php @@ -0,0 +1,222 @@ +fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get the billing premium request usage report for an organisation. + * + * @param string $org The organisation name. + * @param array $filters Optional query parameters: `year`, `month`, `day`, `user`, `model`, `product`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/usage#get-billing-premium-request-usage-report-for-an-organization + * @since __DEPLOY_VERSION__ + */ + public function getPremiumRequestReportForOrg(string $org, array $filters = []) + { + // Build the request path. + $path = '/organizations/' . $org . '/settings/billing/premium_request/usage'; + + $uri = $this->fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get the billing usage report for an organisation. + * + * @param string $org The organisation name. + * @param array $filters Optional query parameters: `year`, `month`, `day`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/usage#get-billing-usage-report-for-an-organization + * @since __DEPLOY_VERSION__ + */ + public function getReportForOrg(string $org, array $filters = []) + { + // Build the request path. + $path = '/organizations/' . $org . '/settings/billing/usage'; + + $uri = $this->fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get the billing usage summary for an organisation. + * + * @param string $org The organisation name. + * @param array $filters Optional query parameters: `year`, `month`, `day`, `repository`, `product`, `sku`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/usage#get-billing-usage-summary-for-an-organization + * @since __DEPLOY_VERSION__ + */ + public function getSummaryForOrg(string $org, array $filters = []) + { + // Build the request path. + $path = '/organizations/' . $org . '/settings/billing/usage/summary'; + + $uri = $this->fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get the billing AI credit usage report for a user. + * + * @param string $username The handle for the GitHub user account. + * @param array $filters Optional query parameters: `year`, `month`, `day`, `model`, `product`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/usage#get-billing-ai-credit-usage-report-for-a-user + * @since __DEPLOY_VERSION__ + */ + public function getAiCreditReportForUser(string $username, array $filters = []) + { + // Build the request path. + $path = '/users/' . $username . '/settings/billing/ai_credit/usage'; + + $uri = $this->fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get the billing premium request usage report for a user. + * + * @param string $username The handle for the GitHub user account. + * @param array $filters Optional query parameters: `year`, `month`, `day`, `model`, `product`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/usage#get-billing-premium-request-usage-report-for-a-user + * @since __DEPLOY_VERSION__ + */ + public function getPremiumRequestReportForUser(string $username, array $filters = []) + { + // Build the request path. + $path = '/users/' . $username . '/settings/billing/premium_request/usage'; + + $uri = $this->fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get the billing usage report for a user. + * + * @param string $username The handle for the GitHub user account. + * @param array $filters Optional query parameters: `year`, `month`, `day`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/usage#get-billing-usage-report-for-a-user + * @since __DEPLOY_VERSION__ + */ + public function getReportForUser(string $username, array $filters = []) + { + // Build the request path. + $path = '/users/' . $username . '/settings/billing/usage'; + + $uri = $this->fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get the billing usage summary for a user. + * + * @param string $username The handle for the GitHub user account. + * @param array $filters Optional query parameters: `year`, `month`, `day`, `repository`, `product`, `sku`. + * + * @return object|array + * + * @link https://docs.github.com/rest/billing/usage#get-billing-usage-summary-for-a-user + * @since __DEPLOY_VERSION__ + */ + public function getSummaryForUser(string $username, array $filters = []) + { + // Build the request path. + $path = '/users/' . $username . '/settings/billing/usage/summary'; + + $uri = $this->fetchUrl($path); + + foreach ($filters as $key => $value) { + $uri->setVar($key, $value); + } + + return $this->processResponse($this->client->get($uri)); + } +}