| 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) | |||||
| } | |||||
| } |
| form.Set("orderAmount", m.OrderAmount) | form.Set("orderAmount", m.OrderAmount) | ||||
| form.Set("orderCurrency", m.OrderCurrency) | form.Set("orderCurrency", m.OrderCurrency) | ||||
| form.Set("transactionId", m.TransactionId) | form.Set("transactionId", m.TransactionId) | ||||
| form.Set("status", m.Status) | |||||
| form.Set("sign", m.Sign) | form.Set("sign", m.Sign) | ||||
| lin, err := getLeanworkInById(m.Leanwork) //which is very unlikely | lin, err := getLeanworkInById(m.Leanwork) //which is very unlikely | ||||
| } else if ri.Pay_result == "1" { | } else if ri.Pay_result == "1" { | ||||
| ret.Status = "processing" | ret.Status = "processing" | ||||
| } | } | ||||
| ret.UpdateSignature() | |||||
| return | 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) { | func (m *LeanworkOut) add2db() (ret LeanworkOut, err error) { | ||||
| if err = db.conn(Config); err != nil { | if err = db.conn(Config); err != nil { | ||||
| return | return |
| fmt.Fprintf(w, "invalid request") | fmt.Fprintf(w, "invalid request") | ||||
| return | return | ||||
| } | } | ||||
| //debugStartLeanworkCallBack(row) | |||||
| askForPaymentSelection(w, row) | askForPaymentSelection(w, row) | ||||
| return | return | ||||
| 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()) | |||||
| } | |||||
| } |
| return | 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 | //receive RPN user name and card number | ||||
| func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { | func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { | ||||
| if r.Method != "POST" { | if r.Method != "POST" { |