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.

83 lines
1.9KB

  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. func logRequestDebug(data []byte, err error) {
  31. if err == nil {
  32. fmt.Printf("%s\n\n", string(data))
  33. } else {
  34. log.Fatalf("%s\n\n", err)
  35. }
  36. }
  37. //receive RPN user name and card number
  38. func rpnNameAndCard(w http.ResponseWriter, r *http.Request) {
  39. if r.Method != "POST" {
  40. errPage(w, http.StatusMethodNotAllowed, "invalid request")
  41. return
  42. }
  43. r.ParseForm()
  44. id := r.FormValue("id")
  45. sign := r.FormValue("sign")
  46. user_name := r.FormValue("name")
  47. user_card := r.FormValue("card")
  48. rpn_type := r.FormValue("rpnType")
  49. if !(id != "" && sign != "" && user_name != "" && user_card != "") {
  50. errPage(w, http.StatusBadRequest, "missing parameters")
  51. return
  52. }
  53. row, err := getRequestRowByIdAndSign(id, sign)
  54. if err != nil {
  55. w.WriteHeader(http.StatusBadRequest)
  56. fmt.Fprintf(w, "bad parameters")
  57. return
  58. }
  59. ro := RpnOut{}
  60. ro.Ip4 = getClientIPLong(r)
  61. ro.Leanwork = row.Id
  62. if rpn_type == "rpnp2p" {
  63. ro.buildReqByLeanworkINP2P(row, user_name, user_card)
  64. } else {
  65. ro.buildReqByLeanworkINFAT(row, user_name, user_card)
  66. }
  67. //create db record
  68. db.addRpnOut(ro)
  69. //build rpn redirect page and send it
  70. ro.sendRedirect(w, row)
  71. }