Skip to content

Instantly share code, notes, and snippets.

@soapdog
Created May 2, 2012 02:32
Show Gist options
  • Save soapdog/2573132 to your computer and use it in GitHub Desktop.
Save soapdog/2573132 to your computer and use it in GitHub Desktop.
RevIPN ipn.irev
<?rev
/* PayPal Instant Payment Notification Handler
* by
* Andre Garzia ([email protected])
*/
try
# Include our PayPal IPN routines
include "ipn.inc"
# Enable HTML debug file (debug.html)
setPref "Debug", true
# Set a passcode to be used by our RevLet
setPref "Passcode","1234"
# Set PayPal IPN Server info
setPref "PayPal IPN server","https://www.sandbox.paypal.com/cgi-bin/webscr"
# Set our login data for PayPal
setPref "PayPal email", ""
setPref "PayPal id", ""
# Set our database server information
setPref "Database host","localhost"
setPref "Database db","andregar_revhub"
setPref "Database username","andregar_revhub"
setPref "Database password",""
setPref "Database type","mysql"
ConnectToDatabase
# The part below deals with a connection from our RevLet
if $_GET["passcode"] is getPref("passcode") then
put getTransactions() into lTransactionsA
put the base64encode of arrayEncode(lTransactionsA)
DisconnectFromDatabase
exit to top
end if
# The part below deals with a connection from PayPal
if isTheTransactionForMe() then
# Save the notification query to use later
put $_POST_RAW into lPostRaw
# Save transaction data
newTransaction $_POST["txn_id"]
repeat for each key tKey in $_POST
setTransactionVar tKey, $_POST[tKey]
end repeat
# Put the 'cmd=_notify-validate' before the notification
put "cmd=_notify-validate&" before lPostRaw
# Check if transaction is valid with PayPal
get URL (getPref("PayPal IPN Server") & "?" & lPostRaw)
# Update transaction status based on PayPal answer
setTransactionStatus it
put "ok"
else
# Transaction is bad or not for us.
debug "Error: bad transaction"
end if
DisconnectFromDatabase
catch n
debug n
end try
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment