|
|
|
@@ -5,6 +5,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
|
|
|
|
type TransactionDB struct { |
|
|
|
@@ -31,30 +32,57 @@ func (m *TransactionDB) close() { |
|
|
|
defer m.h.Close() |
|
|
|
} |
|
|
|
|
|
|
|
func (m *TransactionDB) addRequest(r *http.Request) error { |
|
|
|
if err := m.conn(Config); err != nil { |
|
|
|
return err |
|
|
|
func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkRequest, err error) { |
|
|
|
if err = m.conn(Config); err != nil { |
|
|
|
return row, err |
|
|
|
} |
|
|
|
defer m.close() |
|
|
|
|
|
|
|
r.ParseForm() |
|
|
|
//assuming form has been parsed |
|
|
|
pickupUrl := r.Form["pickupUrl"][0] |
|
|
|
receiveUrl := r.Form["receiveUrl"][0] |
|
|
|
signType := r.Form["signType"][0] |
|
|
|
orderNo := r.Form["orderNo"][0] |
|
|
|
orderAmount := r.Form["orderAmount"][0] |
|
|
|
orderCurrency := r.Form["orderCurrency"][0] |
|
|
|
customerId := r.Form["customerId"][0] |
|
|
|
sign := r.Form["sign"][0] |
|
|
|
row = LeanworkRequest{} |
|
|
|
pickupUrl, _ := retrieveFormValue(r.Form, "pickupUrl") |
|
|
|
receiveUrl, _ := retrieveFormValue(r.Form, "receiveUrl") |
|
|
|
signType, _ := retrieveFormValue(r.Form, "signType") |
|
|
|
orderNo, _ := retrieveFormValue(r.Form, "orderNo") |
|
|
|
orderAmount, _ := retrieveFormValue(r.Form, "orderAmount") |
|
|
|
orderCurrency, _ := retrieveFormValue(r.Form, "orderCurrency") |
|
|
|
customerId, _ := retrieveFormValue(r.Form, "customerId") |
|
|
|
sign, _ := retrieveFormValue(r.Form, "sign") |
|
|
|
valid := isLeanworkFormValid(r.Form) |
|
|
|
ip4 := getClientIPLong(r) |
|
|
|
|
|
|
|
insForm, err := m.h.Prepare("INSERT INTO request(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) VALUES(?,?,?,?,?,?,?,?,?,?)") |
|
|
|
if err == nil { |
|
|
|
insForm.Exec(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) |
|
|
|
log.Println("INSERT: customerId: " + customerId + " | orderAmount: " + orderCurrency + " " + orderAmount) |
|
|
|
if err != nil { |
|
|
|
log.Printf("Failed to prepare SQL statment for insert") |
|
|
|
return |
|
|
|
} |
|
|
|
m.close() |
|
|
|
return err |
|
|
|
|
|
|
|
res, err := insForm.Exec(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) |
|
|
|
if err != nil { |
|
|
|
log.Printf("Error inserting leanwork request with orderNo =%s \n", orderNo) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
id, err := res.LastInsertId() |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
row.Id = id |
|
|
|
row.PickupUrl = pickupUrl |
|
|
|
row.ReceiveUrl = receiveUrl |
|
|
|
row.SignType = signType |
|
|
|
row.OrderNo = orderNo |
|
|
|
row.OrderAmount = orderAmount |
|
|
|
row.OrderCurrency = orderCurrency |
|
|
|
row.CustomerId = customerId |
|
|
|
row.Sign = sign |
|
|
|
row.Valid = valid |
|
|
|
row.Ip4 = ip4 |
|
|
|
log.Println("INSERT[" + strconv.FormatInt(row.Id, 10) + "]: customerId: " + customerId + " | orderAmount: " + orderCurrency + " " + orderAmount) |
|
|
|
|
|
|
|
return row, err |
|
|
|
} |
|
|
|
|
|
|
|
func (m *TransactionDB) addRpnOut(r RpnReq) error { |