diff --git a/purchase.go b/purchase.go index c469a79..3e31551 100644 --- a/purchase.go +++ b/purchase.go @@ -2,55 +2,11 @@ package main import ( "fmt" + "log" "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 @@ -61,7 +17,11 @@ func askForPaymentInfo(w http.ResponseWriter, row LeanworkIn, rpn_type string) { data.Sign = row.Sign data.RpnType = rpn_type //tmpl.ExecuteTemplate(w, "rpnAskNameAndCard", data) - t := template.Must(template.ParseFiles("PG/rpnAskNameAndCard.html")) + fname := "PG/rpnAskNameAndCardP2P.html" + if rpn_type == "rpnfat" { + fname = "PG/rpnAskNameAndCardFAT.html" + } + t := template.Must(template.ParseFiles(fname)) t.Execute(w, data) } @@ -88,3 +48,57 @@ func choosePayment(w http.ResponseWriter, r *http.Request) { //show redirect, and start payment askForPaymentInfo(w, row, rpn_type) } + +//leanwork in for alipay +func leanworkInFAT(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + errPage(w, http.StatusMethodNotAllowed, "invalid method") + return + } + r.ParseForm() + + row, err := db.addRequest(r, Config.LeanWork.MD5FAT) + if err != nil { + errPage(w, http.StatusInternalServerError, "Cannot initiate database transaction for incoming request") + return + } + + if !isLeanworkFormValid(r.Form, Config.LeanWork.MD5FAT) { + // w.WriteHeader(http.StatusMethodNotAllowed) + // fmt.Fprintf(w, "invalid request") + errPage(w, http.StatusBadRequest, "validation of FAT input parameters failed") + return + } + + //show redirect, and start payment + askForPaymentInfo(w, row, "rpnfat") + + return +} + +func leanworkInP2P(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + errPage(w, http.StatusMethodNotAllowed, "invalid method") + return + } + r.ParseForm() + + row, err := db.addRequest(r, Config.LeanWork.MD5P2P) + if err != nil { + errPage(w, http.StatusInternalServerError, "Cannot initiate database transaction for incoming request") + log.Printf("ERROR: cannot initiate LeanworkIn for adding database: %+v \n", r.Form) + return + } + + if !isLeanworkFormValid(r.Form, Config.LeanWork.MD5P2P) { + // w.WriteHeader(http.StatusMethodNotAllowed) + // fmt.Fprintf(w, "invalid request") + errPage(w, http.StatusBadRequest, "validation of P2P input parameters failed") + return + } + + //show redirect, and start payment + askForPaymentInfo(w, row, "rpnp2p") + + return +}