payment gateway for rpn cn
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

97 lines
2.3KB

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