PHPackages                             brianhenryie/bh-php-bitcoinpostageinfo - 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. brianhenryie/bh-php-bitcoinpostageinfo

ActiveLibrary

brianhenryie/bh-php-bitcoinpostageinfo
======================================

API for BitcoinPostage.info

216PHP

Since Dec 5Pushed 2y ago1 watchersCompare

[ Source](https://github.com/BrianHenryIE/bh-php-bitcoinpostageinfo)[ Packagist](https://packagist.org/packages/brianhenryie/bh-php-bitcoinpostageinfo)[ RSS](/packages/brianhenryie-bh-php-bitcoinpostageinfo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

![PHP 8.1](https://camo.githubusercontent.com/1c708345a94c698fd596459da39a9535062cfa1162a57a8ae4e3cdd54e00a25d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312d3838393242462e737667) [![PHPCS PSR-12](https://camo.githubusercontent.com/56b8d0e30cdddaac2db778a2ac2ecd4339ba90ee5ee2f0e416977b514d2cb661/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50485043532d50535225453225383025393331322d3232363134362e737667)](https://www.php-fig.org/psr/psr-12/) [![PHPUnit ](.github/coverage.svg)](https://brianhenryie.github.io/bh-php-bitcoinpostageinfo/) [![PHPStan ](.github/phpstan.svg)](https://phpstan.org/)

BitcoinPostage.info PHP API
===========================

[](#bitcoinpostageinfo-php-api)

A thin PHP wrapper for [BitcoinPostage.info](http://bitcoinpostage.info/) – a website/API which sells USPS, UPS and FedEx postage and accepts Bitcoin and Monero for payment.

```
composer require brianhenryie/bh-php-bitcoinpostageinfo
```

See:

- [API Documentation](https://btcpostage.com/api-documentation) (shows example cURL requests for each endpoint)
- [Register](https://bitcoinpostage.info/register)
- [Create an API key](https://bitcoinpostage.info/myaccount/api-access)

Use
---

[](#use)

Create an instance of the API class with a PSR HTTP implementation. [Guzzle](https://github.com/guzzle/guzzle) is the most popular.

```
$httpFactory = new \GuzzleHttp\Psr7\HttpFactory();
$client      = new \GuzzleHttp\Client();

$bitcoinPostageInfo = new \BrianHenryIE\BitcoinPostageInfo\BitcoinPostageInfoAPI(
    requestFactory: $httpFactory,
    streamFactory: $httpFactory,
    client: $client,
);
```

All API calls require authentication:

```
$credentials = new \BrianHenryIE\BitcoinPostageInfo\Model\Request\Credentials(
    key: $_ENV[ 'BITCOINPOSTAGEINFO_API_KEY' ],
    secret: $_ENV[ 'BITCOINPOSTAGEINFO_API_SECRET' ],
);
```

Add credit to your account:

```
$chargeCreditsRequest = new \BrianHenryIE\BitcoinPostageInfo\Model\Request\ChargeCreditsRequest(
    credentials: $credentials,
    amount: '10.00'
);

/** @var \BrianHenryIE\BitcoinPostageInfo\Model\Response\ChargeCredits $chargeCreditsResponse */
$chargeCreditsResponse = $api->chargeCredits($chargeCreditsRequest);

$bitcoinAddressHref = 'bitcoin:' . $chargeCreditsResponse->address . '?amount=' . $chargeCreditsResponse->amount;
$bitcoinQrCode = 'https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=' . $bitcoinAddressHref . '&choe=UTF-8';

printf(
    'Pay BitcoinPostage.info for $%s credits.',
    $bitcoinAddressHref,
    $bitcoinQrCode,
    $chargeCreditsResponse->credits
);
```

Check your account balance:

```
$credits = $api->getCredits($credentials);

echo $credits->credits;
```

You'll need your from and to addresses and the package dimensions to get rates and to purchase labels:

```
$fromAddress = new \BrianHenryIE\BitcoinPostageInfo\Model\Address(
    name: 'Brian Henry',
    street: '800 N St.',
    street2: null,
    city: 'Sacramento',
    state: 'CA',
    zip: '95814',
    country: 'US',
    phone: null,
);
$toAddress = new \BrianHenryIE\BitcoinPostageInfo\Model\Address(
    name: 'Brian Henry',
    street: '1 Palace St',
    street2: 'Apartment 3',
    city: 'Dublin',
    state: 'Dublin',
    zip: 'D02 XR57',
    country: 'IE',
    phone: null,
);
$dimensions = new \BrianHenryIE\BitcoinPostageInfo\Model\Dimensions(
    weightLbs: 0,
    weightOz: 1.5,
    heightInches: 1.0,
    widthInches: 2.0,
    depthInches: 3.0,
);
```

Query for rates:

```
$ratesRequest = new \BrianHenryIE\BitcoinPostageInfo\Model\Request\GetRatesRequest(
    credentials: $credentials,
    fromAddress: $fromAddress,
    toAddress: $toAddress,
    service: new \BrianHenryIE\BitcoinPostageInfo\Model\Service(
        packageType: UspsPackage::FLAT_RATE_ENVELOPE,
    ),
    dimensions: $dimensions,
);

/** @var \BrianHenryIE\BitcoinPostageInfo\Model\Response\Rate[] $ratesResponse */
$ratesResponse = $api->getRates($ratesRequest);

$cheapest_rate = array_reduce(
    $ratesResponse,
    function (\BrianHenryIE\BitcoinPostageInfo\Model\Response\Rate $carry, \BrianHenryIE\BitcoinPostageInfo\Model\Response\Rate $rate) {
        return is_null($carry) || $rate->rate < $carry->rate ? $rate : $carry;
    },
    null
);
echo "{$cheapest_rate->currency} {$cheapest_rate->rate}";
echo $cheapest_rate->service;
```

International shipments require customs information:

```
$customs = new Customs(
    type: CustomsContentsType::GIFT,
    signer: 'Brian Henry',
    customs: [
         new \BrianHenryIE\BitcoinPostageInfo\Model\CustomsItem(
             quantity: 1,
             description: 'T-shirt',
             totalValue: '10.00',
             totalWeightOz: 20.5,
             countryCodeOfOrigin: 'US',
             hsTariffNumber: '610910',
         )
    ],
);
```

Purchase a label:

```
$createPurchaseRequest = new \BrianHenryIE\BitcoinPostageInfo\Model\Request\CreatePurchaseRequest(
    credentials: $credentials,
    fromAddress: $fromAddress,
    toAddress: $toAddress,
    service: new \BrianHenryIE\BitcoinPostageInfo\Model\Service(
        packageType: UspsPackage::FLAT_RATE_ENVELOPE,
        service: 'usps_intl_first_class_package',
    ),
    dimensions: $dimensions,
    customs: $customs,
    testMode: true,
);

/** @var \BrianHenryIE\BitcoinPostageInfo\Model\Response\Purchase $purchaseResponse */
$purchaseResponse = $api->createPurchase($createPurchaseRequest);

/** @var \BrianHenryIE\BitcoinPostageInfo\Model\Response\PurchaseItem $purchasedLabel */
$purchasedLabel = $purchaseResponse->items[0];

echo $purchasedLabel->price;
echo $purchasedLabel->filename;
echo $purchasedLabel->trackingNo;
```

Notes
-----

[](#notes)

- Currency amounts are strings and other numbers are floats, except for `weightLbs` which is an int
- A good PHP library for generating QR codes is [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode) (for the `::chargeCredits()` payment address)
- [Guzzle](https://github.com/guzzle/guzzle) is a great PSR HTTP library but consider [Art4/WP-Requests-PSR18-Adapter](https://github.com/Art4/WP-Requests-PSR18-Adapter) if you are developing for WordPress
- USPS will send you free flat rate envelopes and boxes. [Order them online](https://store.usps.com/store/results/shipping-supplies/_/N-7d0v8v) or pick them up at your local post office.

Contribute
----------

[](#contribute)

PhpDoc is incomplete. I'm not sure the correct way to document PHP 8.0 constructor property promotion properties.

What's a better coding standard to use?

No testing has been done for UPS / FedEx.

Acknowledgements
----------------

[](#acknowledgements)

The [BitcoinPostage.info support](https://btcpostage.com/faq#contact) was very quick to reply to emails and update documentation as requested.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3541a510f89dedd04f0e7103201e411f6f22685a13e941b3384d97d4c7d32b09?d=identicon)[BrianHenryIE](/maintainers/BrianHenryIE)

---

Top Contributors

[![BrianHenryIE](https://avatars.githubusercontent.com/u/4720401?v=4)](https://github.com/BrianHenryIE "BrianHenryIE (1 commits)")

---

Tags

bitcoinmoneroshipping-apishipping-labelsusps

### Embed Badge

![Health badge](/badges/brianhenryie-bh-php-bitcoinpostageinfo/health.svg)

```
[![Health](https://phpackages.com/badges/brianhenryie-bh-php-bitcoinpostageinfo/health.svg)](https://phpackages.com/packages/brianhenryie-bh-php-bitcoinpostageinfo)
```

PHPackages © 2026

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