-------------------------------------------------------------------------------- Included are code samples for several popular web development environments. While this code has been tested by PayPal, PayPal cannot be held responsible for its use. ASP/VBScript Cold Fusion PERL PHP ASP/VBScript <%@LANGUAGE="VBScript"%> <% Dim authToken, txToken Dim query Dim objHttp Dim sQuerystring Dim sParts, iParts, aParts Dim sResults, sKey, sValue Dim i, result Dim firstName, lastName, itemName, mcGross, mcCurrency authToken = "Dc7P6f0ZadXW-U1X8oxf8_vUK09EHBMD7_53IiTT-CfTpfzkN0nipFKUPYy" 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.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 "first_name" firstName = sValue Case "last_name" lastName = sValue Case "item_name" itemName = sValue Case "mc_gross" mcGross = sValue Case "mc_currency" mcCurrency = sValue End Select Next Response.Write("

Your order has been received.

") Response.Write("Details
") Response.Write("
  • Name: " & firstName & " " & lastName & "
  • ") Response.Write("
  • Description: " & itemName & "
  • ") Response.Write("
  • Amount: " & mcCurrency & " " & mcGross & "
  • ") Response.Write("
    ") Else 'log for manual investigation Response.Write("ERROR") End If %> Back to top Cold Fusion

    Your order has been received.

    Details
  • Name: #firstName# #lastName#
  • Description: #itemName#
  • Amount: #mcCurrency# #mcGross#

  • ERROR
    Back to top PERL #!/usr/bin/perl -w ### # # PayPal PDT (Payment Data Transfer) CGI # ### use strict; use CGI qw(:all unescape); use CGI::Carp qw(fatalsToBrowser); # These modules are required to make the secure HTTP request to PayPal. use LWP::UserAgent; use Crypt::SSLeay; ### # CUSTOMIZE THIS: This is the seller's Payment Data Transfer authorization token. # Replace this with the PDT token in "Website Payment Preferences" under your account. ### my $auth_token = "VUDGCF2EA5huqlEqbSLPbg0JY3F-Pokyf-99r2sZWPR4x7GkWZEa-zIG49O"; sub done_text { return (p('Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at www.paypal.com to view details of this transaction.'), end_html()); } print header(), start_html("Thank you for your purchase!"); # Set up the secure request to the PayPal server to fetch the transaction info my $paypal_server = "www.paypal.com"; my $transaction = param("tx"); if (not $transaction) { print (h2("The transaction ID was not found."), done_text()); exit(); } my $paypal_url = "https://$paypal_server/cgi-bin/webscr"; my $query = join("&", "cmd=_notify-synch", "tx=$transaction", "at=$auth_token"); my $user_agent = new LWP::UserAgent; my $request = new HTTP::Request("POST", $paypal_url); $request->content_type("application/x-www-form-urlencoded"); $request->content($query); # Make the request my $result = $user_agent->request($request); if ($result->is_error) { print(h1("An error was encountered"), br(), p("An error was encountered contacting the PayPal server:"), $result->error_as_HTML, done_text()); exit(); } # Decode the response into individual lines and unescape any HTML escapes my @response = split("\n", unescape($result->content)); # The status is always the first line of the response. my $status = shift @response; if ($status eq "SUCCESS") { # success my %transaction; foreach my $response_line (@response) { my ($key, $value) = split "=", $response_line; $transaction{$key} = $value; } # These are only some of the transaction details available; there are others. # You should print all the transaction details appropriate. print(h2("Here are the details of your purchase:"), ul(li("Customer Name: " . $transaction{'first_name'} . " " . $transaction{'last_name'}), li("Item: " . $transaction{'item_name'}), li("Amount: " . $transaction{'payment_gross'}))); } elsif ($status eq "FAIL") { print(h2("Unable to retrieve transaction details.")); # failure } else { # unknown error print(h2("Error retrieving transaction details.")); } print done_text(); Back to top PHP

    Thank you for your purchase!

    "); echo ("Payment Details
    \n"); echo ("
  • Name: $firstname $lastname
  • \n"); echo ("
  • Item: $itemname
  • \n"); echo ("
  • Amount: $amount
  • \n"); echo (""); } else if (strcmp ($lines[0], "FAIL") == 0) { // log for manual investigation } } fclose ($fp); ?> Your transaction has been completed, and a receipt for your purchase has been emailed to you.
    You may log into your account at www.paypal.com to view details of this transaction.
    Back to top -------------------------------------------------------------------------------- Copyright © 1999-2004 PayPal. All rights reserved.