Premium checkout: CoinPay hosted session with URL + QR in the SSH terminal (#156)
Some checks failed
CI / build (push) Has been cancelled
deploy / deploy (push) Has been cancelled
test / test (push) Has been cancelled

join@ now creates a CoinPay checkout session (POST /checkout/sessions) instead
of a single-chain ETH payment: the buyer picks any coin the business accepts or
PayPal. The session URL and a half-block QR code of it are shown in the
terminal, and the session is polled (GET /checkout/sessions/:id) until paid,
Enter, disconnect or expiry. property=bbs.profullstack.com, account_id=handle,
customer_email=the verified email (asked for if none is stored), metadata
carries pubkey fingerprint, user id and the HMAC ref. Legacy payment ids still
verify.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-10-21 05:54:39 -07:00 • committed by GitHub
parent 8fe601b296
commit 0499cb60f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 333 additions and 181 deletions

View file

@ -1104,48 +1104,93 @@ func (a *app) offerPremium(s ssh.Session, in *bufio.Reader, u *store.User) {
}, "\n"))
// Explicit opt-in. Anything but yes leaves with no payment created.
wish.Print(s, "\n Become a Founding member now? Type \"yes\" for a payment address [no]: ")
wish.Print(s, "\n Become a Founding member now? Type \"yes\" for a checkout link [no]: ")
line, err := readLine(s, in)
if err != nil || !isYes(line) {
wish.Print(s, "\n No problem — you're a free member. Want it later? Re-run: ssh join@"+a.host+"\n\n")
wish.Print(s, "\n No problem, you're a free member. Want it later? Re-run: ssh join@"+a.host+"\n\n")
return
}
ref := payments.PremiumReference(u.PubKeyFP)
c, ok, err := payments.CreatePremiumCharge(ref)
if !ok || err != nil {
// CoinPay needs a receipt email. join@ verifies one first, but ask if a
// legacy account has none on file.
email := strings.TrimSpace(u.Email)
for tries := 0; !validEmail(email) && tries < 3; tries++ {
wish.Print(s, "\n Email for your receipt: ")
line, err := readLine(s, in)
if err != nil {
log.Error("create premium charge", "err", err)
return
}
wish.Print(s, "\n Payment is temporarily unavailable — please try again shortly.\n\n")
email = strings.TrimSpace(line)
}
if !validEmail(email) {
wish.Print(s, "\n A valid email is needed for checkout. Re-run: ssh join@"+a.host+"\n\n")
return
}
// Remember the payment id so a later connect can confirm settlement.
if err := a.st.SetPremiumPayment(u.ID, c.ID); err != nil {
log.Error("store premium payment id", "err", err)
}
amount := "$" + payments.PremiumAmount() + " " + payments.PremiumCurrency()
if c.CryptoAmount != "" {
cur := c.Currency
if cur == "" {
cur = strings.ToUpper(payments.PremiumBlockchain())
ses, ok, err := payments.CreatePremiumSession(payments.Buyer{
AccountID: u.Name,
Email: email,
PubKeyFP: u.PubKeyFP,
UserID: u.ID,
}, "https://"+a.host+"/~"+u.Name)
if !ok || err != nil {
if err != nil {
log.Error("create premium checkout session", "err", err)
}
amount += " (≈ " + c.CryptoAmount + " " + cur + ")"
wish.Print(s, "\n Payment is temporarily unavailable, please try again shortly.\n\n")
return
}
// Remember the session id so a later connect can confirm settlement.
if err := a.st.SetPremiumPayment(u.ID, ses.ID); err != nil {
log.Error("store premium checkout session id", "err", err)
}
lines := []string{
"",
" amount " + amount,
" send to " + c.Address,
}
if c.QR != "" {
lines = append(lines, " qr "+c.QR)
}
lines = append(lines,
" amount $" + payments.PremiumAmount() + " " + payments.PremiumCurrency() + " (pay with any major coin or PayPal)",
" checkout " + ses.URL,
"",
" Perks unlock once payment confirms — then re-run: ssh join@"+a.host,
" Open the link, or scan it with your phone:",
"",
)
}
wish.Println(s, strings.Join(lines, "\n"))
if q := payments.TerminalQR(ses.URL, " "); q != "" {
wish.Print(s, strings.ReplaceAll(q, "\n", "\r\n"))
}
wish.Print(s, "\r\n Waiting for payment here (press Enter to leave; perks also unlock on your next connect)...\r\n")
if a.waitForPremium(s, in, u, ses.ID) {
wish.Println(s, "\n Payment received. Welcome, Founding member!")
a.showPremiumWelcome(s, *u)
return
}
wish.Print(s, "\n Once payment confirms, re-run: ssh join@"+a.host+"\n\n")
}
// waitForPremium polls the checkout session until it is paid, the member
// presses Enter, the session disconnects, or the session would have expired.
func (a *app) waitForPremium(s ssh.Session, in *bufio.Reader, u *store.User, sessionID string) bool {
left := make(chan struct{})
go func() {
_, _ = readLine(s, in)
close(left)
}()
tick := time.NewTicker(5 * time.Second)
defer tick.Stop()
deadline := time.After(60 * time.Minute)
for {
select {
case <-left:
return false
case <-s.Context().Done():
return false
case <-deadline:
return false
case <-tick.C:
if a.ensurePremium(u) {
return true
}
}
}
}
// isYes reports whether a prompt line is an affirmative opt-in.