Compare commits
10 Commits
6fe448e3e2
...
a297b127e1
| Author | SHA1 | Date |
|---|---|---|
|
|
a297b127e1 | |
|
|
8838103f2d | |
|
|
0931ecb0f4 | |
|
|
40134ceba9 | |
|
|
6364bedb29 | |
|
|
97d2bb2593 | |
|
|
570de60338 | |
|
|
c6f98415e3 | |
|
|
0520b1eb02 | |
|
|
1f1e34e213 |
|
|
@ -4,6 +4,8 @@ ADD go.mod .
|
|||
COPY . .
|
||||
RUN go build
|
||||
FROM alpine
|
||||
RUN apk add --no-cache tzdata
|
||||
ENV TZ=Europe/Zurich
|
||||
WORKDIR /build
|
||||
RUN apk add --no-cache tzdata
|
||||
COPY --from=builder /build/wo-bisch-web /build/wo-bisch-web
|
||||
|
|
|
|||
20
README.md
20
README.md
|
|
@ -45,3 +45,23 @@ show range of last values:
|
|||
Autor: Joerg Lehmann, nbit Informatik GmbH
|
||||
|
||||
|
||||
### Influxdb Commands
|
||||
|
||||
```
|
||||
Show tokens
|
||||
# influx auth ls
|
||||
|
||||
Clone Admin Token in Webgui if not known anymore and use this to get all tokens:
|
||||
|
||||
Create Default Config:
|
||||
# influx config create --config-name default --token XXXXXXXXXXX --host-url http://127.0.0.1:8086 -a
|
||||
|
||||
Update Token in Default Config:
|
||||
# influx config update --config-name default --token XXXXXXXXXXX
|
||||
|
||||
Backup Influxdb:
|
||||
# influx backup /root/joergs-backup -t XXXXXadmintokenXXXXX
|
||||
|
||||
Restore Influxdb:
|
||||
# influx restore /var/lib/influxdb2/joergs-backup/ --full
|
||||
```
|
||||
|
|
|
|||
5
go.mod
5
go.mod
|
|
@ -1,11 +1,10 @@
|
|||
module nbit.ch/wo-bisch-web/v2
|
||||
|
||||
go 1.14
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/gomodule/redigo v1.8.4
|
||||
github.com/gorilla/securecookie v1.1.1
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||
github.com/stripe/stripe-go/v72 v72.41.0
|
||||
github.com/stripe/stripe-go/v74 v74.7.0
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
|
||||
)
|
||||
|
|
|
|||
17
go.sum
17
go.sum
|
|
@ -1,29 +1,32 @@
|
|||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gomodule/redigo v1.8.4 h1:Z5JUg94HMTR1XpwBaSH4vq3+PNSIykBLxMdglbw10gg=
|
||||
github.com/gomodule/redigo v1.8.4/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||
github.com/gomodule/redigo/redis v0.0.0-do-not-use h1:J7XIp6Kau0WoyT4JtXHT3Ei0gA1KkSc6bc87j9v9WIo=
|
||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stripe/stripe-go v1.0.3 h1:RHgK2FUKawVNBPJ15pNM4IWkEVVCg5Ju3xK5QZNhTwY=
|
||||
github.com/stripe/stripe-go v70.15.0+incompatible h1:hNML7M1zx8RgtepEMlxyu/FpVPrP7KZm1gPFQquJQvM=
|
||||
github.com/stripe/stripe-go/v72 v72.41.0 h1:HkyJew+GkD/ClBT306+5vKLjBE4PRCJDiZ1enQyxeGQ=
|
||||
github.com/stripe/stripe-go/v72 v72.41.0/go.mod h1:QwqJQtduHubZht9mek5sds9CtQcKFdsykV9ZepRWwo0=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stripe/stripe-go/v74 v74.7.0 h1:KHlyslQj9YOv62b1sycQ31LFj7KlqR+seHsSowAWrjc=
|
||||
github.com/stripe/stripe-go/v74 v74.7.0/go.mod h1:5PoXNp30AJ3tGq57ZcFuaMylzNi8KpwlrYAFmO1fHZw=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
|||
6
mail.go
6
mail.go
|
|
@ -56,7 +56,9 @@ func sendPaymentConfirmationEmail(username, charge_data string, amount int64) {
|
|||
mail_message := "To: " + username + `
|
||||
From: info@wo-bisch.ch
|
||||
Subject: Zahlungsbestaetigung wo-bisch.ch
|
||||
|
||||
MIME-version: 1.0;
|
||||
Content-Type: text/html; charset="UTF-8";
|
||||
<pre>
|
||||
Lieber Benutzer von wo-bisch.ch
|
||||
|
||||
Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
|
||||
|
|
@ -65,7 +67,7 @@ Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
|
|||
|
||||
Mit freundlichen Grüssen
|
||||
--
|
||||
wo-bisch.ch`
|
||||
wo-bisch.ch</pre>`
|
||||
|
||||
sendEmail(username, "mail@wo-bisch.ch", mail_message)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -383,11 +383,7 @@ func prolongActivation(deveui string, years int) (string, error) {
|
|||
fmt.Println(t.Unix())
|
||||
|
||||
var t_new time.Time
|
||||
if t.Before(time.Now()) {
|
||||
t_new = time.Now().AddDate(years, 0, 0)
|
||||
} else {
|
||||
t_new = t.AddDate(years, 0, 0)
|
||||
}
|
||||
t_new = t.AddDate(years, 0, 0)
|
||||
active_until_new := t_new.Format(layout)
|
||||
|
||||
// SET object
|
||||
|
|
|
|||
44
stripe.go
44
stripe.go
|
|
@ -3,8 +3,9 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/stripe/stripe-go/v72"
|
||||
"github.com/stripe/stripe-go/v72/paymentintent"
|
||||
"github.com/stripe/stripe-go/v74"
|
||||
"github.com/stripe/stripe-go/v74/customer"
|
||||
"github.com/stripe/stripe-go/v74/paymentintent"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -21,6 +22,33 @@ func getStripePK() string {
|
|||
return os.Getenv("STRIPE_PK")
|
||||
}
|
||||
|
||||
func getCustomerid(name string) string {
|
||||
// if customer does not already exist, create it...
|
||||
var cid = ""
|
||||
params := &stripe.CustomerSearchParams{}
|
||||
params.Query = *stripe.String("name:'" + name + "'")
|
||||
customers := customer.Search(params)
|
||||
for customers.Next() {
|
||||
fmt.Printf("%s\n", customers.Current().(*stripe.Customer).ID)
|
||||
cid = customers.Current().(*stripe.Customer).ID
|
||||
}
|
||||
|
||||
if cid == "" {
|
||||
// create new customer
|
||||
paramsc := &stripe.CustomerParams{
|
||||
Name: stripe.String(name),
|
||||
}
|
||||
|
||||
customer, err := customer.New(paramsc)
|
||||
if err != nil {
|
||||
log.Println("Error Creating Customer: " + name)
|
||||
}
|
||||
cid = customer.ID
|
||||
}
|
||||
|
||||
return cid
|
||||
}
|
||||
|
||||
func getstripepaymentintentHandler(response http.ResponseWriter, request *http.Request) {
|
||||
name := getUserName(request)
|
||||
if name != "" {
|
||||
|
|
@ -51,10 +79,14 @@ func getstripepaymentintentHandler(response http.ResponseWriter, request *http.R
|
|||
|
||||
stripe.Key = getStripeKey()
|
||||
|
||||
// if customer does not already exist, create it...
|
||||
customerid := getCustomerid(name)
|
||||
|
||||
// define payment
|
||||
params := &stripe.PaymentIntentParams{
|
||||
Amount: stripe.Int64(abo_amount),
|
||||
Currency: stripe.String(string(stripe.CurrencyCHF)),
|
||||
ReceiptEmail: stripe.String(name),
|
||||
Customer: stripe.String(customerid),
|
||||
Amount: stripe.Int64(abo_amount),
|
||||
Currency: stripe.String(string(stripe.CurrencyCHF)),
|
||||
}
|
||||
params.AddMetadata("charge_data", charge_data[0])
|
||||
params.AddMetadata("login_user", name)
|
||||
|
|
@ -121,7 +153,7 @@ func stripeWebhookHandler(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
fmt.Printf("PaymentIntent was successful (charge_data: %s, amount: %d)!\n", paymentIntent.Metadata["charge_data"], paymentIntent.Amount)
|
||||
HandlePayment(paymentIntent.ReceiptEmail, paymentIntent.Metadata["charge_data"], paymentIntent.Amount)
|
||||
HandlePayment(paymentIntent.Metadata["login_user"], paymentIntent.Metadata["charge_data"], paymentIntent.Amount)
|
||||
// ... handle other event types
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "Unexpected event type: %s\n", event.Type)
|
||||
|
|
|
|||
Loading…
Reference in New Issue