This can easily be done with PayPal's IPN.
Instant Payment Notification (IPN) is a means by which PayPal contacts your server directly every time a transaction completes. In other words, IPN is a call-back routine and part of an asynchronous process (in that the notification can happen any time after the transaction).
- Code: Select all
<%@LANGUAGE="VBScript"%>
<%
Dim Item_name, Item_number, Payment_status, Payment_amount
Dim Txn_id, Receiver_email, Payer_email
Dim objHttp, str
' 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")
objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send str
' assign posted variables to local variables1.
1. 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")
2. Payer_email = Request.Form("payer_email")
' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
3. if Payment_status = "Completed" Then
4. ' check that Txn_id has not been previously processed
' check that Receiver_email is your Primary PayPal email
5. if Receiver_email = "youremail@yourisp.com" Then 'Email is correct
' check that Payment_amount/Payment_currency are correct
6. ' process payment
end If
7. end If
elseif (objHttp.responseText = "INVALID") then
' log for manual investigation
else
' error
end if
set objHttp = nothing
%>
You'll need to check that the transaction ID has not been previously processed. One way to accomplish this is to record the txn_id value into a database. Then, query the table, pull the results into a recordset, and then check to see whether the record exists:
- Code: Select all
' check that Txn_id has not been previously processed:
connStore = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb")
set rsCheck = Server.CreateObject("ADODB.Recordset")
rsCheck.ActiveConnection = connStore
rsCheck.Source = "SELECT txn_id FROM tblOrders WHERE txn_id =
'" & txn_id & "'"
rsCheck.Open( )
If rsCheck.EOF And rsCheck.BOF Then 'Not a duplicate, continue processing
' check that Receiver_email is your Primary PayPal email
' check that Payment_amount/Payment_currency are correct
' process payment
End If