payment gateway for rpn cn
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

72 lignes
1.7KB

  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. //start informing leanwork in separate thread, maximum 5 retry, interval 5 minutes
  25. go startLeanworkCallBack(ri)
  26. return
  27. }
  28. //receive RPN user name and card number
  29. func rpnNameAndCard(w http.ResponseWriter, r *http.Request) {
  30. if r.Method != "POST" {
  31. errPage(w, http.StatusMethodNotAllowed, "invalid request")
  32. return
  33. }
  34. r.ParseForm()
  35. id := r.FormValue("id")
  36. sign := r.FormValue("sign")
  37. user_name := r.FormValue("name")
  38. user_card := r.FormValue("card")
  39. rpn_type := r.FormValue("rpnType")
  40. if !(id != "" && sign != "" && user_name != "" && user_card != "") {
  41. errPage(w, http.StatusBadRequest, "missing parameters")
  42. return
  43. }
  44. row, err := getRequestRowByIdAndSign(id, sign)
  45. if err != nil {
  46. w.WriteHeader(http.StatusBadRequest)
  47. fmt.Fprintf(w, "bad parameters")
  48. return
  49. }
  50. ro := RpnOut{}
  51. ro.Ip4 = getClientIPLong(r)
  52. ro.Leanwork = row.Id
  53. if rpn_type == "rpnp2p" {
  54. ro.buildReqByLeanworkINP2P(row, user_name, user_card)
  55. } else {
  56. ro.buildReqByLeanworkINFAT(row, user_name, user_card)
  57. }
  58. //create db record
  59. db.addRpnOut(ro)
  60. //build rpn redirect page and send it
  61. ro.sendRedirect(w, row)
  62. }