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.

89 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. askForPaymentSelection(w, row)
  26. return
  27. // m := RpnOut{}
  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 LeanworkIn) {
  38. t := template.Must(template.ParseFiles("PG/StartPay.html"))
  39. //tmpl.ExecuteTemplate(w, "StartPay", row)
  40. t.Execute(w, row)
  41. }
  42. func askForPaymentInfo(w http.ResponseWriter, row LeanworkIn, 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. }