#!/usr/bin/perl # use CGI::Carp qw(fatalsToBrowser); #comment out this line when your done debugging this script $|++; #dont't buffer output use strict; =head Free PERL PayPal shopping cart script download the latest version from: http://www.perl-studio.com/paypal/free Copyright Notice Copyright (c) 1996-2002 AyerSoft/Perl-Studio. All rights reserved. =cut # Created on Sunday, September 15, 2002 using # Perl Studio by AyerSoft copyright(C) 2002 ################################################### # You are free to customize this script as you wish, but do not # redistribute without written permission from AyerSoft. # DISCLAIMER # The information and code provided is provided 'as is' without # warranty of any kind, either express or implied. In no event # shall the AyerSoft Company be liable for any damages whatsoever # including direct, indirect, incidental, consequential, loss of # business profits or special damages, even if the author has been # advised of the possibility of such damages. # DO NOT USE THIS SCRIPT UNLESS YOU CAN FULLY AGREE WITH THIS # DISCLAIMER. ##################################################### =head This PERL PayPal shopping cart script can display an unlimited number of products from a Microsoft Excel spreadsheet. Just export your Microsoft Excel product spreadsheet as a delimited text file (tab) and your Paypal shopping cart can be ready in minutes Implementation: Enter the details of each item you wish to sell into your Microsoft Excel product spreadsheet. Export your Microsoft Excel product spreadsheet as a delimited text file (tab) saved as products.txt. Edit the PayPal business name (email address) in the PERL PayPal shopping cart scripts, to reflect the PayPal email address that you receive the PayPal payments at. Upload the PERL PayPal shopping cart scripts to a FTP directory on your WebSite. Upload the products.txt to the same FTP directory the PERL PayPal shopping cart scripts are in. Code SYNOPSIS: The PERL PayPal shopping cart script reads in the delimited text file and writes the HTML add to cart buttons for each product in the delimited text file. The PayPal add to cart buttons code is automatically generated. The PayPal view cart button code is also automatically generated. Microsoft Excel product spreadsheet Implementation: Three required columns/fields item_number item_name item_amount The item_number field is an ID, SKU or tracking number for your item. The item_name field is the name of the item or service you wish to sell. The item_amount field is the price of the item you wish to sell. =cut # start user configuration #====================================================================== # Quick install: # edit the $business_email variable # upload the script and products.txt to the same FTP directory # # $products_path: path to Microsoft Excel tab delimited text # file with fields item_number, item_name, item_amount on each line. # my $products_path = "products.txt"; # PayPal business name (email address) my $business_email = "birchtreebooks@gmail.com"; # optional user configuration #====================================================================== # back ground color for products table my $bgcolor="#ffffff"; # type of delimiter used in products delimited text file my $delimiter = "\t"; # $image_url = Add Your Logo # Customize the look of your PayPal payment pages by adding your logo. This # image, which must be 150 by 50 pixels in size, will appear in the upper left # hand corner of the page when your customer presses your Shopping Cart # button.my $image_url = ""; # $return_url = Successful Payment URL # Enter the URL where you would like to send your customers after they have # completed payment. Once your customer has completed their payment, they will # see a payment confirmation page. From this page, they will press the # 'Continue' button and return to the Successful Payment URL you have # specified. If you do not enter a Successful Payment URL, customers who click # this link will be taken to a PayPal web page.my $return_url = "http://$ENV{HTTP_HOST}"; # $cancel_return = Cancel Payment URL # Enter the URL where you would like to send your customers if they cancel # their payment at any point in the Shopping Cart payment flow. If you do # not enter a Cancel Payment URL, customers who click this link will be taken # to a PayPal web page.my $cancel_return = "http://$ENV{HTTP_HOST}"; # Enter the currency symbols PayPal uses to designate US dollars # or Euros or Pounds Sterlings. Enter a backslash before the $ symbol. # US: $ # Euros: ¬ # Pounds Sterling: £ # Canadian Dollar (C$) # Japanese Yen (¥) my $m_symbol = "\$";# The currency of the payment is U.S.Dollars: USD # The currency of the payment is British Pounds Sterling: GBP # The currency of the payment is Euros: EUR # The currency of the payment is Canadian Dollar: CAD # The currency of the payment is Yen: JPYmy $currency_code = "USD"; #====================================================================== # end user configuration print "Content-type: text/html\n\n";site_header('Our Products');# load products.txt. open(FILE, "<$products_path") || show_error("$products_path: Can't open because ($!)."); # Place each line in the products file into an array my @file_contents = <FILE>; close(FILE);# urlencode the PayPal business email address my $email = urlencode($business_email); # loop through the array of products and display the HTML add to cart buttons */ foreach(@file_contents) { # split the line with delimiter used in the file my ($item_number,$item_name,$item_amount) = split($delimiter,$_,3); if($item_amount > 0){ my $number = urlencode($item_number); $item_name =~ s/\"/ /g; my $name_value = $item_name; #remove characters that migh cause problems with the javascript functions $name_value =~ s/[\,\;\`\'\|\*\~\^\[\]\{\}\$\"]/ /g; $name_value =~ s/^\s+|\s+$/ /; my $name = urlencode($name_value); my $amount = urlencode($item_amount); my $url = "https://www.paypal.com/cart/add=1&business=$email&item_number=$number&item_name=$name&amount=$amount&currency_code=$currency_code&bn=AyerSoft.PerlStudio"; $url .= "&return=$return_url&cancel_return=$cancel_return!_url=$image_url"; # create the code for the add to cart buttons for each product my $html_row = qq^ <tr> <td class="cartTD">$item_number</td><td class="cartTD">$item_name</td><td class="cartTD">$m_symbol$item_amount</td> <td> <a href="javascript:onclick=window.paypalwinOpen('$url');"><img src="http://images.paypal.com/images/x-click-but22.gif" border="0"></a> </td></tr> ^; # display the code for the add to cart buttons for each product print $html_row; } } site_footer(); exit; ################################### # library subroutines follow ################################### #====================================================================== # site header and footer functions # read in a html header file or print out a HTML header section #====================================================================== sub site_header($title) { my $title = shift; my $file = $ENV{DOCUMENT_ROOT} .'/header.html'; if (!(-r $file)){ $file = "header.html"; }my $header = qq^ <HTML> <HEAD> <TITLE>$title</TITLE> <script language="JavaScript"> <!-- var pixels_width = window.screen.width; var pixels_height = window.screen.height; var nWidth= "600"; var nHeight="400"; if(pixels_width < 740){ nWidth = "540"; } if(pixels_height < 540){ nHeight = "350"; } var optionString = "scrollbars,location,resizable,status,"; optionString += "height=" + nHeight + ",width=" + nWidth; optionString += ",screenX=10,screenY=10,top=10,left=10"; var cartWindow = null; function paypalwinOpen(url){ if (!cartWindow || cartWindow.closed) { cartWindow = window.open(url,"cart",optionString); } else { // window already exists, so bring it forward cartWindow.location.href=url; cartWindow.focus(); } } // --> </script> <style type="text/css"> .cartTD {font-size: 11px; font-family: verdana,helvetica,arial,sans-serif;} </style> </HEAD> ^; print $header; if (-r $file){ include($file); } print "\n<table width=550 bgcolor=\"$bgcolor\" cellspacing=0 cellpadding=0 border=1>\n"; } # read in a html footer file or print out a HTML footer section #====================================================================== sub site_footer() { my $file = $ENV{DOCUMENT_ROOT} .'/footer.html'; if (!(-r $file)){ $file = "footer.html"; } my $cart_url = "https://www.paypal.com/cart/display=1&business=$email"; my $footer = qq^ </table> <p align=center> <a href="javascript:onclick=window.paypalwinOpen('$cart_url');"><img src="https://www.paypal.com/images/view_cart_02.gif" border="0"></a> </p> ^; print $footer; if ( -r $file){ include($file); } else{ print "\n <a href=http://www.1-counter.com title="Free web site statistics"> <script src="http://www.1-hit.com/1counter.js"></script> <noscript><img alt="Free web site statistics" src="http://www.1-counter.com/pphlogger.php?id=1-hit&st=img&showme=y"></noscript> </a> </body> </HTML>\n"; } } #====================================================================== sub include{ my $file = shift; return undef unless(-r $file); my $contents; open(PK,"<$file") || show_error("$file: Can't open because ($!)."); read(PK, $contents, -s PK); close PK; print $contents; } #====================================================================== sub show_error{ my($item) = shift; my $server = ($ENV{HTTP_HOST}) ? $ENV{HTTP_HOST}:'localhost'; my $REQUEST_URI = $0; $item =~ s/\]/\]<br>/g; $item =~ s/\(/<br>\(/g; $item =~ s/\)/\)<br>/g; print qq! <HTML><HEAD><TITLE>Script Error</TITLE></HEAD><BODY BGCOLOR=#FFFFFF> <CENTER><TABLE border=0 cellpadding=0 cellspacing=1 BGCOLOR=#000099> <TR><TD><TABLE BORDER=0 WIDTH=600 CELLSPACING=0 BGCOLOR=#ffffff cellpadding=3> <TR><TD align="center" BGCOLOR=#000099><TABLE><TR><TD> <FONT color=#FFFFFF face="Verdana,Arial,Helvetica" size=3> <B>CGI Script Error</B></FONT></TD></TR></TABLE></TD></TR><TR><TD> <FONT color=#000000 face="Verdana,Arial,Helvetica" size=2> <BLOCKQUOTE><FONT size=3>http://$server</FONT> <P><A HREF="http://$ENV{HTTP_HOST}"> $server </A></P> <P> The requested URL <P><B>$REQUEST_URI</B></p> <P>returned the following error message</P> <P><strong>$item </strong></P> <P><A HREF="http://www.perl-studio.com/cgi-bin/faq/search.cgi">Perl CGI Script Error Help</A> </FONT></BLOCKQUOTE></TD></TR><TR><TD BGCOLOR=#000099> <DIV align="center"><FONT color=#ffffff size=1 face="Verdana,Arial,Helvetica"> <B>Perl Studio for Unix/Linux/Windows</B> </FONT></DIV></TD></TR></TABLE></TD></TR></TABLE><BR> <P><A HREF="http://www.perl-studio.com">This script generated by www.perl-studio.com</A> </CENTER> <a href=http://www.1-counter.com title="Free web site statistics"> <script src="http://www.1-hit.com/1counter.js"></script> <noscript><img alt="Free web site statistics" src="http://www.1-counter.com/pphlogger.php?id=1-hit&st=img&showme=y"></noscript> </a> </body> </HTML> !; exit; } #=======================================================================================# sub urlencode{ my($esc) = @_; $esc =~ s/^\s+|\s+$//gs; $esc =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; $esc =~ s/ /\+/g; $esc =~ s/%20/\+/g; return $esc; } #=======================================================================================# __END__ =head1 AUTHORS This module is part of the Perl Studio distribution. Copyright 2002 AyerSoft =cut
Make your own free website on Tripod.com