diff --git a/abocost.go b/abocost.go
index 9408b04..88e8bab 100644
--- a/abocost.go
+++ b/abocost.go
@@ -23,6 +23,8 @@ func abocostHandler(response http.ResponseWriter, request *http.Request) {
}
response.Header().Set("Content-Type", "text/json; charset=utf-8")
fmt.Fprintf(response, "{\n")
+ fmt.Fprintf(response, " \"stripe_pk\": \"%s\",\n", getStripePK())
+ fmt.Fprintf(response, " \"data\": {\n")
first := true
for key, value := range data {
fmt.Println("Key:", key, "Value:", value)
@@ -31,7 +33,8 @@ func abocostHandler(response http.ResponseWriter, request *http.Request) {
} else {
fmt.Fprintf(response, " ,")
}
- fmt.Fprintf(response, " \"%s\": [ %d, %d, \"%s\", \"%s\" ]\n", key, int(value), int(getYearlyAboCost(key)*int(value)), getActiveUntil(key), getDevAlias(key))
+ fmt.Fprintf(response, " \"%s\": [ %d, %d, \"%s\", \"%s\" ]\n", key, int(value), int(getYearlyAboCost(key)*int(value)), getActiveUntil(key), getDevAlias(key))
}
+ fmt.Fprintf(response, " }\n")
fmt.Fprintf(response, "}\n")
}
diff --git a/static/js/tracker.js b/static/js/tracker.js
index 73edfc4..cb43224 100644
--- a/static/js/tracker.js
+++ b/static/js/tracker.js
@@ -1,5 +1,6 @@
// dictionary: deveui as key, count as value
var abos_to_buy = {}
+var stripe_pk = "";
function validate(what, text) {
if (what == 'alias') {
@@ -26,7 +27,7 @@ function HandleAbocostResponse(data) {
abo_table += '
| Alias | verlängern bis | Betrag |
';
jQuery.each(ordered, function (index, val) {
counter += 1;
- abo_table += '| ' + val[3] + ' | ' + moment(val[2], 'DD.MM.YYYY').add('years', val[0]).format('DD.MM.YYYY') + ' | ' + (val[1] / 100).toFixed(2) + ' |
';
+ abo_table += '| ' + val[3] + ' | ' + moment(val[2], 'DD.MM.YYYY').add(val[0], 'years').format('DD.MM.YYYY') + ' | ' + (val[1] / 100).toFixed(2) + ' |
';
total_amount += (val[1] / 100);
if (charge_data == '') {
charge_data = index + ":" + val[0] + ":" + val[1];
@@ -124,8 +125,6 @@ $(document).ready(function () {
return;
}
- loadStripeLibrary();
-
$.ajax({
url: "abocost",
type: "POST", //send it through post method
@@ -133,8 +132,13 @@ $(document).ready(function () {
data: JSON.stringify(abos_to_buy),
success: function(response) {
console.log("SUCCESS");
- console.log(response);
- HandleAbocostResponse(response);
+ console.log(response.stripe_pk);
+ console.log(response.data);
+ if (stripe_pk == "") {
+ stripe_pk = response['stripe_pk'];
+ loadStripeLibrary();
+ }
+ HandleAbocostResponse(response['data']);
},
error: function(xhr) {
console.log("ERROR");
@@ -207,7 +211,7 @@ function loadStripeLibrary() {
function SetupStripe() {
// Set your publishable key: remember to change this to your live publishable key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
- stripe = Stripe('pk_test_51Icq29K2XyHQRTs2DeltUIWrbFb5evfJVGaQzMv4r50g8Q7HAUkSFr7BBGv0aP1damXIhM6fZ4Yf9Wz0qW6TpTVi00dWcW7J1O');
+ stripe = Stripe(stripe_pk);
elements = stripe.elements({ locale: "de" });
// Set up Stripe.js and Elements to use in checkout form
diff --git a/stripe.go b/stripe.go
index a71ac8a..4a4a826 100644
--- a/stripe.go
+++ b/stripe.go
@@ -17,6 +17,10 @@ func getStripeKey() string {
return os.Getenv("STRIPE_KEY")
}
+func getStripePK() string {
+ return os.Getenv("STRIPE_PK")
+}
+
func getstripepaymentintentHandler(response http.ResponseWriter, request *http.Request) {
name := getUserName(request)
if name != "" {
@@ -53,6 +57,7 @@ func getstripepaymentintentHandler(response http.ResponseWriter, request *http.R
ReceiptEmail: stripe.String(name),
}
params.AddMetadata("charge_data", charge_data[0])
+ params.AddMetadata("login_user", name)
paymentintent, err := paymentintent.New(params)
if err != nil {
diff --git a/systemd/wo-bisch-web.service b/systemd/wo-bisch-web.service
index b1b1098..5eefcf6 100644
--- a/systemd/wo-bisch-web.service
+++ b/systemd/wo-bisch-web.service
@@ -6,6 +6,7 @@ After=network.target
[Service]
Environment="INFLUX_RO_TOKEN=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
Environment="STRIPE_KEY=sk_XXXXXXXXXXXXXX"
+Environment="STRIPE_PK=pk_XXXXXXXXXXXXXX"
Type=simple
User=appuser
Group=appuser