| import ( | import ( | ||||
| "fmt" | "fmt" | ||||
| "net/http" | "net/http" | ||||
| "os" | |||||
| "text/template" | |||||
| ) | ) | ||||
| func StartPay(w http.ResponseWriter, r *http.Request) { | func StartPay(w http.ResponseWriter, r *http.Request) { | ||||
| tmpl.ExecuteTemplate(w, "StartPay", row) | 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) | |||||
| } | } |