finetune payment

This commit is contained in:
Joerg Lehmann 2021-04-06 17:01:11 +02:00
parent d7e69f7e38
commit 08e7fa95d3
4 changed files with 20 additions and 7 deletions

View File

@ -23,6 +23,8 @@ func abocostHandler(response http.ResponseWriter, request *http.Request) {
} }
response.Header().Set("Content-Type", "text/json; charset=utf-8") response.Header().Set("Content-Type", "text/json; charset=utf-8")
fmt.Fprintf(response, "{\n") fmt.Fprintf(response, "{\n")
fmt.Fprintf(response, " \"stripe_pk\": \"%s\",\n", getStripePK())
fmt.Fprintf(response, " \"data\": {\n")
first := true first := true
for key, value := range data { for key, value := range data {
fmt.Println("Key:", key, "Value:", value) fmt.Println("Key:", key, "Value:", value)
@ -31,7 +33,8 @@ func abocostHandler(response http.ResponseWriter, request *http.Request) {
} else { } else {
fmt.Fprintf(response, " ,") 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") fmt.Fprintf(response, "}\n")
} }

View File

@ -1,5 +1,6 @@
// dictionary: deveui as key, count as value // dictionary: deveui as key, count as value
var abos_to_buy = {} var abos_to_buy = {}
var stripe_pk = "";
function validate(what, text) { function validate(what, text) {
if (what == 'alias') { if (what == 'alias') {
@ -26,7 +27,7 @@ function HandleAbocostResponse(data) {
abo_table += '<tr><th class="is-2">Alias</th><th>verl&auml;ngern bis</th><th class="has-text-right">Betrag</th></tr>'; abo_table += '<tr><th class="is-2">Alias</th><th>verl&auml;ngern bis</th><th class="has-text-right">Betrag</th></tr>';
jQuery.each(ordered, function (index, val) { jQuery.each(ordered, function (index, val) {
counter += 1; counter += 1;
abo_table += '<tr><td>' + val[3] + '</td><td>' + moment(val[2], 'DD.MM.YYYY').add('years', val[0]).format('DD.MM.YYYY') + '</td><td class="has-text-right">' + (val[1] / 100).toFixed(2) + '</td></tr>'; abo_table += '<tr><td>' + val[3] + '</td><td>' + moment(val[2], 'DD.MM.YYYY').add(val[0], 'years').format('DD.MM.YYYY') + '</td><td class="has-text-right">' + (val[1] / 100).toFixed(2) + '</td></tr>';
total_amount += (val[1] / 100); total_amount += (val[1] / 100);
if (charge_data == '') { if (charge_data == '') {
charge_data = index + ":" + val[0] + ":" + val[1]; charge_data = index + ":" + val[0] + ":" + val[1];
@ -124,8 +125,6 @@ $(document).ready(function () {
return; return;
} }
loadStripeLibrary();
$.ajax({ $.ajax({
url: "abocost", url: "abocost",
type: "POST", //send it through post method type: "POST", //send it through post method
@ -133,8 +132,13 @@ $(document).ready(function () {
data: JSON.stringify(abos_to_buy), data: JSON.stringify(abos_to_buy),
success: function(response) { success: function(response) {
console.log("SUCCESS"); console.log("SUCCESS");
console.log(response); console.log(response.stripe_pk);
HandleAbocostResponse(response); console.log(response.data);
if (stripe_pk == "") {
stripe_pk = response['stripe_pk'];
loadStripeLibrary();
}
HandleAbocostResponse(response['data']);
}, },
error: function(xhr) { error: function(xhr) {
console.log("ERROR"); console.log("ERROR");
@ -207,7 +211,7 @@ function loadStripeLibrary() {
function SetupStripe() { function SetupStripe() {
// Set your publishable key: remember to change this to your live publishable key in production // 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 // See your keys here: https://dashboard.stripe.com/account/apikeys
stripe = Stripe('pk_test_51Icq29K2XyHQRTs2DeltUIWrbFb5evfJVGaQzMv4r50g8Q7HAUkSFr7BBGv0aP1damXIhM6fZ4Yf9Wz0qW6TpTVi00dWcW7J1O'); stripe = Stripe(stripe_pk);
elements = stripe.elements({ locale: "de" }); elements = stripe.elements({ locale: "de" });
// Set up Stripe.js and Elements to use in checkout form // Set up Stripe.js and Elements to use in checkout form

View File

@ -17,6 +17,10 @@ func getStripeKey() string {
return os.Getenv("STRIPE_KEY") return os.Getenv("STRIPE_KEY")
} }
func getStripePK() string {
return os.Getenv("STRIPE_PK")
}
func getstripepaymentintentHandler(response http.ResponseWriter, request *http.Request) { func getstripepaymentintentHandler(response http.ResponseWriter, request *http.Request) {
name := getUserName(request) name := getUserName(request)
if name != "" { if name != "" {
@ -53,6 +57,7 @@ func getstripepaymentintentHandler(response http.ResponseWriter, request *http.R
ReceiptEmail: stripe.String(name), ReceiptEmail: stripe.String(name),
} }
params.AddMetadata("charge_data", charge_data[0]) params.AddMetadata("charge_data", charge_data[0])
params.AddMetadata("login_user", name)
paymentintent, err := paymentintent.New(params) paymentintent, err := paymentintent.New(params)
if err != nil { if err != nil {

View File

@ -6,6 +6,7 @@ After=network.target
[Service] [Service]
Environment="INFLUX_RO_TOKEN=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==" Environment="INFLUX_RO_TOKEN=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
Environment="STRIPE_KEY=sk_XXXXXXXXXXXXXX" Environment="STRIPE_KEY=sk_XXXXXXXXXXXXXX"
Environment="STRIPE_PK=pk_XXXXXXXXXXXXXX"
Type=simple Type=simple
User=appuser User=appuser
Group=appuser Group=appuser