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.

75 lines
1.7KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "net/http/httputil"
  7. )
  8. func rpnNotify(w http.ResponseWriter, r *http.Request) {
  9. logRequestDebug(httputil.DumpRequest(r, true))
  10. if r.Method != "POST" {
  11. errPage(w, http.StatusMethodNotAllowed, "invalid request")
  12. return
  13. }
  14. ri, err := GetRpnInFromHTTPRequest(r) //ParseForm called
  15. if err != nil {
  16. errPage(w, http.StatusBadRequest, "invalid parameters")
  17. return
  18. }
  19. ro, _ := getRpnOutByOrderId(ri.Order_id)
  20. ri.Leanwork = ro.Leanwork
  21. _, err = ri.add2db() //TODO:check error add
  22. if err != nil {
  23. log.Printf("failed to add rpnIn %+v , error is %s", ri, err.Error())
  24. }
  25. fmt.Fprintf(w, "[SUCCESS]")
  26. //start informing leanwork in separate thread, maximum 5 retry, interval 5 minutes
  27. go startLeanworkCallBack(ri)
  28. return
  29. }
  30. //receive RPN user name and card number
  31. func rpnNameAndCard(w http.ResponseWriter, r *http.Request) {
  32. if r.Method != "POST" {
  33. errPage(w, http.StatusMethodNotAllowed, "invalid request")
  34. return
  35. }
  36. r.ParseForm()
  37. id := r.FormValue("id")
  38. sign := r.FormValue("sign")
  39. user_name := r.FormValue("name")
  40. user_card := r.FormValue("card")
  41. rpn_type := r.FormValue("rpnType")
  42. if !(id != "" && sign != "" && user_name != "" && user_card != "") {
  43. errPage(w, http.StatusBadRequest, "missing parameters")
  44. return
  45. }
  46. row, err := getRequestRowByIdAndSign(id, sign)
  47. if err != nil {
  48. w.WriteHeader(http.StatusBadRequest)
  49. fmt.Fprintf(w, "bad parameters")
  50. return
  51. }
  52. ro := RpnOut{}
  53. ro.Ip4 = getClientIPLong(r)
  54. ro.Leanwork = row.Id
  55. if rpn_type == "rpnp2p" {
  56. ro.buildReqByLeanworkINP2P(row, user_name, user_card)
  57. } else {
  58. ro.buildReqByLeanworkINFAT(row, user_name, user_card)
  59. }
  60. //create db record
  61. db.addRpnOut(ro)
  62. //build rpn redirect page and send it
  63. ro.sendRedirect(w, row)
  64. }