
<!--#include file="../conn.asp"-->
<!--#include file="../fuction.asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%
Dim authToken, txToken
Dim query,err_flag
Dim objHttp
Dim sQuerystring
Dim sParts, iParts, aParts
Dim sResults, sKey, sValue
Dim i, result
Dim firstName, lastName, itemName, mcGross, mcCurrency

err_flag =1

 Set rs = conn.Execute("select * from shop_pay where id = 1") 
authToken =rs("pay5")


'authToken = "Dc7P6f0ZadXW-U1X8oxf8_vUK09EHBMD7_53IiTT-CfTpfzkN0nipFKUPYy"
'authToken = "Uz0-URA3Fk8YHy2vsGV_f5sMTidpCrYQELq_l0w8OL7Kv2hKzsZrVhE2wWS"
txToken = Request.Querystring("tx")

query = "cmd=_notify-synch&tx=" & txToken &"&at=" & authToken

set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
' set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHttp.open "POST", "http://www.paypal.com/cgi-bin/webscr", false
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send query

sQuerystring = objHttp.responseText

If Mid(sQuerystring,1,7) = "SUCCESS" Then
sQuerystring = Mid(sQuerystring,9)
sParts = Split(sQuerystring, vbLf)
iParts = UBound(sParts) - 1
ReDim sResults(iParts, 1)
For i = 0 To iParts
aParts = Split(sParts(i), "=")
sKey = aParts(0)
sValue = aParts(1)
sResults(i, 0) = sKey
sResults(i, 1) = sValue

Select Case sKey
Case "item_name"
' get shop name
	itemName = sValue
Case "mc_gross"
' get 支付金额
	mcGross = sValue
Case "mc_currency"
' get 支付比种
	mcCurrency = sValue
Case "invoice"
' get 定单号
	invoice = sValue
Case "payer_email"
' get 支付帐户地址
	payer_email = sValue
Case "receiver_email"
' get 接受帐户主地址
	receiver_email = replace(sValue,"%40","@")
Case "business"
' get 接受帐户地址
	business = replace(sValue,"%40","@")
Case "payer_email"
' get 支付帐户地址
	payer_email = replace(sValue,"%40","@")
Case "txn_id"
' get 反馈回来的系统id
	txn_id = sValue
End Select
Next
'---------------------定单处理

'----------------预计增加判断
'txn_id 检测

set rs_pay_pp=server.CreateObject("adodb.recordset")
sql = "select * from shop_action where dingdan='" & nosql(invoice) &"'"
rs_pay_pp.Open sql,conn,1,3
if  rs_pay_pp.eof and rs_pay_pp.bof then 
	err_flag =0
else
	if rs_pay_pp("zhuangtai") >2 then 
		err_flag =0
	else
	while (not rs_pay_pp.eof) and (not rs_pay_pp.bof)
	rs_pay_pp("zhuangtai")=3
	rs_pay_pp("liuyan") = txn_id
	rs_pay_pp.update
	rs_pay_pp.movenext
		wend
	end if
end if
rs_pay_pp.close
'---------------------
%>
 <style type="text/css">
<!--
.style1 {color: #6699FF}
body,td,th {
	font-size: 14px;
	color: #000000;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.dddd_dd {
	border: 1px dashed #6699FF;
}
-->
</style>
<table width="442" border="0" align="center" bordercolor="#6699FF" class="dddd_dd">
  <tr> 
    <td width="436"> 
	<p align="center"><b><font color="#FF0000"><br>
      在线支付提示信息<br>
    </font> 您使用PAYPAL在线支付的定单反馈如下：</b><br>
    <br>
        
		<span class="style1">-------------------------------------------------------------</span><br>
        您的定单号为：<strong><font color="#FF0000"><%=invoice%></font>        
	<font color="#FF0000">支付成功</font>!<br>
    <span class="style1">------------------------------------------------------<br>
    <br>
    </span></font></strong></p>    </td>
  </tr>
	<tr>
	<td><table width="100%" border="0" class="top">
	        <tr bgcolor="#63CFFF" class="link_redblank">
          <td><div align="right">商品名称：</div></td>
          <td><%=itemName%></td>
        </tr>

        <tr bgcolor="#66CCFF">
          <td><div align="right">支付状态：</div></td>
          <td>完成！<%if err_flag then %>[NEW]<%else%>[OLD]<%end if%></td>
        </tr>
        <tr class="style1">
          <td><div align="right">支付帐户： </div></td>
          <td><%=payer_email%></td>
        </tr>
        <tr class="style1">
          <td><div align="right">支付币种： </div></td>
          <td><%=mcCurrency%></td>
        </tr>
        <tr bgcolor="#63CFFF" class="link_redblank">
          <td><div align="right">支付金额：</div></td>
          <td><%=mcGross%></td>
        </tr>
      </table>      </td>
	</tr>
		<tr>
		<td><div align="center"><span class="style1"><br>
	    --------------------------------------------------------------</span><br>
		</div>
		  <div align="center"><a href="../dingdan.asp?dan=<%=invoice%>">立即查看定单</a>&nbsp;&nbsp;&nbsp;<a href="user.asp">进入个人帐户</a> <br>
		    <br>
		  </div></td>
	</tr>
</table>
<%
Else
'log for manual investigation
Response.Write("ERROR！")
Response.Write("</br>超时或者已经过期了！")
End If
%>