payment gateway for rpn cn
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

85 lines
1.8KB

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