How to Verify Bitcoin Website Payments Before Delivery
Never accept a browser callback or a transaction ID alone as proof of payment. Match trusted chain observations against the expected output and confirmation policy.
Implementation approach
Normalize verified observations from your backend before calling this function. The script does not fetch blockchain data. A reorganization can invalidate a previously accepted observation; production systems must reconcile and hold irreversible delivery until their risk threshold is met.
Source code
1def paid(invoice, output):
2 return (output.get('canonical') is True and output.get('network')==invoice['network'] and output.get('address')==invoice['address'] and type(output.get('sats')) is int and output['sats']>=invoice['sats'] and type(output.get('confirmations')) is int and output['confirmations']>=invoice['min_confirmations'])
3
4if __name__=='__main__':
5 invoice=dict(network='test',address='fixture',sats=5000,min_confirmations=2)
6 output=dict(network='test',address='fixture',sats=5000,confirmations=2,canonical=True)
7 assert paid(invoice,output)
8 assert not paid(invoice,dict(output,canonical=False))
9 assert not paid(invoice,dict(output,sats=4999))Local validation
Run python3 stage22-payment-verification.py. The assertions use synthetic fixtures, not real Bitcoin addresses or payments. This is a reference example, not a complete production checkout. No SEND operation is included.
Related documentation
https://thamer.org/api
https://thamer.org/learn/bitcoin-ai-agents-advanced-research-guide
