Skip to content

Order

An Order represents a buyer's intent to purchase from a Store Page. It contains a derived Bitcoin address, an expiration window, and tracks payment status through its lifecycle.

Properties

PropertyTypeDescription
IdintPrimary key
BuyerIdint?FK → AppUser (null for anonymous orders)
SellerIdintFK → AppUser (the store page owner)
StorePageIdintFK → StorePage
PaymentDestinationIdintFK → PaymentDestination
DerivedPaymentAddressstringThe unique Bitcoin address for this order
AccessTokenstringBearer token for accessing purchased content
DerivationIndexintIndex used to derive the payment address
NetAmountSatslongPrice before VAT
VatRatedecimalVAT percentage applied
VatAmountSatslongVAT amount in satoshis
TotalAmountSatslongTotal amount the buyer must pay
IsVatExemptboolWhether the buyer has a valid VAT ID
BuyerVatIdstring?Buyer's VAT identification number
DisplayAmountBtcstringHuman-readable BTC amount
FiatReferenceAmountUsddecimal?USD equivalent at time of order
ExpiresAtUtcDateTime4 hours from creation
StatusOrderStatusCurrent payment status
IsAnonymousboolWhether this is an anonymous purchase
AnonymousEmailstring?Email for anonymous buyer notifications
ClaimCodestring?Code for anonymous buyers to claim the game
IsLightningPaymentboolWhether this is a Lightning payment
InvoiceEnabledboolWhether an invoice should be generated

Order Statuses

StatusDescription
OpenCreated, awaiting payment
PaidPendingConfirmationPayment detected on-chain, awaiting confirmations
FulfilledPayment confirmed, games delivered to buyer
Expired4-hour window elapsed without payment
CancelledBuyer cancelled before paying
ReturnedOrder reversed (refund)
RevokedAccess revoked by seller/admin

Payment Flow

Order Created (Open)

  ├─ On-chain: PaymentDetector polls blockchain
  │   → PaidPendingConfirmation (detected)
  │   → Fulfilled (confirmed)

  ├─ Lightning: Webhook receives settlement
  │   → Fulfilled (instant)

  ├─ 4 hours elapse → Expired

  └─ Buyer cancels → Cancelled

Address Derivation

Each order gets a unique Bitcoin address derived from the seller's xpub/descriptor:

  1. PaymentAddressAllocator atomically increments DerivationIndex on the seller's PaymentDestination.
  2. NBitcoinPaymentAddressDerivationService derives the address using NBitcoin.
  3. The address is registered with the Payment Detector for monitoring.

Relationships

Order (N) ──── (1) AppUser   (buyer, optional)
Order (N) ──── (1) AppUser   (seller)
Order (N) ──── (1) StorePage
Order (N) ──── (1) PaymentDestination
Order (1) ──── (N) OrderItem

Sell indie games for Bitcoin.