[ic] PayPal Code!!!

Scott Kennedy interchange-users@interchange.redhat.com
Mon May 13 16:59:05 2002


--0-1116286570-1021058651=:93098
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I've come up with some code for PayPal to be used on the receipt page
that I hope you all find to be useful.  I've spent a considerable
amount of time fine-tuning and debugging this code.  Please see
attached HTML file for the code.  You can see this code in action at,

    http://neatway.com/cgi-bin/altchoice/index.html

There is just one thing basically that I'm wondering about.  How can I
add PayPal as a payment method so that PayPal will be mentioned on the
receipt page and on the email receipt as the means of payment?  Would
merely modifying the checkout page in some way be all that's needed
here?  Any help would be greatly appreciated.

Thanks in advance,
Scott


***********************************************************
/ Custom Web Promotions /
Economical web hosting & online storefronts featuring
Red Hat Linux 7.2 & Red Hat Interchange 4.8.5
http://custweb.com / 888-287-8932 / sales@custweb.com
***********************************************************


__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Mother's Day is May 12th!
http://shopping.yahoo.com
--0-1116286570-1021058651=:93098
Content-Type: text/html; name="receipt.html"
Content-Description: receipt.html
Content-Disposition: inline; filename="receipt.html"

[comment]
ui_template: Yes
ui_template_name: noleft
[/comment]

[tmp page_title]__COMPANY__ -- Receipt[/tmp]

@_NOLEFT_TOP_@

<!-- BEGIN CONTENT -->

<br>
<center>
<TABLE>
<tr>
	<th align=right>
	ORDER NUMBER
	</th>
	<td>
	[value mv_order_number]
	</td>
</tr>
<tr>
	<th align=right>
		Name
	</th>
	<td>
	[value fname] [value lname]
	</td>
</tr>
[if value company]
<tr>
	<th align=right>
		Company
	</th>
	<td>
	[value company]
	</td>
</tr>
[/if]
<tr>
	<th align=right>
		Email Address
	</th>
	<td>
	[value email]
	</td>
</tr>
<tr>
	<th align=right>
		Address
	</th>
	<td>
	[value address1]
	</td>
</tr>
[if value address2]
<tr>
	<th align=right>
		&nbsp;
	</th>
	<td>
	[value address2]
	</td>
</tr>
[/if]
<tr>
	<th align=right>
		City, State, Zip
	</th>
	<td>
	[value city], [value state]  [value zip]
	</td>
</tr>
<tr>
	<th align=right>
		Country
	</th>
	<td>
	[value country]
	</td>
</tr>
<tr>
	<th align=right>
		Payment Method
	</th>
	<td>
	[value mv_payment]
	</td>
</tr>
<tr>
	<th align=right>
		Shipping Method
	</th>
	<td>
	[shipping_desc]
	</td>
</tr>
[if value mv_handling]
<tr>
	<th align=right>
		Handling Charge
	</th>
	<td>
	[loop list="[value mv_handling]"]
	[loop-change 1]
		[condition]1[/condition]
		[else]<BR>[/else]
	[/loop-change 1]
	[either][shipping_desc mode="[loop-code]"][or]CHARGED[/either]
	[/loop]
	</td>
</tr>
[/if]
[if value phone_day]
<tr>
	<th align=right>
		Daytime Phone
	</th>
	<td>
	[value phone_day]
	</td>
</tr>
[/if]
[if value phone_night]
<tr>
	<th align=right>
		Evening Phone
	</th>
	<td>
	[value phone_night]
	</td>
</tr>
[/if]
[if value b_fname]
<tr>
	<th align=right>
		Billing Name
	</th>
	<td>
	[value b_fname] [value b_lname]
	</td>
</tr>
[/if]
[if value b_address1]
<tr>
	<th align=right>
		Billing Address
	</th>
	<td>
	[value b_address1]
	</td>
</tr>
[if value b_address2]
<tr>
	<th align=right>
		&nbsp;
	</th>
	<td>
	[value b_address2]
	</td>
</tr>
[/if]
<tr>
	<th align=right>
		City, State, Zip
	</th>
	<td>
	[value b_city], [value b_state]  [value b_zip]
	</td>
</tr>
[/if]
[if value b_country]
<tr>
	<th align=right>
		Billing Country
	</th>
	<td>
	[value b_country]
	</td>
</tr>
[/if]

</TABLE>

<p>

[comment] Handle downloadables [/comment]
[perl products]
	sub get_download {
		if (! $Scratch->{download_present}) {
			return '(<B>Must pay by credit card to download now.)</B>';
		}
		my $sku = shift;
		return '' unless tag_data('products', 'download', $sku);
		my $loc =  tag_data('products', 'dl_location', $sku);
		my $save = delete $Scratch->{mv_add_dot_html};
		my $url = $Tag->area( {
						href => "deliver/$loc",
						arg => $sku,
						form => $Scratch->{mv_autocreate},
					} ); 
		$Scratch->{mv_add_dot_html} = $save if $save;
		return qq{<BR><A HREF="$url"><IMG border=0 SRC="download.png"></A>};
	}
	return;
