payment gateway for rpn cn
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

91 lignes
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. //debugStartLeanworkCallBack(row)
  26. askForPaymentSelection(w, row)
  27. return
  28. // m := RpnOut{}
  29. // resp, err := m.SendReq(r.Form)
  30. // if err != nil {
  31. // fmt.Fprintf(w, "invalid response from RPN")
  32. // }
  33. // w.Header().Set("Content-Type", resp.Header.Get("Content-Type"))
  34. // w.Header().Set("Content-Length", resp.Header.Get("Content-Length"))
  35. // io.Copy(w, resp.Body)
  36. //fmt.Fprintf(w, "my md5=%s", sign)
  37. }
  38. func askForPaymentSelection(w http.ResponseWriter, row LeanworkIn) {
  39. t := template.Must(template.ParseFiles("PG/StartPay.html"))
  40. //tmpl.ExecuteTemplate(w, "StartPay", row)
  41. t.Execute(w, row)
  42. }
  43. func askForPaymentInfo(w http.ResponseWriter, row LeanworkIn, rpn_type string) {
  44. var data struct {
  45. Id int64
  46. Sign string
  47. RpnType string
  48. }
  49. data.Id = row.Id
  50. data.Sign = row.Sign
  51. data.RpnType = rpn_type
  52. //tmpl.ExecuteTemplate(w, "rpnAskNameAndCard", data)
  53. t := template.Must(template.ParseFiles("PG/rpnAskNameAndCard.html"))
  54. t.Execute(w, data)
  55. }
  56. func choosePayment(w http.ResponseWriter, r *http.Request) {
  57. //get inform from form .
  58. r.ParseForm()
  59. id := r.FormValue("id")
  60. sign := r.FormValue("sign")
  61. rpn_type := r.FormValue("rpnType")
  62. if id == "" || sign == "" {
  63. w.WriteHeader(http.StatusMethodNotAllowed)
  64. fmt.Fprintf(w, "invalid parameters")
  65. return
  66. }
  67. row, err := getRequestRowByIdAndSign(id, sign)
  68. if err != nil {
  69. w.WriteHeader(http.StatusBadRequest)
  70. fmt.Fprintf(w, "invalid signature")
  71. return
  72. }
  73. //show redirect, and start payment
  74. askForPaymentInfo(w, row, rpn_type)
  75. }