From 65b26c5c5eb6764d74d630e71e766c140706924b Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 10 Mar 2020 02:32:02 +1100 Subject: [PATCH] ask payment info now contains rpn type. --- purchase.go | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/purchase.go b/purchase.go index 85fda43..5b35a90 100644 --- a/purchase.go +++ b/purchase.go @@ -3,8 +3,6 @@ package main import ( "fmt" "net/http" - "os" - "text/template" ) func StartPay(w http.ResponseWriter, r *http.Request) { @@ -49,8 +47,38 @@ func askForPaymentSelection(w http.ResponseWriter, row LeanworkRequest) { tmpl.ExecuteTemplate(w, "StartPay", row) } -func askForPaymentInfo(w http.ResponseWriter, r *http.Request) { - t := template.Must(template.New("askForPaymentInfo").ParseGlob("form/*.tmpl")) - t.ExecuteTemplate(os.Stdout, "rpnAskNameAndCard", r.Form) - t.ExecuteTemplate(w, "rpnAskNameAndCard", r.Form) +func askForPaymentInfo(w http.ResponseWriter, row LeanworkRequest, rpn_type string) { + var data struct { + Id int64 + Sign string + RpnType string + } + data.Id = row.Id + data.Sign = row.Sign + data.RpnType = rpn_type + tmpl.ExecuteTemplate(w, "rpnAskNameAndCard", data) +} + +func choosePayment(w http.ResponseWriter, r *http.Request) { + //get inform from form . + r.ParseForm() + id := r.FormValue("id") + sign := r.FormValue("sign") + rpn_type := r.FormValue("rpnType") + + if id == "" || sign == "" { + w.WriteHeader(http.StatusMethodNotAllowed) + fmt.Fprintf(w, "invalid parameters") + return + } + + row, err := getRequestRowByIdAndSign(id, sign) + + if err != nil { + w.WriteHeader(http.StatusBadRequest) + fmt.Fprintf(w, "invalid signature") + return + } + //show redirect, and start payment + askForPaymentInfo(w, row, rpn_type) }