{"id":15146880,"url":"https://github.com/brianhenryie/bh-php-bitcoinpostageinfo","last_synced_at":"2026-01-28T01:02:52.566Z","repository":{"id":210847742,"uuid":"727588499","full_name":"BrianHenryIE/bh-php-bitcoinpostageinfo","owner":"BrianHenryIE","description":"Buy USPS, UPS and FedEx postage with Bitcoin and Monero.","archived":false,"fork":false,"pushed_at":"2023-12-05T06:59:53.000Z","size":41,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T05:17:57.662Z","etag":null,"topics":["bitcoin","monero","shipping-api","shipping-labels","usps"],"latest_commit_sha":null,"homepage":"https://bitcoinpostage.info","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrianHenryIE.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-12-05T06:59:51.000Z","updated_at":"2025-01-30T19:33:37.000Z","dependencies_parsed_at":"2023-12-05T07:50:20.695Z","dependency_job_id":"9ad1c82b-a655-4d22-9075-8bb861b9a191","html_url":"https://github.com/BrianHenryIE/bh-php-bitcoinpostageinfo","commit_stats":null,"previous_names":["brianhenryie/bh-php-bitcoinpostageinfo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHenryIE%2Fbh-php-bitcoinpostageinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHenryIE%2Fbh-php-bitcoinpostageinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHenryIE%2Fbh-php-bitcoinpostageinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrianHenryIE%2Fbh-php-bitcoinpostageinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrianHenryIE","download_url":"https://codeload.github.com/BrianHenryIE/bh-php-bitcoinpostageinfo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247563934,"owners_count":20958971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","monero","shipping-api","shipping-labels","usps"],"created_at":"2024-09-26T12:20:22.138Z","updated_at":"2026-01-28T01:02:51.748Z","avatar_url":"https://github.com/BrianHenryIE.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PHP 8.1](https://img.shields.io/badge/PHP-8.1-8892BF.svg)]() [![PHPCS PSR-12](https://img.shields.io/badge/PHPCS-PSR–12-226146.svg)](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/)\n\n# BitcoinPostage.info PHP API\n\nA 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.\n\n```bash\ncomposer require brianhenryie/bh-php-bitcoinpostageinfo\n```\nSee:\n\n* [API Documentation](https://btcpostage.com/api-documentation) (shows example cURL requests for each endpoint)\n* [Register](https://bitcoinpostage.info/register)\n* [Create an API key](https://bitcoinpostage.info/myaccount/api-access)\n\n\n## Use\n\nCreate an instance of the API class with a PSR HTTP implementation. [Guzzle](https://github.com/guzzle/guzzle) is the most popular.\n```php\n$httpFactory = new \\GuzzleHttp\\Psr7\\HttpFactory();\n$client      = new \\GuzzleHttp\\Client();\n\n$bitcoinPostageInfo = new \\BrianHenryIE\\BitcoinPostageInfo\\BitcoinPostageInfoAPI(\n    requestFactory: $httpFactory,\n    streamFactory: $httpFactory,\n    client: $client,\n);\n```\n\nAll API calls require authentication:\n```php\n$credentials = new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Request\\Credentials(\n    key: $_ENV[ 'BITCOINPOSTAGEINFO_API_KEY' ],\n    secret: $_ENV[ 'BITCOINPOSTAGEINFO_API_SECRET' ],\n);\n```\n\nAdd credit to your account:\n```php\n$chargeCreditsRequest = new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Request\\ChargeCreditsRequest(\n    credentials: $credentials,\n    amount: '10.00'\n);\n\n/** @var \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Response\\ChargeCredits $chargeCreditsResponse */\n$chargeCreditsResponse = $api-\u003echargeCredits($chargeCreditsRequest);\n\n$bitcoinAddressHref = 'bitcoin:' . $chargeCreditsResponse-\u003eaddress . '?amount=' . $chargeCreditsResponse-\u003eamount;\n$bitcoinQrCode = 'https://chart.googleapis.com/chart?chs=300x300\u0026cht=qr\u0026chl=' . $bitcoinAddressHref . '\u0026choe=UTF-8';\n\nprintf(\n    '\u003ca href=\"%s\" target=\"_blank\"\u003e\u003cimg src=\"%s\"/\u003e\u003cbr/\u003ePay BitcoinPostage.info for $%s credits.\u003c/a\u003e',\n    $bitcoinAddressHref,\n    $bitcoinQrCode,\n    $chargeCreditsResponse-\u003ecredits\n);\n```\n\nCheck your account balance:\n```php\n$credits = $api-\u003egetCredits($credentials);\n\necho $credits-\u003ecredits;\n```\n\nYou'll need your from and to addresses and the package dimensions to get rates and to purchase labels:\n\n```php\n$fromAddress = new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Address(\n    name: 'Brian Henry',\n    street: '800 N St.',\n    street2: null,\n    city: 'Sacramento',\n    state: 'CA',\n    zip: '95814',\n    country: 'US',\n    phone: null,\n);\n$toAddress = new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Address(\n    name: 'Brian Henry',\n    street: '1 Palace St',\n    street2: 'Apartment 3',\n    city: 'Dublin',\n    state: 'Dublin',\n    zip: 'D02 XR57',\n    country: 'IE',\n    phone: null,\n);\n$dimensions = new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Dimensions(\n    weightLbs: 0,\n    weightOz: 1.5,\n    heightInches: 1.0,\n    widthInches: 2.0,\n    depthInches: 3.0,\n);\n```\n\nQuery for rates:\n```php\n$ratesRequest = new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Request\\GetRatesRequest(\n    credentials: $credentials,\n    fromAddress: $fromAddress,\n    toAddress: $toAddress,\n    service: new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Service(\n        packageType: UspsPackage::FLAT_RATE_ENVELOPE,\n    ),\n    dimensions: $dimensions,\n);\n\n/** @var \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Response\\Rate[] $ratesResponse */\n$ratesResponse = $api-\u003egetRates($ratesRequest);\n\n$cheapest_rate = array_reduce(\n    $ratesResponse,\n    function (\\BrianHenryIE\\BitcoinPostageInfo\\Model\\Response\\Rate $carry, \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Response\\Rate $rate) {\n        return is_null($carry) || $rate-\u003erate \u003c $carry-\u003erate ? $rate : $carry;\n    },\n    null\n);\necho \"{$cheapest_rate-\u003ecurrency} {$cheapest_rate-\u003erate}\";\necho $cheapest_rate-\u003eservice;\n```\n\nInternational shipments require customs information:\n```php\n$customs = new Customs(\n    type: CustomsContentsType::GIFT,\n    signer: 'Brian Henry',\n    customs: [\n         new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\CustomsItem(\n             quantity: 1,\n             description: 'T-shirt',\n             totalValue: '10.00',\n             totalWeightOz: 20.5,\n             countryCodeOfOrigin: 'US',\n             hsTariffNumber: '610910',\n         )\n    ],\n);\n```\n\nPurchase a label:\n```php\n$createPurchaseRequest = new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Request\\CreatePurchaseRequest(\n    credentials: $credentials,\n    fromAddress: $fromAddress,\n    toAddress: $toAddress,\n    service: new \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Service(\n        packageType: UspsPackage::FLAT_RATE_ENVELOPE,\n        service: 'usps_intl_first_class_package',\n    ),\n    dimensions: $dimensions,\n    customs: $customs,\n    testMode: true,\n);\n\n/** @var \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Response\\Purchase $purchaseResponse */\n$purchaseResponse = $api-\u003ecreatePurchase($createPurchaseRequest);\n\n/** @var \\BrianHenryIE\\BitcoinPostageInfo\\Model\\Response\\PurchaseItem $purchasedLabel */\n$purchasedLabel = $purchaseResponse-\u003eitems[0];\n\necho $purchasedLabel-\u003eprice;\necho $purchasedLabel-\u003efilename;\necho $purchasedLabel-\u003etrackingNo;\n```\n\n## Notes\n\n* Currency amounts are strings and other numbers are floats, except for `weightLbs` which is an int\n* A good PHP library for generating QR codes is [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode) (for the `::chargeCredits()` payment address) \n* [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\n* 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.\n\n## Contribute\n\nPhpDoc is incomplete. I'm not sure the correct way to document PHP 8.0 constructor property promotion properties.\n\nWhat's a better coding standard to use?\n\nNo testing has been done for UPS / FedEx.\n\n## Acknowledgements\n\nThe [BitcoinPostage.info support](https://btcpostage.com/faq#contact) was very quick to reply to emails and update documentation as requested.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianhenryie%2Fbh-php-bitcoinpostageinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianhenryie%2Fbh-php-bitcoinpostageinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianhenryie%2Fbh-php-bitcoinpostageinfo/lists"}