Professional Documents
Culture Documents
ASP.Net/C# Java/JSP
ASP.Net/VB PERL
ASP/VBScript PHP
ColdFusion
ASP.Net/C#
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;
//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
//req.Proxy = proxy;
if (strResponse == "VERIFIED")
{
//check the payment_status is 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
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
1 of 6 2/23/2011 4:00 PM
Instant Payment Notification - Code Samples - PayPal https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-p...
Back to top
ASP.Net/VB
Imports System.Net
Imports System.IO
'for proxy
'Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
'req.Proxy = proxy
Back to top
ASP/VBScript
(requires MSXML)
<%@LANGUAGE="VBScript"%>
<%
Dim Item_name, Item_number, Payment_status, Payment_amount
Dim Txn_id, Receiver_email, Payer_email
Dim objHttp, str
2 of 6 2/23/2011 4:00 PM
Instant Payment Notification - Code Samples - PayPal https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-p...
Back to top
ColdFusion
<!-- read post from PayPal system and add 'cmd' -->
<CFSET str="cmd=_notify-validate">
<CFLOOP INDEX="TheField" list="#Form.FieldNames#">
<CFSET str = str & "&#LCase(TheField)#=#URLEncodedFormat(Form[TheField])#">
</CFLOOP>
<CFIF IsDefined("FORM.payment_date")>
<CFSET str = str & "&payment_date=#URLEncodedFormat(Form.payment_date)#">
</CFIF>
<CFIF IsDefined("FORM.subscr_date")>
<CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.subscr_date)#">
</CFIF>
<CFIF IsDefined("FORM.auction_closing_date")>
<CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.auction_closing_date)#">
</CFIF>
<!-- post back to PayPal system to validate -->
<CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false">
</CFHTTP>
<!-- assign posted variables to local variables -->
<CFSET item_name=FORM.item_name>
<CFSET payment_status=FORM.payment_status>
<CFSET payment_amount=FORM.mc_gross>
<CFSET payment_currency=FORM.mc_currency>
<CFSET txn_id=FORM.txn_id>
<CFSET receiver_email=FORM.receiver_email>
<CFSET payer_email=FORM.payer_email>
<CFIF IsDefined("FORM.item_number")>
<CFSET item_number=FORM.item_number>
</CFIF>
<!-- check notification validation -->
<CFIF #CFHTTP.FileContent# is "VERIFIED">
3 of 6 2/23/2011 4:00 PM
Instant Payment Notification - Code Samples - PayPal https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-p...
Back to top
Java/JSP
<%
// read post from PayPal system and add 'cmd'
Enumeration en = request.getParameterNames();
String str = "cmd=_notify-validate";
while(en.hasMoreElements()){
String paramName = (String)en.nextElement();
String paramValue = request.getParameter(paramName);
str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
}
4 of 6 2/23/2011 4:00 PM
Instant Payment Notification - Code Samples - PayPal https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-p...
Back to top
PERL
(requires LWP::UserAgent)
#!/usr/bin/perl
if ($res->is_error) {
# HTTP error
}
elsif ($res->content eq 'VERIFIED') {
# check the $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
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
}
else {
# error
}
print "content-type: text/plain\n\n";
Back to top
PHP 4.1
5 of 6 2/23/2011 4:00 PM
Instant Payment Notification - Code Samples - PayPal https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-p...
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is 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
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
Back to top
Close Window
6 of 6 2/23/2011 4:00 PM