From 2c455aec1cd4cf128c34a070de322b131385a212 Mon Sep 17 00:00:00 2001 From: patrick Date: Mon, 9 Mar 2020 21:33:39 +1100 Subject: [PATCH] handling name and cards info and start redirect using template --- rpn.go | 69 +++++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/rpn.go b/rpn.go index eb93857..aca72a7 100644 --- a/rpn.go +++ b/rpn.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net/http" "net/url" "strconv" @@ -24,6 +25,7 @@ type RpnReq struct { user_name string user_cardno string signature string + url string //where to post entire data structure } //build request from leanwork request forms @@ -96,45 +98,34 @@ func (m *RpnReq) encode() string { return s } -// '1.1', -// 'sign_type'=> 'MD5', -// 'mid' => 'EU85201311P2P', //must to use your mid -// 'notify_url' => 'https://lawipac.com/dumprequest.php', -// 'order_id' => "demo-" . date('YmdHis'), -// 'order_amount' => 120000 , //round($_POST['amount']*100), -// 'order_time' => date('YmdHis'), -// 'user_id'=> 'supertraderP2P', //$_POST['user_id'], -// 'user_name'=>"zhang3", //urlencode($_POST['user_name']), -// 'user_cardno'=>"6212262002002377849" //$_POST['user_cardno'], -// ); +//receive RPN user name and card number +func rpnNameAndCard(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + fmt.Fprintf(w, "invalid request") + return + } + r.ParseForm() + order_id, ok1 := r.Form["id"][0] + signature, ok2 := r.Form["si"][0] + user_name, ok3 := r.Form["name"][0] + user_card, ok4 := r.Form["card"][0] -// $params = array(); -// foreach ($data as $field => $value) { -// if( $value == '' ) continue; -// $params[] = "$field=$value"; -// } -// $params[] = "key=p1j4A3mEMj+ft0xkSfVULQ"; //must to use your key + if !(ok1 && ok2 && ok3 && ok4) { + fmt.Fprintf(w, "missing parameters") + return + } -// $data['signature'] = md5(implode('|', $params)); -// ?> + row, err := db.updateRpnOutNameAndCard(order_id, signature, user_name, user_card) + if err != nil { + fmt.Fprintf(w, "cannot update transaction") + return + } -// -// -// -// -// -//
-// $val) { -// echo ''; -// } -// ?> -// -//
-// -// -// some text + //build rpn redirect page and send it + row.sendRedirect(w) +} + +func (m *RpnReq) sendRedirect(w http.ResponseWriter) { + m.url = Config.Rpn.Url + tmpl.ExecuteTemplate(w, "rpnCallOutRedirect", *m) +}