| m.h = nil //clear it, very important to prevent multiple opening | m.h = nil //clear it, very important to prevent multiple opening | ||||
| } | } | ||||
| func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkRequest, err error) { | |||||
| func (m *TransactionDB) addRequest(r *http.Request) (row LeanworkIn, err error) { | |||||
| if err = m.conn(Config); err != nil { | if err = m.conn(Config); err != nil { | ||||
| return row, err | return row, err | ||||
| } | } | ||||
| r.ParseForm() | r.ParseForm() | ||||
| //assuming form has been parsed | //assuming form has been parsed | ||||
| row = LeanworkRequest{} | |||||
| row = LeanworkIn{} | |||||
| pickupUrl := r.FormValue("pickupUrl") | pickupUrl := r.FormValue("pickupUrl") | ||||
| receiveUrl := r.FormValue("receiveUrl") | receiveUrl := r.FormValue("receiveUrl") | ||||
| signType := r.FormValue("signType") | signType := r.FormValue("signType") | ||||
| valid := isLeanworkFormValid(r.Form) | valid := isLeanworkFormValid(r.Form) | ||||
| ip4 := getClientIPLong(r) | ip4 := getClientIPLong(r) | ||||
| insForm, err := m.h.Prepare("INSERT INTO request(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) VALUES(?,?,?,?,?,?,?,?,?,?)") | |||||
| insForm, err := m.h.Prepare("INSERT INTO leanworkIn (pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) VALUES(?,?,?,?,?,?,?,?,?,?)") | |||||
| if err != nil { | if err != nil { | ||||
| log.Printf("Failed to prepare SQL statment for insert") | log.Printf("Failed to prepare SQL statment for insert") | ||||
| return | return | ||||
| res, err := insForm.Exec(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) | res, err := insForm.Exec(pickupUrl, receiveUrl, signType, orderNo, orderAmount, orderCurrency, customerId, sign, valid, ip4) | ||||
| if err != nil { | if err != nil { | ||||
| log.Printf("Error inserting leanwork request with orderNo =%s \n", orderNo) | |||||
| log.Printf("Error inserting leanworkIn with orderNo =%s \n", orderNo) | |||||
| return | return | ||||
| } | } | ||||
| "time" | "time" | ||||
| ) | ) | ||||
| type LeanworkRequest struct { | |||||
| type LeanworkIn struct { | |||||
| Id int64 | Id int64 | ||||
| PickupUrl string | PickupUrl string | ||||
| ReceiveUrl string | ReceiveUrl string | ||||
| return err == nil | return err == nil | ||||
| } | } | ||||
| func getRequestRowByIdAndSign(id string, sign string) (row LeanworkRequest, err error) { | |||||
| func getRequestRowByIdAndSign(id string, sign string) (row LeanworkIn, err error) { | |||||
| //retrieve form DB | //retrieve form DB | ||||
| row = LeanworkRequest{} | |||||
| row = LeanworkIn{} | |||||
| db.conn(Config) | db.conn(Config) | ||||
| selDB, err := db.h.Query("SELECT * FROM request WHERE id=? and sign=?", id, sign) | |||||
| selDB, err := db.h.Query("SELECT * FROM leanworkIN WHERE id=? and sign=?", id, sign) | |||||
| if err != nil { | if err != nil { | ||||
| return | return | ||||
| } | } |
| package main | |||||
| } | } | ||||
| func askForPaymentSelection(w http.ResponseWriter, row LeanworkRequest) { | |||||
| func askForPaymentSelection(w http.ResponseWriter, row LeanworkIn) { | |||||
| t := template.Must(template.ParseFiles("PG/StartPay.html")) | t := template.Must(template.ParseFiles("PG/StartPay.html")) | ||||
| //tmpl.ExecuteTemplate(w, "StartPay", row) | //tmpl.ExecuteTemplate(w, "StartPay", row) | ||||
| t.Execute(w, row) | t.Execute(w, row) | ||||
| } | } | ||||
| func askForPaymentInfo(w http.ResponseWriter, row LeanworkRequest, rpn_type string) { | |||||
| func askForPaymentInfo(w http.ResponseWriter, row LeanworkIn, rpn_type string) { | |||||
| var data struct { | var data struct { | ||||
| Id int64 | Id int64 | ||||
| Sign string | Sign string |
| <?php | |||||
| $data = array( | |||||
| 'order_id'=>'200310160057TW002184000000000001', | |||||
| 'order_time'=> date('YmdHis'), | |||||
| 'order_amount'=> '120000', | |||||
| 'deal_id' => "deal" + date('YmdHis'), | |||||
| 'deal_time' => date('YmdHis'), | |||||
| 'pay_amount' => '120000', | |||||
| 'pay_result' => '3', | |||||
| ); | |||||
| $params = array(); | |||||
| foreach ($data as $field => $value) { | |||||
| if( $value == '' ) continue; | |||||
| $params[] = "$field=$value"; | |||||
| } | |||||
| $params[] = "key=p1j4A3mEMj+ft0xkSfVULQ"; //must to use your key | |||||
| $comp = implode('|', $params); | |||||
| $data['signature'] = md5(implode('|', $params)); | |||||
| ?> | |||||
| <html> | |||||
| <head> | |||||
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |||||
| </head> | |||||
| <body> | |||||
| https://deposit.paylomo.net/pay.php?r=payEasy <br> | |||||
| http://debug.biukop.com:8080/rpn_notify | |||||
| <form id="payment" name="payment" action="http://debug.biukop.com:8080/rpn_notify" method="POST"> | |||||
| <?php | |||||
| foreach ($data as $key => $val) { | |||||
| echo '<input type="hidden" name="'.$key.'" value="'.$val.'" />'; | |||||
| } | |||||
| ?> | |||||
| <input type="submit" value="submit"> | |||||
| </form> | |||||
| </body> | |||||
| <script type="text/javascript"> | |||||
| // document.getElementById('payment').submit(); | |||||
| </script> | |||||
| some text | |||||
| <?php echo "$comp ------" ?> | |||||
| <?php echo $data['signature'] ?> | |||||
| </html> |
| ro, _ := getRpnOutByOrderId(ri.Order_id) | ro, _ := getRpnOutByOrderId(ri.Order_id) | ||||
| ri.Leanwork = ro.Leanwork | ri.Leanwork = ro.Leanwork | ||||
| ri1, err := ri.add2db() //TODO:check error add | |||||
| _, err = ri.add2db() //TODO:check error add | |||||
| if err != nil { | if err != nil { | ||||
| log.Printf("failed to add rpnIn %+v , error is %s", ri, err.Error()) | log.Printf("failed to add rpnIn %+v , error is %s", ri, err.Error()) | ||||
| } | } | ||||
| ro.Ip4 = getClientIPLong(r) | ro.Ip4 = getClientIPLong(r) | ||||
| ro.Leanwork = row.Id | ro.Leanwork = row.Id | ||||
| if rpn_type == "rpnp2p" { | if rpn_type == "rpnp2p" { | ||||
| ro.buildReqByLeanworkRequestP2P(row, user_name, user_card) | |||||
| ro.buildReqByLeanworkINP2P(row, user_name, user_card) | |||||
| } else { | } else { | ||||
| ro.buildReqByLeanworkRequestFAT(row, user_name, user_card) | |||||
| ro.buildReqByLeanworkINFAT(row, user_name, user_card) | |||||
| } | } | ||||
| //create db record | //create db record | ||||
| db.addRpnOut(ro) | db.addRpnOut(ro) |
| return | return | ||||
| } | } | ||||
| func (m *RpnIn) signature() string { | |||||
| func (m *RpnIn) signature() (sig string) { | |||||
| s := "order_id=" + m.Order_id | s := "order_id=" + m.Order_id | ||||
| s += "|order_time=" + m.Order_time | s += "|order_time=" + m.Order_time | ||||
| s += "|order_amount=" + m.Order_amount | s += "|order_amount=" + m.Order_amount | ||||
| s += "|pay_amount=" + m.Pay_amount | s += "|pay_amount=" + m.Pay_amount | ||||
| s += "|pay_result=" + m.Pay_result | s += "|pay_result=" + m.Pay_result | ||||
| s += "|key=" + m.md5key() | s += "|key=" + m.md5key() | ||||
| return md5str(s) | |||||
| sig = md5str(s) | |||||
| //log.Println("signature of rpnIn = " + sig + " using key " + m.md5key()) | |||||
| return | |||||
| } | } | ||||
| func (m *RpnIn) md5key() string { | func (m *RpnIn) md5key() string { |
| Ts mysql.NullTime | Ts mysql.NullTime | ||||
| } | } | ||||
| func (m *RpnOut) buildReqByLeanworkRequestP2P(row LeanworkRequest, user_name string, user_cardno string) RpnOut { | |||||
| func (m *RpnOut) buildReqByLeanworkINP2P(row LeanworkIn, user_name string, user_cardno string) RpnOut { | |||||
| m.Version = "1.1" | m.Version = "1.1" | ||||
| m.Sign_type = "MD5" | m.Sign_type = "MD5" | ||||
| return *m | return *m | ||||
| } | } | ||||
| func (m *RpnOut) buildReqByLeanworkRequestFAT(row LeanworkRequest, user_name string, user_cardno string) RpnOut { | |||||
| func (m *RpnOut) buildReqByLeanworkINFAT(row LeanworkIn, user_name string, user_cardno string) RpnOut { | |||||
| m.Version = "1.1" | m.Version = "1.1" | ||||
| m.Sign_type = "MD5" | m.Sign_type = "MD5" | ||||
| m.Mid = Config.Rpn.MIDFAT | m.Mid = Config.Rpn.MIDFAT | ||||
| return s | return s | ||||
| } | } | ||||
| func (m *RpnOut) sendRedirect(w http.ResponseWriter, row LeanworkRequest) { | |||||
| func (m *RpnOut) sendRedirect(w http.ResponseWriter, row LeanworkIn) { | |||||
| //execute redirect | //execute redirect | ||||
| m.Url = Config.Rpn.Url | m.Url = Config.Rpn.Url | ||||
| tmpl.ExecuteTemplate(w, "rpnCallOutRedirect", *m) | tmpl.ExecuteTemplate(w, "rpnCallOutRedirect", *m) |