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.

95 lignes
2.3KB

  1. package main
  2. import (
  3. "database/sql"
  4. "log"
  5. "net/http"
  6. "strconv"
  7. )
  8. type TransactionDB struct {
  9. h *sql.DB
  10. }
  11. var db TransactionDB
  12. func (m *TransactionDB) conn(c AppConfig) error {
  13. dbDriver := c.DB.Driver
  14. dbUser := c.DB.User
  15. dbPass := c.DB.Pass
  16. dbName := c.DB.Schema
  17. h, err := sql.Open(dbDriver, dbUser+":"+dbPass+"@/"+dbName)
  18. if err != nil {
  19. panic(err.Error())
  20. }
  21. m.h = h
  22. return err
  23. }
  24. func (m *TransactionDB) close() {
  25. defer m.h.Close()
  26. }
  27. func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkRequest, err error) {
  28. if err = m.conn(Config); err != nil {
  29. return row, err
  30. }
  31. defer m.close()
  32. r.ParseForm()
  33. //assuming form has been parsed
  34. row = LeanworkRequest{}
  35. pickupUrl := r.FormValue("pickupUrl")
  36. receiveUrl := r.FormValue("receiveUrl")
  37. signType := r.FormValue("signType")
  38. orderNo := r.FormValue("orderNo")
  39. orderAmount := r.FormValue("orderAmount")
  40. orderCurrency := r.FormValue("orderCurrency")
  41. customerId := r.FormValue("customerId")
  42. sign := r.FormValue("sign")
  43. valid := isLeanworkFormValid(r.Form)
  44. ip4 := getClientIPLong(r)
  45. insForm, err := m.h.Prepare("INSERT INTO request(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) VALUES(?,?,?,?,?,?,?,?,?,?)")
  46. if err != nil {
  47. log.Printf("Failed to prepare SQL statment for insert")
  48. return
  49. }
  50. res, err := insForm.Exec(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4)
  51. if err != nil {
  52. log.Printf("Error inserting leanwork request with orderNo =%s \n", orderNo)
  53. return
  54. }
  55. id, err := res.LastInsertId()
  56. if err != nil {
  57. return
  58. }
  59. row.Id = id
  60. row.PickupUrl = pickupUrl
  61. row.ReceiveUrl = receiveUrl
  62. row.SignType = signType
  63. row.OrderNo = orderNo
  64. row.OrderAmount = orderAmount
  65. row.OrderCurrency = orderCurrency
  66. row.CustomerId = customerId
  67. row.Sign = sign
  68. row.Valid = valid
  69. row.Ip4 = ip4
  70. log.Println("INSERT[" + strconv.FormatInt(row.Id, 10) + "]: customerId: " + customerId + " | orderAmount: " + orderCurrency + " " + orderAmount)
  71. return row, err
  72. }
  73. func (m *TransactionDB) addRpnOut(r RpnReq) error {
  74. return nil
  75. }
  76. func (m *TransactionDB) updateRpnOutNameAndCard(orderid string, signature string, name string, card string) (row RpnReq, err error) {
  77. err = nil
  78. row = RpnReq{}
  79. return
  80. }