Billing API
Read your monthly billing summary and outstanding invoices via the SDK.
HivePay charges merchants on a monthly cycle — see Billing & Pricing for the model. The SDK exposes one method merchants typically need: billing.getMine().
Get Your Billing Summary
Returns the current-month volume, the projected invoice at the prevailing tier, and the full history of outstanding and paid invoices.
import { HivePay } from '@hivepay/client';
const hivepay = new HivePay({ apiKey: process.env.HIVEPAY_API_KEY! });
const summary = await hivepay.billing.getMine();
use HivePay\HivePay;
$hivepay = new HivePay(['apiKey' => getenv('HIVEPAY_API_KEY')]);
$summary = $hivepay->billing->getMine();
curl https://hivepay.me/api/public/billing/me \
-H "Authorization: Bearer sk_live_xxx"
Response Shape
BillingPeriod
FeeTier
Pay an Outstanding Invoice
Outstanding invoices each include an invoicePaymentUrl — share or open it to pay in HBD via a regular HivePay checkout.
const summary = await hivepay.billing.getMine();
for (const invoice of summary.outstandingInvoices) {
if (invoice.invoicePaymentUrl) {
console.log(`Pay $${invoice.invoiceAmountCents / 100} at ${invoice.invoicePaymentUrl}`);
}
}
$summary = $hivepay->billing->getMine();
foreach ($summary['outstandingInvoices'] as $invoice) {
if ($invoice['invoicePaymentUrl']) {
echo 'Pay $' . ($invoice['invoiceAmountCents'] / 100)
. " at {$invoice['invoicePaymentUrl']}\n";
}
}
Display the Active Tier Schedule
The schedule shipped with HivePay is configurable per deployment. Read summary.feeTiers rather than hard-coding rates so your app stays in sync if rates change.
const { feeTiers, currentMonth } = await hivepay.billing.getMine();
const sorted = [...feeTiers].sort((a, b) => a.minVolumeCents - b.minVolumeCents);
const currentTier = sorted.find(t =>
currentMonth.totalVolumeCents >= t.minVolumeCents
&& (t.maxVolumeCents === null || currentMonth.totalVolumeCents <= t.maxVolumeCents)
);
if (currentTier) {
console.log(`You are in the ${currentTier.percentFee}% tier this month.`);
}
Polling for Invoice Payment
After redirecting yourself to an invoicePaymentUrl, you can poll getMine() to confirm settlement — the period status flips from invoiced to paid as soon as the invoice transaction is confirmed on Hive.
import { HivePay } from '@hivepay/client';
const hivepay = new HivePay({ apiKey: process.env.HIVEPAY_API_KEY! });
async function waitForInvoicePaid (invoiceId: string, timeoutMs = 5 * 60 * 1000) {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const summary = await hivepay.billing.getMine();
const paid = summary.paidInvoices.find(i => i.id === invoiceId);
if (paid) return paid;
await new Promise(r => setTimeout(r, 5000));
}
throw new Error('Invoice not paid within timeout');
}
Error Handling
billing.getMine() requires a valid merchant API key. Common errors:
import { HivePay, isHivePayError } from '@hivepay/client';
try {
const summary = await hivepay.billing.getMine();
// ...
} catch (err) {
if (isHivePayError(err) && err.isAuthError()) {
console.error('Check your API key');
} else {
throw err;
}
}