package main import ( "fmt" "net/http" "text/template" ) func StartPay(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { w.WriteHeader(http.StatusMethodNotAllowed) fmt.Fprintf(w, "invalid method") return } r.ParseForm() row, err := db.addRequest(r) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Cannot initiate database transaction")) return } if !isLeanworkFormValid(r.Form) { w.WriteHeader(http.StatusMethodNotAllowed) fmt.Fprintf(w, "invalid request") return } //debugStartLeanworkCallBack(row) askForPaymentSelection(w, row) return // m := RpnOut{} // resp, err := m.SendReq(r.Form) // if err != nil { // fmt.Fprintf(w, "invalid response from RPN") // } // w.Header().Set("Content-Type", resp.Header.Get("Content-Type")) // w.Header().Set("Content-Length", resp.Header.Get("Content-Length")) // io.Copy(w, resp.Body) //fmt.Fprintf(w, "my md5=%s", sign) } func askForPaymentSelection(w http.ResponseWriter, row LeanworkIn) { t := template.Must(template.ParseFiles("PG/StartPay.html")) //tmpl.ExecuteTemplate(w, "StartPay", row) t.Execute(w, row) } func askForPaymentInfo(w http.ResponseWriter, row LeanworkIn, 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) t := template.Must(template.ParseFiles("PG/rpnAskNameAndCard.html")) t.Execute(w, 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) }