Przeglądaj źródła

add signType to LeanworkOut

master
patrick 5 lat temu
rodzic
commit
395c104c69
1 zmienionych plików z 51 dodań i 7 usunięć
  1. +51
    -7
      leanworkOut.go

+ 51
- 7
leanworkOut.go Wyświetl plik

@@ -13,6 +13,7 @@ import (
type LeanworkOut struct {
Id int64
Leanwork int64
SignType string
OrderNo string
OrderAmount string
OrderCurrency string
@@ -42,6 +43,8 @@ func (m *LeanworkOut) DoHttp() (retry bool, err error) {
resp, err := http.PostForm(lin.ReceiveUrl, form)
if err != nil {
log.Println("Leanwork Server Error, give bad response, " + err.Error())
m.LeanworkResp = "Http Error: " + err.Error()
m.add2db()
return
}
defer resp.Body.Close()
@@ -61,15 +64,46 @@ func (m *LeanworkOut) DoHttp() (retry bool, err error) {
return
}

func (m *LeanworkOut) startCallBack() {
func startLeanworkCallBack(ri RpnIn) {
lo, err := buildLeanworkOutByRpnIn(ri)
if err != nil {
log.Printf("Fatal: cannot inform Leanwork %+v , \n\t%s\n", ri, err.Error())
return
}

if ri.Pay_result != "3" {
log.Printf("Warning: RpnIn is processing not informing leanwork %+v", ri)
return
}

for i := 1; i <= 5; i++ {
retry, err := m.DoHttp()
retry, err := lo.DoHttp()
if !retry {
break
}
time.Sleep(5 * time.Minute) //sleep 5 minute and try again
log.Printf("Trying(%d) to report leanwork about transaction status %+v, encountered error %s \n", i, *m, err.Error())
log.Printf("Trying(%d) to report leanwork about transaction status %+v, encountered error %s \n", i, lo, err.Error())
}
}

func buildLeanworkOutByRpnIn(ri RpnIn) (ret LeanworkOut, err error) {
li, err := getLeanworkInById(ri.Leanwork)
if err != nil {
return
}
ret.Leanwork = ri.Leanwork
ret.SignType = "MD5"
ret.OrderNo = li.OrderNo
ret.OrderAmount = li.OrderAmount
ret.OrderCurrency = li.OrderCurrency
ret.TransactionId = ri.Deal_id
if ri.Pay_result == "3" {
ret.Status = "success"
} else if ri.Pay_result == "1" {
ret.Status = "processing"
}

return
}

func (m *LeanworkOut) add2db() (ret LeanworkOut, err error) {
@@ -79,9 +113,9 @@ func (m *LeanworkOut) add2db() (ret LeanworkOut, err error) {
defer db.close()

q := `INSERT INTO leanworkOut(
leanwork, orderNo, orderAmount, orderCurrency,
leanwork, signType, orderNo, orderAmount, orderCurrency,
transactionId, status, sign, leanworkResp)
VALUES(?,?,?,?,?,?,?,?)
VALUES(?,?,?,?,?,?,?,?,?)
`
insForm, err := db.h.Prepare(q)
if err != nil {
@@ -89,7 +123,7 @@ func (m *LeanworkOut) add2db() (ret LeanworkOut, err error) {
return
}
res, err := insForm.Exec(
m.Leanwork, m.OrderNo, m.OrderAmount, m.OrderCurrency,
m.Leanwork, m.SignType, m.OrderNo, m.OrderAmount, m.OrderCurrency,
m.TransactionId, m.Status, m.Sign, m.LeanworkResp)

if err != nil {
@@ -114,7 +148,17 @@ func getLeanWorkOutById(id int64) (row LeanworkOut, err error) {
db.conn(Config)
defer db.close()
err = db.h.QueryRow("SELECT * FROM leanworkOut WHERE id=? ", id).Scan(
&row.Id, &row.Leanwork, &row.OrderNo, &row.OrderAmount,
&row.Id, &row.Leanwork, &row.SignType, &row.OrderNo, &row.OrderAmount,
&row.OrderCurrency, &row.TransactionId, &row.Status, &row.Sign,
&row.Ts, &row.LeanworkResp)
return
}

func getLeanWorkOutByLeanworkId(id int64) (row LeanworkOut, err error) {
db.conn(Config)
defer db.close()
err = db.h.QueryRow("SELECT * FROM leanworkOut WHERE leanwork=? ORDER BY id DESC LIMIT 1", id).Scan(
&row.Id, &row.Leanwork, &row.SignType, &row.OrderNo, &row.OrderAmount,
&row.OrderCurrency, &row.TransactionId, &row.Status, &row.Sign,
&row.Ts, &row.LeanworkResp)
return

Ładowanie…
Anuluj
Zapisz