|
- package main
-
- import (
- "fmt"
- "log"
- "net/http"
- "text/template"
- )
-
- 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)
- fname := "PG/rpnAskNameAndCardP2P.html"
- if rpn_type == "rpnfat" {
- fname = "PG/rpnAskNameAndCardFAT.html"
- }
- t := template.Must(template.ParseFiles(fname))
- 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)
- }
-
- //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
- }
|