[/perl]
<p>
<TABLE>
<TH align=right>[L]Quan[/L]</TH>
<TH>[L]Item No.[/L]</TH>
<TH>[L]Description[/L]</TH>	
<TH align=right>[L]Price[/L]</TH>	
<TH align=right>[L]Extension[/L]</TH>	
[item-list modular=1]
<tr>
	<td align=right valign=top>
	[item-quantity]
	</td>
	<td valign=top>
		[item-sku]
	</td>
	<td>
	[item-data products description]
	[if-modifier size]<BR>SIZE-->[item-modifier size][/if-modifier][if-modifier color] COLOR-->[item-modifier color][/if-modifier]
	[if-item-data options o_enable]
		[if-item-data !options o_modular]
			[table-organize cols=4 table=' ' font="size=1" pretty=1]
				[item-options td=1 label=1 bold=1 price=1 type=display]
			[/table-organize]
		[/if-item-data]
	[/if-item-data]

	[if-item-field download]
		<br>[calc]get_download('[item-code]')[/calc]
	[/if-item-field]
	[if-item-modifier mv_ad]
	<BR>
	<tt><b>SHIP TO:</B></tt>
	<PRE>[item-modifier mv_ad]</pre>
	[/if-item-modifier]
	</td>
	<td align=right valign=top>
		[item-price]
	</td>
	<td align=right valign=top>
		[item-subtotal]
	</td>
[/item-list]
<tr>
	<td colspan=3>
		&nbsp;
	</td>
	<td>
		SUBTOTAL
	</td>
	<td align=right>
		[subtotal]
	</td>
</tr>
<tr>
	<td colspan=3>
		&nbsp;
	</td>
	<td>
		SALES TAX
	</td>
	<td align=right>
		[salestax]
	</td>
</tr>
[if value mv_shipmode]
<tr>
	<td colspan=3>
		&nbsp;
	</td>
	<td>
		SHIPPING
	</td>
	<td align=right>
		[shipping]
	</td>
</tr>
[/if]
[if value mv_handling]
<tr>
	<td colspan=3>
		&nbsp;
	</td>
	<td>
		HANDLING
	</td>
	<td align=right>
		[handling]
	</td>
</tr>
[/if]
<tr>
	<td colspan=3>
		&nbsp;
	</td>
	<td>
		ORDER TOTAL
	</td>
	<td align=right>
		[total-cost]
	</td>
</tr>
[if value gift_note]
<tr>
	<td colspan=2>
	<B>Comments/Note for Gift:</B>
	</td>
	<td colspan=3>
	<PRE>
	[value gift_note]
	</PRE>
	</td>
</tr>
[/if]
</table>
<P>
<font face="Verdana, Arial, Helvetica, sans-serif" size="1">
<I>(Please print this receipt for your records. Thank you for your order!)</I>
</font>
<P>

[include templates/components/specials]
</CENTER>

<!-- END CONTENT -->

@_NOLEFT_BOTTOM_@

<!--
Portions of the code below are copyrighted 2002 by Scott Kennedy.  All rights reserved.
Code may be freely used and redistributed as long as this message is left intact.
Contact information:
    Custom Web Promotions
    1210 E. Main
    Tishomingo, OK 73460
    (580) 371-2528
    http://custweb.com
    scott@custweb.com
-->

<SCRIPT LANGUAGE="JavaScript">

function round (n) { 
n = Math.round(n * 100) / 100; 
n = (n + 0.001) + ''; 
return n.substring(0, n.indexOf('.') + 3); 
}

function OpenWindow() {

// ***** Open new window *****

  win = window.open('', 'win1', 'width=675,height=425,scrollbars=yes,resizable=yes,left=25,top=25');
}

function Deposit() {

// ***** Calculate order deposit *****

	var total = "[total-cost noformat=1]";
	var deposit = total * .05;
	if(deposit > 100 && deposit < 1900) {
		deposit = round(deposit);
		return(deposit);
	}
	if (deposit < 100)
		return(100.00);
	return(1900.00);
}

// ***** Send payment information to PayPal *****

// Initialize variables

var amount = Deposit();                                        // Total amount to be billed to PayPal
var business = "sales@neatway.com";                            // Payment recipient
var order_number = "[value mv_order_number]";                  // Get order number
var email = "[value email]";                                   // E-Mail address
var item_name = "__COMPANY__ - " + "Order # " + order_number;  // Set item name
var submitstring = 'win.document.PayPal.submit();';            // PayPal form submission string

// Get shipping info
var first_name = "[value fname]";                              // First name
var last_name = "[value lname]";                               // Last name
var address1 = "[value address1]";                             // First address line
var address2 = "[value address2]";                             // Second address line
var city = "[value city]";                                     // City
var state = "[value state]";                                   // State
var zip = "[value zip]";                                       // Zip
var phone_night = "[value phone_night]";                       // Night phone
var phone_day = "[value phone_day]";                           // Day phone

