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.

105 satır
2.5KB

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