payment gateway for rpn cn
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

116 líneas
3.1KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "net/http/httputil"
  7. "text/template"
  8. )
  9. func askForPaymentInfo(w http.ResponseWriter, row LeanworkIn, rpn_type string) {
  10. var data struct {
  11. Id int64
  12. Sign string
  13. RpnType string
  14. }
  15. data.Id = row.Id
  16. data.Sign = row.Sign
  17. data.RpnType = rpn_type
  18. //tmpl.ExecuteTemplate(w, "rpnAskNameAndCard", data)
  19. fname := "PG/rpnAskNameAndCardP2P.html"
  20. if rpn_type == "rpnfat" {
  21. fname = "PG/rpnAskNameAndCardFAT.html"
  22. }
  23. t := template.Must(template.ParseFiles(fname))
  24. t.Execute(w, data)
  25. }
  26. func choosePayment(w http.ResponseWriter, r *http.Request) {
  27. //get inform from form .
  28. r.ParseForm()
  29. id := r.FormValue("id")
  30. sign := r.FormValue("sign")
  31. rpn_type := r.FormValue("rpnType")
  32. if id == "" || sign == "" {
  33. w.WriteHeader(http.StatusMethodNotAllowed)
  34. fmt.Fprintf(w, "invalid parameters")
  35. return
  36. }
  37. row, err := getRequestRowByIdAndSign(id, sign)
  38. if err != nil {
  39. w.WriteHeader(http.StatusBadRequest)
  40. fmt.Fprintf(w, "invalid signature")
  41. return
  42. }
  43. //show redirect, and start payment
  44. askForPaymentInfo(w, row, rpn_type)
  45. }
  46. //leanwork in for alipay
  47. func leanworkInFAT(w http.ResponseWriter, r *http.Request) {
  48. if r.Method != "POST" {
  49. log.Println("Invalid Request expect POST for leanworkInFAT")
  50. logRequestDebug(httputil.DumpRequest(r, true))
  51. errPage(w, http.StatusMethodNotAllowed, "invalid method")
  52. return
  53. }
  54. r.ParseForm()
  55. row, err := db.addRequest(r, Config.LeanWork.MD5FAT)
  56. if err != nil {
  57. log.Printf("ERROR failed to add leanworkIn %+v \n", r.Form)
  58. logRequestDebug(httputil.DumpRequest(r, true))
  59. errPage(w, http.StatusInternalServerError, "Cannot initiate database transaction for incoming request")
  60. return
  61. }
  62. if !isLeanworkFormValid(r.Form, Config.LeanWork.MD5FAT) {
  63. // w.WriteHeader(http.StatusMethodNotAllowed)
  64. // fmt.Fprintf(w, "invalid request")
  65. errPage(w, http.StatusBadRequest, "validation of FAT input parameters failed")
  66. log.Printf("Invalid Request received, Signature is not correct")
  67. logRequestDebug(httputil.DumpRequest(r, true))
  68. return
  69. }
  70. //show redirect, and start payment
  71. askForPaymentInfo(w, row, "rpnfat")
  72. return
  73. }
  74. func leanworkInP2P(w http.ResponseWriter, r *http.Request) {
  75. if r.Method != "POST" {
  76. log.Println("Invalid P2P Request expect POST for leanworkInP2P")
  77. logRequestDebug(httputil.DumpRequest(r, true))
  78. errPage(w, http.StatusMethodNotAllowed, "invalid method")
  79. return
  80. }
  81. r.ParseForm()
  82. row, err := db.addRequest(r, Config.LeanWork.MD5P2P)
  83. if err != nil {
  84. errPage(w, http.StatusInternalServerError, "Cannot initiate database transaction for incoming request")
  85. log.Printf("ERROR: cannot initiate LeanworkIn for adding database: %+v \n", r.Form)
  86. return
  87. }
  88. if !isLeanworkFormValid(r.Form, Config.LeanWork.MD5P2P) {
  89. // w.WriteHeader(http.StatusMethodNotAllowed)
  90. // fmt.Fprintf(w, "invalid request")
  91. errPage(w, http.StatusBadRequest, "validation of P2P input parameters failed")
  92. log.Printf("Invalid Request received, Signature is not correct")
  93. logRequestDebug(httputil.DumpRequest(r, true))
  94. return
  95. }
  96. //show redirect, and start payment
  97. askForPaymentInfo(w, row, "rpnp2p")
  98. return
  99. }