PHPackages                             pondersource/billing-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. pondersource/billing-api

ActiveLibrary[API Development](/categories/api)

pondersource/billing-api
========================

A Billing API for Heroku, Github, AWS

2.0.2(4y ago)0354↓33.3%MITPHPPHP ^7.3||^8.0

Since Mar 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/pondersource/billing-api)[ Packagist](https://packagist.org/packages/pondersource/billing-api)[ Docs](https://github.com/pondersource/billing-api)[ RSS](/packages/pondersource-billing-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (8)Used By (0)

Billing API PHP Client
----------------------

[](#billing-api-php-client)

### Requirements

[](#requirements)

- PHP 7.3+ or 8.x

A PHP client for the Billing Platform API working for Invoices, Account, Apps .etc

### Usage

[](#usage)

`composer require pondersource/billing-api`

- Checkout this repo
- Create a .env file you can do it go to the CLI and run `cp .env.example .env`
- Comment/uncomment the service for which you want to retrieve invoices or usage info (Google, AWS, Github, Heroku).
- Run `composer install`
- Go to  and create a personal access token. Tick 'admin:org' and 'user' as scopes.
- Save this in your `.env` file as:

```
GITHUB_ACCESS_TOKEN=ghp_0AwgbEb....

```

- You need to show your own Github Username:

```
$user_billing = $github->getUserSharedStorageBilling("michielbdejong");

```

- Run `echo -n; heroku auth:token` to get a personal token for Heroku or you can do it simple just run `heroku auth:token` inside CLI.
- Save this in your `.env` file as:

```
HEROKU_API_KEY=30a84169-7c38-4b71-a19...

```

- Working with google you need to run first `cloud auth application-default login` from CLI
- It generate you json file that you can copy and paste inside Google `putenv('GOOGLE_APPLICATION_CREDENTIALS='.realpath("application_default_credentials.json"))`
- Run `php index.php`
- When you run `php index.php` every service will generate xml or json array collection of item UBL and JSON

Heroku API Client
-----------------

[](#heroku-api-client)

```
use PonderSource\HerokuApi\HerokuClient;

$her = new HerokuClient([
    'apiKey' =>  getenv('HEROKU_API_KEY'),
]);

$her->getHerokuInvoice();
$her->getHerokuTeamInvoices();
```

We are using Heroku Invoices for simple user and we can use in the same way for the teams and I will show you response of one of the function. We will work directly with platform API of the Heroku and fetching inforamtion.

- Response json from first method for simple Heroku Invoice

```
[
    {
        "charges_total": 0,
        "created_at": "2022-02-17T02:45:30Z",
        "credits_total": 0,
        "id": "22e1c650-291e-48b7-b462-4bbd9eba4a0e",
        "number": 62983158,
        "period_end": "2022-03-01",
        "period_start": "2022-02-01",
        "state": 1,
        "total": 0,
        "updated_at": "2022-03-01T12:59:11Z"
    },
    {
        "charges_total": 0,
        "created_at": "2022-03-01T02:44:04Z",
        "credits_total": 0,
        "id": "e4bbdb15-40db-4de8-b89f-d2f921766302",
        "number": 63410419,
        "period_end": "2022-03-17",
        "period_start": "2022-03-01",
        "state": 0,
        "total": 0,
        "updated_at": "2022-03-17T02:40:34Z"
    }
]
```

- Reponse UBL from first method for simple Heroku Invoice

```

  0
  2022-02-17T02:45:30Z

  22e1c650-291e-48b7-b462-4bbd9eba4a0e
  62983158
  2022-02-01
  2022-03-01
  1
  0
  2022-03-01T12:59:11Z

  0
  2022-03-01T02:44:04Z

  e4bbdb15-40db-4de8-b89f-d2f921766302
  63410419
  2022-03-01
  2022-03-17
  0
  0
  2022-03-17T02:40:34Z

```

Google API Client
-----------------

[](#google-api-client)

```
use PonderSource\GoogleApi\Google;

$google = new Google([
    'apiKey' => putenv('GOOGLE_APPLICATION_CREDENTIALS='.realpath("application_default_credentials.json"))
]);
$google->getCloudbillingSkus();
```

Inside your json file you will generate it in the up you can see instruction. We are using Google Cloud library for take information for services and other stuff.

- Response from JSON one of example

```
[
    {
        "sku_name": "services\/0069-3716-5463\/skus\/00C0-AE90-D5AE",
        "sku_id": "00C0-AE90-D5AE",
        "sku_description": "Custom Commit Plan QUser",
        "sku_provider_name": "Qubole",
        "sku_service_name": "Qubole Data Service",
        "sku_resource": "ApplicationServices",
        "sku_group": "Qubole",
        "sku_usage_type": "OnDemand",
        "sku_effective_time": "18:42:26",
        "sku_usage_unit": "mo",
        "sku_usage_unit_description": "month",
        "sku_base_unit": "s",
        "sku_base_unit_description": "second",
        "sku_base_unit_conversion_factor": 2674800,
        "sku_display_quantity": 1,
        "sku_start_usage_amount": 0,
        "sku_unit_price": "USD"
    },
]
```

- Response UBL show one of example

```

  services/0069-3716-5463/skus/00C0-AE90-D5AE
  00C0-AE90-D5AE
  Custom Commit Plan QUser
  Qubole
  Qubole Data Service
  ApplicationServices
  Qubole
  OnDemand
  18:42:26
  mo
  month
  s
  second
  2674800
  1
  0

```

GitHub API PHP Client
=====================

[](#github-api-php-client)

Namespace `PonderSource\GitHubApi`

### Authorization

[](#authorization)

We need to provide the user's TOKEN(We recommend to use TOKENS with expiration date)

### Headers

[](#headers)

Recuired Headers to call the GitHub API endpoints:

```
    "User-Agent: Example REST API Client",
    "Accept: application/vnd.github.v3+json",
    "Authorization: token TOKEN"

```

### Methods

[](#methods)

We can ask for billing information either for a user or organization

#### Organization

[](#organization)

- getOrgSharedStorageBilling($org)
    - [Get GitHub Actions billing for an organization](https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-an-organization)
- getOrgActionsBilling($org)
    - [Get GitHub Packages billing for an organization](https://docs.github.com/en/rest/reference/billing#get-github-packages-billing-for-an-organization)
- getOrgPackagesBillingInfo($org)
    - [Get shared storage billing for an organization](https://docs.github.com/en/rest/reference/billing#get-shared-storage-billing-for-an-organization)

##### User

[](#user)

- getUserSharedStorageBilling($user)
    - [Get GitHub Actions billing for a user](https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-a-user)
- getUserActionsBilling($user)
    - [Get GitHub Packages billing for a user](https://docs.github.com/en/rest/reference/billing#get-github-packages-billing-for-a-user)
- getUserPackagesBillingInfo($user)
    - [Get shared storage billing for a user](https://docs.github.com/en/rest/reference/billing#get-shared-storage-billing-for-a-user)

#### Example

[](#example)

##### Get shared storage billing for an organization

[](#get-shared-storage-billing-for-an-organization)

At the `billing-api/index.php` first we need to create the GitHub Client

1. First we have to initialize the GitHub Client

```
$github = new GitHubClient();

```

2. Now we can choose between the 6 available functions and retrieve billing info(JSON) either for Organization or User.

```
$github->getOrgSharedStorageBilling("org");

```

3. Response

```
{
 "days_left_in_billing_cycle": 20,
 "estimated_paid_storage_for_month": 15,
 "estimated_storage_for_month": 40
}

```

AWS API PHP Client
==================

[](#aws-api-php-client)

Namespace `PonderSource\AWSApi`

- PHP library for communication with AWS services: [AWS SDK](https://aws.amazon.com/sdk-for-php/).
- Cost Explorer API endpoint: `https://ce.us-east-1.amazonaws.com`.

### Credentials

[](#credentials)

From `~/.aws/credentials.ini` we can retireve the credentials

- AWS\_ACCESS\_KEY\_ID
- AWS\_SECRET\_ACCESS\_KEY

#### Using temporary security credentials with the AWS CLI

[](#using-temporary-security-credentials-with-the-aws-cli)

`aws sts get-session-token --serial-number arn-of-the-mfa-device --token-code code-from-token`

### [Root Access Keys VS IAM Access Keys](https://docs.aws.amazon.com/general/latest/gr/root-vs-iam.html)

[](#root-access-keys-vs-iam-access-keys)

- Root access

    - Allow full access to all resources in the account
- IAM Access Keys

    - Access to AWS services and resources for users in your AWS account

### Example

[](#example-1)

1. At the `billing-api/index.php` first we need to create AWS Client

```
$aws = new AWSClient([
    'region'  => 'us-east-1',
    'version' => 'latest',
    'credentials' => [
      'key' => $key,
      'secret' => $secret
    ],
    'endpoint' => 'https://ce.us-east-1.amazonaws.com'
]);

```

2. Now we can get Cost and Usage report. Please consider, that the User have to enable the Cost Explorer first(It may take some time to ingest the data)

```

$aws->getCostAndUsage([
'Granularity' => 'DAILY', // REQUIRED
'Metrics' => ['BlendedCost'], // REQUIRED
'TimePeriod' => [ // REQUIRED
		'Start' => '2022-01-03', // REQUIRED
    'End' => '2022-02-03', // REQUIRED
	],
],'aws_cost_and_usage');

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

1496d ago

Major Versions

1.0.1 → 2.0.12022-04-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/90cf56bb60a2395a6f8c61ae3ee3b41193bda2cd21049e0e7cbed3385233da7a?d=identicon)[AlexMalikov94](/maintainers/AlexMalikov94)

![](https://www.gravatar.com/avatar/314812d46664b241ac4719c58eca4c93b24dc93b93c6bda9f65488fd0befd150?d=identicon)[michielbdejong](/maintainers/michielbdejong)

---

Top Contributors

[![ishifoev](https://avatars.githubusercontent.com/u/34019391?v=4)](https://github.com/ishifoev "ishifoev (77 commits)")[![michielbdejong](https://avatars.githubusercontent.com/u/408412?v=4)](https://github.com/michielbdejong "michielbdejong (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pondersource-billing-api/health.svg)

```
[![Health](https://phpackages.com/badges/pondersource-billing-api/health.svg)](https://phpackages.com/packages/pondersource-billing-api)
```

###  Alternatives

[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[saloonphp/saloon

Build beautiful API integrations and SDKs with Saloon

2.4k9.6M468](/packages/saloonphp-saloon)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69333.0M114](/packages/algolia-algoliasearch-client-php)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[j0k3r/graby

Graby helps you extract article content from web pages

384349.6k2](/packages/j0k3r-graby)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