// Get billing info, where available
var b_first_name = "[value b_fname]";                          // First name
var b_last_name = "[value b_lname]";                           // Last name
var b_address1 = "[value b_address1]";                         // First address line
var b_address2 = "[value b_address2]";                         // Second address line
var b_city = "[value b_city]";                                 // City
var b_state = "[value b_state]";                               // State
var b_zip = "[value b_zip]";                                   // Zip

// Set PayPal billing info; Use billing values instead of shipping values where available
if(b_first_name != "")
	first_name = b_first_name;
if(b_last_name != "")
	last_name = b_last_name;
if(b_address1 != "")
	address1 = b_address1;
if(b_address2 != "")
	address2 = b_address2;
if(b_city != "")
	city = b_city;
if(b_state != "")
	state = b_state;
if(b_zip != "")
	zip = b_zip;

// Process telephone numbers for PayPal

[perl]

	$phone_night = $Values->{phone_night};
	$phone_day = $Values->{phone_day};

	# Strip unwanted characters
	# PayPal only allows digits

	$phone_night = $Tag->filter('digits', $phone_night);
	$phone_day = $Tag->filter('digits', $phone_day);

	# Group digits of each phone number into three parts
	# Phone number format PayPal uses is AREA CODE / PREFIX / NUMBER

	$phone_day =~ /(\d\d\d)(\d\d\d)(\d\d\d\d)/;

	$Tag->set('day_phone_a', $1);
	$Tag->set('day_phone_b', $2);
	$Tag->set('day_phone_c', $3);

	$phone_night =~ /(\d\d\d)(\d\d\d)(\d\d\d\d)/;

	$Tag->set('night_phone_a', $1);
	$Tag->set('night_phone_b', $2);
	$Tag->set('night_phone_c', $3);

[/perl]

// Create PayPal form text

text = "<FORM NAME=\"PayPal\" METHOD=\"post\" ";
text += "ACTION=\"https://www.paypal.com/cgi-bin/webscr\">";
text += "<INPUT TYPE=hidden NAME=\"cmd\" value=\"_ext-enter\">";
text += "<INPUT TYPE=hidden NAME=\"redirect_cmd\" value=\"_xclick\">";
text += "<INPUT TYPE=hidden NAME=\"business\" value=\"" + business + "\">";
text += "<INPUT TYPE=hidden NAME=\"undefined_quantity\" value=\"\">";
text += "<INPUT TYPE=hidden NAME=\"item_name\" value=\"" + item_name + "\">";
text += "<INPUT TYPE=hidden NAME=\"item_number\" value=\"-----\">";
text += "<INPUT TYPE=hidden NAME=\"amount\" value=\"" + amount + "\">";
text += "<INPUT TYPE=hidden NAME=\"shipping\" value=\"\">";
text += "<INPUT TYPE=hidden NAME=\"shipping2\" value=\"\">";
text += "<INPUT TYPE=hidden NAME=\"first_name\" value=\"" + first_name + "\">";
text += "<INPUT TYPE=hidden NAME=\"last_name\" value=\"" + last_name + "\">";
text += "<INPUT TYPE=hidden NAME=\"address1\" value=\"" + address1 + "\">";
text += "<INPUT TYPE=hidden NAME=\"address2\" value=\"" + address2 + "\">";
text += "<INPUT TYPE=hidden NAME=\"city\" value=\"" + city + "\">";
text += "<INPUT TYPE=hidden NAME=\"state\" value=\"" + state + "\">";
text += "<INPUT TYPE=hidden NAME=\"zip\" value=\"" + zip + "\">";
text += "<INPUT TYPE=hidden NAME=\"night_phone_a\" value=\"" + "[scratch night_phone_a]" + "\">";
text += "<INPUT TYPE=hidden NAME=\"night_phone_b\" value=\"" + "[scratch night_phone_b]" + "\">";
text += "<INPUT TYPE=hidden NAME=\"night_phone_c\" value=\"" + "[scratch night_phone_c]" + "\">";
text += "<INPUT TYPE=hidden NAME=\"day_phone_a\" value=\"" + "[scratch day_phone_a]" + "\">";
text += "<INPUT TYPE=hidden NAME=\"day_phone_b\" value=\"" + "[scratch day_phone_b]" + "\">";
text += "<INPUT TYPE=hidden NAME=\"day_phone_c\" value=\"" + "[scratch day_phone_c]" + "\">";
text += "<INPUT TYPE=hidden NAME=\"email\" value=\"" + email + "\">";
text += "</FORM>";

// Open pop-up window; close window and then open window again if open already
OpenWindow(); win.close(); OpenWindow();
win.document.writeln(text); // Write form text to pop-up window
eval(submitstring); // Submit PayPal form

</SCRIPT>

--0-1116286570-1021058651=:93098--