Files
terminalShop-old/pkg/tui/qrfefe/qr.go
marcusDenslow 062242e346 feat: add browser-based card collection via Stripe Checkout Session
adds a /pay/{token} redirect endpoint that generates a short URL
pointing to a stripe checkout sessions in setup mode. The TUI shows a QR
code and URL on the payment page so users can add a card via the browser
instead of entering raw card data over SSH.

the checkout.session.completed webhook saves the card to the database.
the TUI polls GET /api/v1/cards every second and auto-proceeds to
confirmation once the new card is detected.

also adds a dev.sh startup script that runs all four required processes.
(SSH server, API server, Stripe CLI listener, ngrok) in a single
terminal
2026-04-08 01:03:43 +02:00

59 lines
1.2 KiB
Go

package qrfefe
import (
sgr "github.com/foize/go.sgr"
"rsc.io/qr"
)
var tops_bottoms = []rune{' ', '▀', '▄', '█'}
func Generate(size int, text string) (string, int, error) {
return generate(qr.L, text)
}
func generate(level qr.Level, text string) (string, int, error) {
code, err := qr.Encode(text, qr.Level(level))
if err != nil {
return "", 0, err
}
qrRunes := make([]rune, 0)
for y := 0; y < code.Size-1; y+= 2 {
qrRunes = append(qrRunes, []rune(sgr.FgWhite+sgr.BgBlack)...)
for x := 0; x < code.Size; x += 1 {
var num int8
if code.Black(x, y) { // top pixel black
num += 1
}
if code.Black(x, y+1) { // bottom pixel black
num += 2
}
qrRunes = append(qrRunes, tops_bottoms[num])
}
qrRunes = append(qrRunes, []rune(sgr.Reset)...)
qrRunes = append(qrRunes, '\n')
}
addWhiteRow(&qrRunes, code.Size+4)
return string(qrRunes), code.Size, nil
}
func addWhiteRow(qrRunes *[]rune, width int) {
if qrRunes == nil {
return
}
*qrRunes = append(*qrRunes, []rune(sgr.FgWhite+sgr.BgBlack)...)
for i := 1; i < width-3; i++ {
*qrRunes = append(*qrRunes, '▀')
}
*qrRunes = append(*qrRunes, []rune(sgr.Reset)...)
*qrRunes = append(*qrRunes, '\n')
}