On this page
Match the payment to the player
A transfer from a wallet carries no player name, so you match on the invoice instead. Put the player’s id into metadata when you create it and the webhook hands it back. Each invoice has its own payment address, so two players sending the same amount at the same second cannot be confused.
const invoice = await hisarpay.invoices.create({
price_usd: pack.priceUsd, // from your own price list, never from the browser
order_id: 'credit-' + purchase.id,
description: pack.name,
metadata: { player_id: player.id },
success_url: 'https://yourserver.example/store/thanks',
});- Store the id, not the display name. Names change, ids do not.
metadataholds up to 4 KB. - Save the purchase on your side first and take
order_idfrom it. A player who clicks twice gets the same invoice back. - Verify the player. A code shown in the game or a login beats a text box; credit sent to a misspelt name is hard to bring back.
Give credit on the paid event only
The payment page reacts as soon as a transfer is seen, but the invoice counts as paid after 20 block confirmations, about a minute later. There is no reason to hand out credit before that. The player waits a minute, and you never have to claw back a mistake.
| Event | What to do |
|---|---|
invoice.paid | Give the credit |
invoice.overpaid | Give it if you have not yet; settle the extra by hand |
invoice.partial | Wait; the rest can go to the same address |
invoice.expired | Close the purchase but keep it, a late payment may come |
A late payment can reopen an expired invoice, so invoice.paid after invoice.expired is normal. A visit to your success_url, on the other hand, proves nothing. Anyone can open that address.
A short webhook handler
This sketch checks the signature, ignores test events and grants credit once per invoice. grants.addOnce is yours to write: an insert into a table where the invoice id is unique. Work out the credit from price_amount, the dollar price of the invoice.
app.post('/webhooks/hisarpay', express.raw({ type: 'application/json' }), async (req, res) => {
let event;
try {
event = HisarPay.webhooks.constructEvent(req.body, req.headers['x-hisarpay-signature'], secret);
} catch (err) {
if (err instanceof SignatureVerificationError) return res.status(400).send(err.message);
throw err;
}
if (!event.livemode) return res.sendStatus(200); // test invoices give no credit
if (event.livemode && (event.type === 'invoice.paid' || event.type === 'invoice.overpaid')) {
const { id, metadata, price_amount } = event.data.invoice;
await grants.addOnce(id, metadata.player_id, price_amount); // invoice id is unique
}
res.sendStatus(200);
});The same event can arrive more than once, and one invoice can send invoice.paid and later invoice.overpaid. The unique invoice id makes both harmless. If the game server is down, queue the credit, answer 200 and apply it at the next login. PHP and Python versions are in our first invoice guide.
Open-amount links
To let players choose how much to buy, the simplest route is an amount box on your own store page and an invoice through the API. Without a page, use an open-amount payment link. Mind the trap: a payment through a link says nothing about the player by itself. That is fine for donations and means matching by hand for credit. Have the link ask for the player’s name, and make it required:
const link = await hisarpay.paymentLinks.create({
title: 'Server credit',
kind: 'open',
min_usd: '10.00',
max_usd: '200.00',
suggested_amounts: ['10.00', '25.00', '50.00'],
ask: { note: 'required', note_label: 'Player name' },
});
// webhook: the name the payer entered
const player = await players.byName(event.data.invoice.payer.note);What the payer entered is in payer.note of the invoice. Look the name up on your server in case of a typo; queue a payment that matches nobody and ask. A campaign link can have an end and a number of uses as well. The kinds of link are compared in our article on payment links.
Small amounts and the $10 minimum
The smallest invoice is $10, so a $3 item cannot be sold on its own. Sell at least $10 of credit and let the item cost credit. That also makes the 1 USDT network fee a smaller share. With the commission on you, USDT looks like this:
| Pack | Player sends | Reaches your balance |
|---|---|---|
| $10 | 11 USDT | 9.96 USDT |
| $15 | 16 USDT | 14.94 USDT |
| $25 | 26 USDT | 24.90 USDT |
| $50 | 51 USDT | 49.80 USDT |
TRX payments carry no network fee. Players who send from an exchange can end up slightly short because its fee came off the amount. A small underpayment tolerance in the dashboard keeps those out of your inbox.
Write the refund rules first
A final payment cannot be reversed, so spent credit is not clawed back by a dispute. Refunds are therefore your decision alone. Take the credit back in the game, then send a withdrawal to an address the player gives you in writing. Do not return it to the address it came from, which may belong to an exchange. The smallest withdrawal is worth $10 and costs 1 USDT or 1 TRX, so for small sums returning credit makes more sense than returning coins. More in our article on refunds.
Against abuse
- Let the server set the price. A store that trusts an amount from the browser will be fooled.
- No test key in production. Anyone who opens a test invoice can mark it paid.
- No credit for screenshots. Proof is an invoice shown as paid in your dashboard.
- Cap open purchases per player.
- Share links from official channels. For copied stores, see fake payment pages.
- Know about held payments. Now and then one is flagged in screening and reviewed; you see it in the dashboard and in an alert. How screening works.
Frequently asked questions
Does a player get credit for a short payment?
Are hundreds of small payments a day a problem?
Can I sell credit without a website?
What about players who are minors?
- #Game servers
- #Webhooks
- #Payment links
- #Credit
Try crypto payments in test mode
No setup or monthly fees. Experiment as much as you like in test mode and go live when you are ready.