- commit
- 054d684
- parent
- a934d17
- author
- Eric Bower
- date
- 2024-05-15 02:19:07 +0000 UTC
chore: url shortener for payment processor checkout url
2 files changed,
+20,
-2
+17,
-0
1@@ -515,6 +515,22 @@ func paymentWebhookHandler(secret string) func(http.ResponseWriter, *http.Reques
2 }
3 }
4
5+// URL shortener for out pico+ URL
6+func checkoutHandler(w http.ResponseWriter, r *http.Request) {
7+ username, err := url.PathUnescape(getField(r, 0))
8+ if err != nil {
9+ w.WriteHeader(http.StatusUnprocessableEntity)
10+ return
11+ }
12+ link := "https://checkout.pico.sh/buy/73c26cf9-3fac-44c3-b744-298b3032a96b"
13+ url := fmt.Sprintf(
14+ "%s?discount=0&checkout[custom][username]=%s",
15+ link,
16+ username,
17+ )
18+ http.Redirect(w, r, url, http.StatusMovedPermanently)
19+}
20+
21 func createMainRoutes() []shared.Route {
22 fileServer := http.FileServer(http.Dir("auth/public"))
23 secret := os.Getenv("PICO_SECRET_WEBHOOK")
24@@ -523,6 +539,7 @@ func createMainRoutes() []shared.Route {
25 }
26
27 routes := []shared.Route{
28+ shared.NewRoute("GET", "/checkout/(.+)", checkoutHandler),
29 shared.NewRoute("GET", "/.well-known/oauth-authorization-server", wellKnownHandler),
30 shared.NewRoute("POST", "/introspect", introspectHandler),
31 shared.NewRoute("GET", "/authorize", authorizeHandler),
+3,
-2
1@@ -2,6 +2,7 @@ package plus
2
3 import (
4 "fmt"
5+ "net/url"
6
7 "github.com/charmbracelet/bubbles/viewport"
8 tea "github.com/charmbracelet/bubbletea"
9@@ -12,8 +13,8 @@ import (
10 )
11
12 func PlusView(username string) string {
13- paymentLink := "https://checkout.pico.sh/buy/73c26cf9-3fac-44c3-b744-298b3032a96b?discount=0"
14- url := fmt.Sprintf("%s&checkout[custom][username]=%s", paymentLink, username)
15+ paymentLink := "https://auth.pico.sh/checkout"
16+ url := fmt.Sprintf("%s/%s", paymentLink, url.QueryEscape(username))
17 md := fmt.Sprintf(`# pico+
18
19 Signup to get premium access