소스 검색

leanwork working properly now

master
patrick 5 년 전
부모
커밋
80a3eb4bac
5개의 변경된 파일59개의 추가작업 그리고 9개의 파일을 삭제
  1. +14
    -0
      debug.go
  2. +7
    -1
      leanworkOut.go
  3. +2
    -0
      purchase.go
  4. +36
    -0
      purchase_debug.go
  5. +0
    -8
      rpn.go

+ 14
- 0
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)
}
}

+ 7
- 1
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

+ 2
- 0
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


+ 36
- 0
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())
}
}

+ 0
- 8
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" {

Loading…
취소
저장