payment gateway for rpn cn
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0KB

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "text/template"
  6. )
  7. func StartPay(w http.ResponseWriter, r *http.Request) {
  8. if r.Method != "POST" {
  9. w.WriteHeader(http.StatusMethodNotAllowed)
  10. fmt.Fprintf(w, "invalid method")
  11. return
  12. }
  13. r.ParseForm()
  14. row, err := db.addRequest(r)
  15. if err != nil {
  16. w.WriteHeader(http.StatusInternalServerError)
  17. w.Write([]byte("Cannot initiate database transaction"))
  18. return
  19. }
  20. if !isLeanworkFormValid(r.Form) {
  21. w.WriteHeader(http.StatusMethodNotAllowed)
  22. fmt.Fprintf(w, "invalid request")
  23. return
  24. }
  25. askForPaymentSelection(w, row)
  26. return
  27. // m := RpnReq{}
  28. // resp, err := m.SendReq(r.Form)
  29. // if err != nil {
  30. // fmt.Fprintf(w, "invalid response from RPN")
  31. // }
  32. // w.Header().Set("Content-Type", resp.Header.Get("Content-Type"))
  33. // w.Header().Set("Content-Length", resp.Header.Get("Content-Length"))
  34. // io.Copy(w, resp.Body)
  35. //fmt.Fprintf(w, "my md5=%s", sign)
  36. }
  37. func askForPaymentSelection(w http.ResponseWriter, row LeanworkRequest) {
  38. t := template.Must(template.ParseFiles("PG/index.html"))
  39. //tmpl.ExecuteTemplate(w, "StartPay", row)
  40. t.Execute(w, row)
  41. }
  42. func askForPaymentInfo(w http.ResponseWriter, row LeanworkRequest, rpn_type string) {
  43. var data struct {
  44. Id int64
  45. Sign string
  46. RpnType string
  47. }
  48. data.Id = row.Id
  49. data.Sign = row.Sign
  50. data.RpnType = rpn_type
  51. //tmpl.ExecuteTemplate(w, "rpnAskNameAndCard", data)
  52. t := template.Must(template.ParseFiles("PG/rpnAskNameAndCard.html"))
  53. t.Execute(w, data)
  54. }
  55. func choosePayment(w http.ResponseWriter, r *http.Request) {
  56. //get inform from form .
  57. r.ParseForm()
  58. id := r.FormValue("id")
  59. sign := r.FormValue("sign")
  60. rpn_type := r.FormValue("rpnType")
  61. if id == "" || sign == "" {
  62. w.WriteHeader(http.StatusMethodNotAllowed)
  63. fmt.Fprintf(w, "invalid parameters")
  64. return
  65. }
  66. row, err := getRequestRowByIdAndSign(id, sign)
  67. if err != nil {
  68. w.WriteHeader(http.StatusBadRequest)
  69. fmt.Fprintf(w, "invalid signature")
  70. return
  71. }
  72. //show redirect, and start payment
  73. askForPaymentInfo(w, row, rpn_type)
  74. }