diff --git a/main.go b/main.go
index 6e05907..f88e492 100644
--- a/main.go
+++ b/main.go
@@ -56,7 +56,7 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
var last_metrics []OneMetric
var checkout_session_id string
- if (r.URL.Path == "/scales.html") || (r.URL.Path == "/abos.html") {
+ if (r.URL.Path == "/scales.html") {
// wir holen noch die letzten Metriken
for _, v := range scales {
last_metric := getLastMetrics(v)
@@ -64,13 +64,6 @@ 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
@@ -107,6 +100,7 @@ func main() {
http.HandleFunc("/metrics", metricsHandler)
http.HandleFunc("/lastmetrics", lastmetricsHandler)
http.HandleFunc("/save_scale_settings", save_scale_settingsHandler)
+ http.HandleFunc("/getstripesession", getstripesessionHandler)
logit("Starting Web Application...")
http.ListenAndServe("127.0.0.1:4000", nil)
diff --git a/snippets/abos.html b/snippets/abos.html
deleted file mode 100644
index ce19261..0000000
--- a/snippets/abos.html
+++ /dev/null
@@ -1,50 +0,0 @@
-{{define "body_content"}}
-
Abos
-Hier können blablabla...
-
-{{ if ne .UserName "" }}
-{{range .LastMetrics}}
-
-
-
{{.Alias}} (bis 01.01.2099)
-
-
-
-
-
-
-{{end}}
-
-
-
-
-
-
-
-
-{{ else }}
-
-{{end}}
-{{end}}
diff --git a/snippets/scales.html b/snippets/scales.html
index e02efba..5daa8b4 100644
--- a/snippets/scales.html
+++ b/snippets/scales.html
@@ -179,25 +179,11 @@ $(".show-modal").click(function() {
$("#modal").addClass("is-active");
});
-$(".abo_pay").click(function() {
- console.log("pay...");
- el = $(this).parent().find(".abo_add_years");
- counter = Number(el.html());
- if (counter > 0) {
- $("#cart").addClass("is-active");
- }
-});
-
$("#cart-close").click(function() {
console.log("blabla");
$("#cart").removeClass("is-active");
});
-$("#cart-pay").click(function() {
- console.log("hoopla");
- $("#cart").removeClass("is-active");
-});
-
$(".abo_plus").click(function() {
console.log("abo_plus");
el = $(this).parent().find(".abo_add_years");
@@ -232,6 +218,15 @@ $(".abo_minus").click(function() {
}
});
+$(".abo_pay").click(function() {
+ console.log("pay...");
+ el = $(this).parent().find(".abo_add_years");
+ counter = Number(el.html());
+ if (counter > 0) {
+ $("#cart").addClass("is-active");
+ }
+});
+
$("#modal-close").click(function() {
console.log("blabla");
$("#modal").removeClass("is-active");
@@ -303,6 +298,52 @@ $("#modal-save").click(function() {
$("#modal").removeClass("is-active");
});
+});
+
+
+
+
+
+
diff --git a/stripe.go b/stripe.go
index af209c4..16bc98a 100644
--- a/stripe.go
+++ b/stripe.go
@@ -1,34 +1,85 @@
package main
import (
- "github.com/stripe/stripe-go"
- "github.com/stripe/stripe-go/checkout/session"
+ "fmt"
+ "log"
+ "strconv"
+ "net/http"
+ "github.com/stripe/stripe-go"
+ "github.com/stripe/stripe-go/checkout/session"
)
-func GetStripeSessionID() string {
- stripe.Key = "sk_test_GJbXPD0IAFNvvGpNEpaeDfhl"
+func getstripesessionHandler(response http.ResponseWriter, request *http.Request) {
+ name := getUserName(request)
+ if name != "" {
- params := &stripe.CheckoutSessionParams{
- PaymentMethodTypes: stripe.StringSlice([]string{
- "card",
- }),
+ charge_name, ok := request.URL.Query()["charge_name"]
+ if !ok || len(charge_name[0]) < 1 {
+ log.Println("Url Param 'charge_name' is missing")
+ fmt.Fprintf(response, "{ \"rc\": 1, \"msg\": \"charge_name must be specified in URL\" }")
+ return
+ }
+
+ charge_description, ok := request.URL.Query()["charge_description"]
+ if !ok || len(charge_description[0]) < 1 {
+ log.Println("Url Param 'charge_description' is missing")
+ fmt.Fprintf(response, "{ \"rc\": 2, \"msg\": \"charge_description must be specified in URL\" }")
+ return
+ }
+
+ charge_quantity, ok := request.URL.Query()["charge_quantity"]
+ if !ok || len(charge_quantity[0]) < 1 {
+ log.Println("Url Param 'charge_quantity' is missing")
+ fmt.Fprintf(response, "{ \"rc\": 3, \"msg\": \"charge_quantity must be specified in URL\" }")
+ return
+ }
+ charge_quantity_int64, err := strconv.Atoi(charge_quantity[0])
+ if err == nil {
+ fmt.Println(charge_quantity_int64)
+ } else {
+ fmt.Println(charge_quantity[0], "is not an integer.")
+ }
+
+ charge_amount_rappen, ok := request.URL.Query()["charge_amount_rappen"]
+ if !ok || len(charge_amount_rappen[0]) < 1 {
+ log.Println("Url Param 'charge_amount_rappen' is missing")
+ fmt.Fprintf(response, "{ \"rc\": 4, \"msg\": \"charge_amount_rappen must be specified in URL\" }")
+ return
+ }
+ charge_amount_rappen_int64, err := strconv.Atoi(charge_amount_rappen[0])
+ if err == nil {
+ fmt.Println(charge_amount_rappen_int64,)
+ } else {
+ fmt.Println(charge_amount_rappen[0], "is not an integer.")
+ }
+
+ 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),
+ Name: stripe.String(charge_name[0]),
+ Description: stripe.String(charge_description[0]),
+ Amount: stripe.Int64(int64(charge_amount_rappen_int64)),
Currency: stripe.String(string(stripe.CurrencyCHF)),
- Quantity: stripe.Int64(1),
+ Quantity: stripe.Int64(int64(charge_quantity_int64)),
},
},
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 {
+ fmt.Fprintf(response,"{ \"rc\": 5, \"stripesessionid\": \"%s\" }\n","ERROR")
+ } else {
+ fmt.Fprintf(response,"{ \"rc\": 0, \"stripesessionid\": \"%s\" }\n",session.ID )
+ }
- session, err := session.New(params)
- if err != nil {
- return ""
} else {
- return session.ID
+ fmt.Fprintf(response, "{ \"rc\": 6, \"msg\": \"Only available for logged in users\" }")
}
}