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.

69 lines
1.6KB

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