diff --git a/main.go b/main.go index f16e50a..6e05907 100644 --- a/main.go +++ b/main.go @@ -54,6 +54,7 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) { var datetimestring = t.Format("20060102150405") var scales = getMyDevs(userName) var last_metrics []OneMetric + var checkout_session_id string if (r.URL.Path == "/scales.html") || (r.URL.Path == "/abos.html") { // wir holen noch die letzten Metriken @@ -63,16 +64,25 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) { } } + if (r.URL.Path == "/abos.html") { + // wir generieren die Stripe Session ID + checkout_session_id = GetStripeSessionID() + logit("Stripe Session ID: " + checkout_session_id) + + } + data := struct { UserName string DateTimeString string Scales []string LastMetrics []OneMetric + CheckoutSessionID string } { userName, datetimestring, scales, last_metrics, + checkout_session_id, } if err := tmpl.ExecuteTemplate(w, "layout", &data); err != nil { diff --git a/snippets/abos.html b/snippets/abos.html index 0cc1b4d..ce19261 100644 --- a/snippets/abos.html +++ b/snippets/abos.html @@ -8,13 +8,13 @@ {{range .LastMetrics}}
- {{.Alias}} -
+ {{.Alias}} (bis 01.01.2099) +
@@ -23,8 +23,27 @@
{{end}} +
+
+ + + + {{ else }}

Bitte zuerst einloggen

{{end}} diff --git a/snippets/payment_cancelled.html b/snippets/payment_cancelled.html new file mode 100644 index 0000000..277b677 --- /dev/null +++ b/snippets/payment_cancelled.html @@ -0,0 +1,4 @@ +{{define "body_content"}} +

Zahlung abgebrochen!

+

Zahlung wurde abgebrochen

+{{end}} diff --git a/snippets/payment_received.html b/snippets/payment_received.html new file mode 100644 index 0000000..4f5a207 --- /dev/null +++ b/snippets/payment_received.html @@ -0,0 +1,4 @@ +{{define "body_content"}} +

Danke schoen!

+

Danke fuer die Zahlung!

+{{end}} diff --git a/snippets/scales.html b/snippets/scales.html index 49dad53..c60281f 100644 --- a/snippets/scales.html +++ b/snippets/scales.html @@ -103,11 +103,11 @@ Device ID:
-
diff --git a/stripe.go b/stripe.go new file mode 100644 index 0000000..af209c4 --- /dev/null +++ b/stripe.go @@ -0,0 +1,34 @@ +package main + +import ( + "github.com/stripe/stripe-go" + "github.com/stripe/stripe-go/checkout/session" +) + +func GetStripeSessionID() string { + stripe.Key = "sk_test_GJbXPD0IAFNvvGpNEpaeDfhl" + + params := &stripe.CheckoutSessionParams{ + PaymentMethodTypes: stripe.StringSlice([]string{ + "card", + }), + LineItems: []*stripe.CheckoutSessionLineItemParams{ + &stripe.CheckoutSessionLineItemParams{ + Name: stripe.String("Abo"), + Description: stripe.String("Abo mini-beieli.ch"), + Amount: stripe.Int64(500), + Currency: stripe.String(string(stripe.CurrencyCHF)), + Quantity: stripe.Int64(1), + }, + }, + SuccessURL: stripe.String("https://mini-beieli.ch/payment_received.html"), + CancelURL: stripe.String("https://mini-beieli.ch/payment_cancelled.html"), + } + + session, err := session.New(params) + if err != nil { + return "" + } else { + return session.ID + } +}