From 80a3eb4bacbb1e7637e7be18df7d9df8fecfdeb1 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 11 Mar 2020 21:20:14 +1100 Subject: [PATCH] leanwork working properly now --- debug.go | 14 ++++++++++++++ leanworkOut.go | 8 +++++++- purchase.go | 2 ++ purchase_debug.go | 36 ++++++++++++++++++++++++++++++++++++ rpn.go | 8 -------- 5 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 debug.go create mode 100644 purchase_debug.go diff --git a/debug.go b/debug.go new file mode 100644 index 0000000..9045401 --- /dev/null +++ b/debug.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + "log" +) + +func logRequestDebug(data []byte, err error) { + if err == nil { + fmt.Printf("%s\n\n", string(data)) + } else { + log.Fatalf("%s\n\n", err) + } +} diff --git a/leanworkOut.go b/leanworkOut.go index e2456ab..98621c2 100644 --- a/leanworkOut.go +++ b/leanworkOut.go @@ -33,6 +33,7 @@ func (m *LeanworkOut) DoHttp() (retry bool, err error) { form.Set("orderAmount", m.OrderAmount) form.Set("orderCurrency", m.OrderCurrency) form.Set("transactionId", m.TransactionId) + form.Set("status", m.Status) form.Set("sign", m.Sign) lin, err := getLeanworkInById(m.Leanwork) //which is very unlikely @@ -105,10 +106,15 @@ func buildLeanworkOutByRpnIn(ri RpnIn) (ret LeanworkOut, err error) { } else if ri.Pay_result == "1" { ret.Status = "processing" } - + ret.UpdateSignature() return } +func (m *LeanworkOut) UpdateSignature() { + s := m.SignType + m.OrderNo + m.OrderAmount + m.OrderCurrency + m.TransactionId + m.Status + Config.LeanWork.MD5Key + m.Sign = md5str(s) +} + func (m *LeanworkOut) add2db() (ret LeanworkOut, err error) { if err = db.conn(Config); err != nil { return diff --git a/purchase.go b/purchase.go index 3b3ce52..c469a79 100644 --- a/purchase.go +++ b/purchase.go @@ -26,6 +26,8 @@ func StartPay(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "invalid request") return } + + //debugStartLeanworkCallBack(row) askForPaymentSelection(w, row) return diff --git a/purchase_debug.go b/purchase_debug.go new file mode 100644 index 0000000..8a107d4 --- /dev/null +++ b/purchase_debug.go @@ -0,0 +1,36 @@ +package main + +import ( + "log" + "time" +) + +func buildLeanworkOutByIn(in LeanworkIn) (ret LeanworkOut) { + ret.Leanwork = in.Id + ret.SignType = "MD5" + ret.OrderNo = in.OrderNo + ret.OrderAmount = in.OrderAmount + ret.OrderCurrency = in.OrderCurrency + ret.TransactionId = "DEMO" + time.Now().Format("20060102150405") + ret.Status = "success" + ret.UpdateSignature() + return +} + +func debugStartLeanworkCallBack(li LeanworkIn) { + lo := buildLeanworkOutByIn(li) + + if lo.Status != "success" { + log.Printf("Warning: Leanwork Status is not Success, skip notify leanwork %+v", lo) + return + } + + for i := 1; i <= 1; i++ { + 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, lo, err.Error()) + } +} diff --git a/rpn.go b/rpn.go index 5197d8c..51686a7 100644 --- a/rpn.go +++ b/rpn.go @@ -33,14 +33,6 @@ func rpnNotify(w http.ResponseWriter, r *http.Request) { return } -func logRequestDebug(data []byte, err error) { - if err == nil { - fmt.Printf("%s\n\n", string(data)) - } else { - log.Fatalf("%s\n\n", err) - } -} - //receive RPN user name and card number func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" {