work on payment code

This commit is contained in:
Joerg Lehmann 2019-07-27 18:30:08 +02:00
parent 495871b3fe
commit 7217960da2
4 changed files with 48 additions and 3 deletions

View File

@ -54,7 +54,6 @@ 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") {
// wir holen noch die letzten Metriken
@ -69,13 +68,11 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
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 {

View File

@ -3,6 +3,7 @@ package main
import (
"time"
"strings"
"fmt"
"log"
"crypto/rand"
"golang.org/x/crypto/bcrypt"
@ -54,6 +55,7 @@ type Dev struct {
Alias string
Alarmactive string
Smsnumber string
ActiveUntil string // Abo bezahlt bis TT.MM.YYYY
}
func initDB() {
@ -203,6 +205,42 @@ func getDevSmsnumber(deveui string) string {
return res
}
func prolongActivation(deveui string, years int) (string, error) {
conn := globalPool.Get()
defer conn.Close()
active_until_old, err := redis.String(conn.Do("HGET", devPrefix+deveui, "active_until"))
if err == nil {
logit("prolongActivation: active_until: " +active_until_old)
} else {
log.Print(err)
}
layout := "02.01.2006"
t, err := time.Parse(layout, active_until_old)
if err != nil {
fmt.Println(err)
}
fmt.Println(t.Unix())
var t_new time.Time
if t.Before(time.Now()) {
t_new = time.Now().AddDate(1, 0, 0)
} else {
t_new = t.AddDate(1, 0, 0)
}
active_until_new := t_new.Format(layout)
// SET object
_, err1 := conn.Do("HMSET", devPrefix+deveui, "active_until", active_until_new)
if err1 != nil {
return "",err1
}
return active_until_new, nil
}
func randString(n int) string {
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var bytes = make([]byte, n)

View File

@ -1,4 +1,9 @@
{{define "body_content"}}
{{ if ne .UserName "" }}
<p class="title is-4">Zahlung abgebrochen!</p>
<p>Zahlung wurde abgebrochen</p>
{{ else }}
<h4>Bitte zuerst <a href="login.html">einloggen</a></h4>
{{end}}
{{end}}

View File

@ -1,4 +1,9 @@
{{define "body_content"}}
{{ if ne .UserName "" }}
<p class="title is-4">Danke schoen!</p>
<p>Danke fuer die Zahlung!</p>
{{ else }}
<h4>Bitte zuerst <a href="login.html">einloggen</a></h4>
{{end}}
{{end}}