| @@ -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) | |||
| } | |||
| } | |||
| @@ -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 | |||
| @@ -26,6 +26,8 @@ func StartPay(w http.ResponseWriter, r *http.Request) { | |||
| fmt.Fprintf(w, "invalid request") | |||
| return | |||
| } | |||
| //debugStartLeanworkCallBack(row) | |||
| askForPaymentSelection(w, row) | |||
| return | |||
| @@ -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()) | |||
| } | |||
| } | |||
| @@ -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" { | |||