用paypal集成的问题
请问paypal如何判断支付成功没有,如果成功,怎么返回表单里面的值给指定的数据库。请问下这个该怎么写,或者有这方面的例子吗?
[解决办法]
我做过ASP+PAYPAL支付的。
paypal有个功能,就是会返回支付状态给你,你可以保存进数据库。这个不需要用户支付完再点返回按钮什么的接收值。我找出以前处理代码“IPN.ASP”,这个就是跟paypal进行支付状态通讯的。后台进行的,有paypal那边跟你直接反馈。
<!--#include file="code.asp"-->
<!--#include file="conn.asp"-->
<%
' dim some variables
Dim Item_name, Item_number, Payment_status, Payment_amount
Dim Txn_id, Receiver_email, Payer_email
Dim objHttp, str
'define subroutine to handle "all" payments ##
sub allPayments() ' begin sub ###########################################################
end sub 'end sub ###########################################################################
'begin IPN handling
' read post from PayPal system and add 'cmd'
str = Request.Form & "&cmd=_notify-validate"
' post back to PayPal system to validate
'set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
' set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false
'objHttp.open "POST", "https://www.sandbox.paypal.com/cgi-bin/webscr", false
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send str
' assign posted variables to local variables
payment_date = Request.Form("payment_date")
invoice = Request.Form("invoice")
Item_name = Request.Form("item_name")
Item_number = Request.Form("item_number")
Payment_status = Request.Form("payment_status")
Payment_amount = Request.Form("mc_gross")
Payment_currency = Request.Form("mc_currency")
Txn_id = Request.Form("txn_id")
Receiver_email = Request.Form("receiver_email")
Payer_email = Request.Form("payer_email")
firstName = Request.Form("first_name")
lastName = Request.Form("last_name")
' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
' check that Payment_status=Completed
' check that Txn_id has not been previously processed
' check that Receiver_email is your Primary PayPal email
' check that Payment_amount/Payment_currency are correct
' process payment
'implement IPN handling logic for DB insertion '#########################################################
'decide what to do based on txn_type - using Select Case
set rs=server.createobject("adodb.recordset")
sql="select * from dingdan where pro_name='"&item_name&"' "
rs.open sql,conn,3,2
'add records to the Payments table
rs.Fields("payment_date") = payment_date
rs.Fields("payment_status") = payment_status
rs.Fields("pro_name") = item_name
rs.Fields("Payment_amount")=Payment_amount
rs.Fields("Payment_currency")=Payment_currency
'finish up
rs.Update
'修改订单支付状态
set rs=server.createobject("adodb.recordset")
sql="update cart_list set cart_stat=3 where cart_sessionid='"&item_name&"' and cart_stat<3"
rs.open sql,conn,3,2
'增加用户积分
a_jifen1=int(int(Payment_amount)*site_configs(14))
if a_jifen1<=0 then
a_jifen=0
else
a_jifen=a_jifen1
end if
set rs=server.createobject("adodb.recordset")
sql="update reguser set reg_jifen="&a_jifen&" where reg_id in (select top 1 cart_buynameid from cart_list where cart_sessionid='"&item_name&"') "
rs.open sql,conn,3,2
rs.Close
Set rs = Nothing
Set conn = Nothing
elseif (objHttp.responseText = "INVALID") then
' log for manual investigation
' add code to handle the INVALID scenario
response.write"<Script language=javascript>alert('You do not have permission');location.href='index.asp';</script>"
else
' error
end if
set objHttp = nothing
%>