Macropay is the merchant of record on every one of these purchases. We collect and remit sales tax and VAT worldwide, appear as the seller on the customer’s statement, and absorb PCI and chargeback handling — so the only thing you wire up here is the credit grant itself.
Two ways to grant credits
These are billing primitives, not just sign-up perks. If you’re metering an AI product or agent, the same prepaid balance covers token usage billed through the AI proxy — drop in a block of credits at purchase, then let real consumption draw it down.
Option A — the Meter Credits benefit (no code)
A Meter Credits benefit attaches to a product and grants a fixed number of credits once, automatically, the first time someone buys. No handler, no signature verification, no idempotency bookkeeping.1
Create a meter
Set up a meter with Sum aggregation to track the units your product consumes (requests, tokens, GB-hours — whatever you bill on).
2
Create the Meter Credits benefit
Add a Meter Credits benefit and set the number of credits to hand out — say, 500 units for a launch promo.
3
Build the product and attach it
Under Products → Catalogue → New Product, give it a name, choose Recurring (or one-time), and set the price —
$0 works for a free starter tier, or any amount you like. Click Add Additional Price to attach your meter and set the per-unit overage cost. Then scroll to Automated Benefits and toggle on your Meter Credits benefit.4
Save
Click Create Product. Every new purchase now lands with its credit balance pre-loaded.
Option B — webhooks + the Events API (full control)
When the grant logic lives in your code — variable amounts, referral bonuses, monthly top-ups, or backfilling customers who already signed up — listen for the purchase event and write the credit yourself.How crediting works under the hood
A meter on Sum aggregation simply adds up the values of the events you send it. Usage events carry positive values; a credit is just a negative event. Ingest-500 and the customer’s balance drops to -500, which means “500 units in the bank.”
Because the balance is a running sum, a negative number is good — it’s stored credit. The balance crosses zero into positive territory only once consumption outruns the granted credits, at which point your metered price bills the overage.
What you’ll need
- A meter on Sum aggregation, with a product attached
- A webhook endpoint subscribed to
order.paid - An organization access token for the Events API
1
Create the meter
In the dashboard go to Products → Meters → Create Meter. Name it (e.g.
image_generations), add a filter that matches your usage events (such as name equals image_generation), and choose Sum over the property you bill on (e.g. units). Note the meter name — you’ll reference it when ingesting.2
Create the product
Build the product as in Option A, but skip the Meter Credits benefit — your handler does the granting instead.
3
Wire up the webhook
Follow the webhook endpoints guide, subscribe to
order.paid (fired on every completed purchase), and store the secrets:Terminal
The handler
Verify the signature, confirm it’s the right product, then ingest one negative event. Macropay signs webhooks with the Standard Webhooks scheme, so any compliant library validates them.app/api/webhook/macropay/route.ts
Don’t double-grant
order.paid can be redelivered, and webhook handlers should be idempotent anyway. Key off the order ID and record each grant before you return a success response.
Confirm it worked
1
Run it in the sandbox
Exercise the whole flow in the sandbox so no real money or production data is touched.
2
Make a test purchase
Open a checkout session and complete it as a customer would.
3
Confirm delivery
Check your logs for the
order.paid event reaching your handler.4
Read the balance back
Pull the customer’s meter with the Customer Meters API: