THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

How to Restore a Bitcoin Website Checkout Session

permalink THAMER
#bitcoin#payments#python#website

A checkout must survive browser refreshes and application restarts without issuing a new invoice on every visit. Store the internal watch ID and bind it to the authenticated customer and order.

Implementation approach

The WAB WATCH CREATE endpoint accepts expected_sat and ttl_sec and returns a watch_id. Store that identifier after successful creation. This SQLite example restores local metadata only, not engine state. An ambiguous creation timeout requires reconciliation rather than blind retries. Use a persistent database path in deployment and never treat expiry as proof that funds did not arrive.

Source code

Python · 17 lines
1import sqlite3
2
3def init(db):
4    db.execute('CREATE TABLE IF NOT EXISTS checkout (order_id TEXT PRIMARY KEY, owner TEXT NOT NULL, watch_id TEXT NOT NULL UNIQUE, address TEXT NOT NULL)')
5
6def save(db, order_id, owner, watch_id, address):
7    with db:
8        db.execute('INSERT INTO checkout VALUES (?,?,?,?)',(order_id,owner,watch_id,address))
9
10def restore(db, order_id, authenticated_owner):
11    return db.execute('SELECT watch_id,address FROM checkout WHERE order_id=? AND owner=?',(order_id,authenticated_owner)).fetchone()
12
13if __name__=='__main__':
14    with sqlite3.connect(':memory:') as db:
15        init(db); save(db,'o1','alice','w1','fixture')
16        assert restore(db,'o1','alice')==('w1','fixture')
17        assert restore(db,'o1','bob') is None

Local validation

Run python3 stage22-checkout-recovery.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

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects